diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 460648b..f64caf4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,6 +53,7 @@ android:theme="@style/Theme.BigImageActivity" /> + + +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder( + parent: ViewGroup, viewType: Int + ): DeviceListAdapter.ItemViewHolder { + return ItemViewHolder( + layoutInflater.inflate(R.layout.item_device_manage_recycleview, parent, false) + ) + } + + override fun getItemCount(): Int = dataRows.size + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + + holder.deviceStateView.text = rowsBean.onlineStateName + if (rowsBean.onlineState == "1") { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + } else { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_gray) + } + holder.deviceCodeView.text = rowsBean.devcode + holder.deviceTypeView.text = String.format("设备类型:${rowsBean.deviceTypeName}") + holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") + holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") + holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.dataHistoryButton.setOnClickListener { + listener!!.onHistoryClicked(position) + } + holder.editButton.setOnClickListener { + listener!!.onEditClicked(position) + } + holder.wellDetailButton.setOnClickListener { + listener!!.onWellDetailClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) + var deviceTypeView: TextView = view.findViewById(R.id.deviceTypeView) + var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) + var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) + var editButton: QMUIRoundButton = view.findViewById(R.id.editButton) + var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onHistoryClicked(position: Int) + + fun onEditClicked(position: Int) + + fun onWellDetailClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 460648b..f64caf4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,6 +53,7 @@ android:theme="@style/Theme.BigImageActivity" /> + +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder( + parent: ViewGroup, viewType: Int + ): DeviceListAdapter.ItemViewHolder { + return ItemViewHolder( + layoutInflater.inflate(R.layout.item_device_manage_recycleview, parent, false) + ) + } + + override fun getItemCount(): Int = dataRows.size + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + + holder.deviceStateView.text = rowsBean.onlineStateName + if (rowsBean.onlineState == "1") { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + } else { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_gray) + } + holder.deviceCodeView.text = rowsBean.devcode + holder.deviceTypeView.text = String.format("设备类型:${rowsBean.deviceTypeName}") + holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") + holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") + holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.dataHistoryButton.setOnClickListener { + listener!!.onHistoryClicked(position) + } + holder.editButton.setOnClickListener { + listener!!.onEditClicked(position) + } + holder.wellDetailButton.setOnClickListener { + listener!!.onWellDetailClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) + var deviceTypeView: TextView = view.findViewById(R.id.deviceTypeView) + var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) + var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) + var editButton: QMUIRoundButton = view.findViewById(R.id.editButton) + var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onHistoryClicked(position: Int) + + fun onEditClicked(position: Int) + + fun onWellDetailClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index eb24d44..a97b83f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -24,6 +24,7 @@ import com.casic.app.smartwell.sanxi.utils.Constant import com.casic.app.smartwell.sanxi.utils.DialogHelper import com.casic.app.smartwell.sanxi.view.AlarmManageActivity +import com.casic.app.smartwell.sanxi.view.DeviceManageActivity import com.casic.app.smartwell.sanxi.view.WellManageActivity import com.casic.app.smartwell.sanxi.view.WorkOrderManageActivity import com.casic.app.smartwell.sanxi.vm.AlarmViewModel @@ -326,7 +327,7 @@ } homeView.deviceDataLayout.setOnClickListener { -// requireContext().navigatePageTo() + requireContext().navigatePageTo() } homeView.orderDataLayout.setOnClickListener { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 460648b..f64caf4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,6 +53,7 @@ android:theme="@style/Theme.BigImageActivity" /> + +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder( + parent: ViewGroup, viewType: Int + ): DeviceListAdapter.ItemViewHolder { + return ItemViewHolder( + layoutInflater.inflate(R.layout.item_device_manage_recycleview, parent, false) + ) + } + + override fun getItemCount(): Int = dataRows.size + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + + holder.deviceStateView.text = rowsBean.onlineStateName + if (rowsBean.onlineState == "1") { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + } else { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_gray) + } + holder.deviceCodeView.text = rowsBean.devcode + holder.deviceTypeView.text = String.format("设备类型:${rowsBean.deviceTypeName}") + holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") + holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") + holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.dataHistoryButton.setOnClickListener { + listener!!.onHistoryClicked(position) + } + holder.editButton.setOnClickListener { + listener!!.onEditClicked(position) + } + holder.wellDetailButton.setOnClickListener { + listener!!.onWellDetailClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) + var deviceTypeView: TextView = view.findViewById(R.id.deviceTypeView) + var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) + var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) + var editButton: QMUIRoundButton = view.findViewById(R.id.editButton) + var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onHistoryClicked(position: Int) + + fun onEditClicked(position: Int) + + fun onWellDetailClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index eb24d44..a97b83f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -24,6 +24,7 @@ import com.casic.app.smartwell.sanxi.utils.Constant import com.casic.app.smartwell.sanxi.utils.DialogHelper import com.casic.app.smartwell.sanxi.view.AlarmManageActivity +import com.casic.app.smartwell.sanxi.view.DeviceManageActivity import com.casic.app.smartwell.sanxi.view.WellManageActivity import com.casic.app.smartwell.sanxi.view.WorkOrderManageActivity import com.casic.app.smartwell.sanxi.vm.AlarmViewModel @@ -326,7 +327,7 @@ } homeView.deviceDataLayout.setOnClickListener { -// requireContext().navigatePageTo() + requireContext().navigatePageTo() } homeView.orderDataLayout.setOnClickListener { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java b/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java new file mode 100644 index 0000000..fc9f820 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.sanxi.model; + +import java.util.List; + +public class DeviceListPageModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 460648b..f64caf4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,6 +53,7 @@ android:theme="@style/Theme.BigImageActivity" /> + +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder( + parent: ViewGroup, viewType: Int + ): DeviceListAdapter.ItemViewHolder { + return ItemViewHolder( + layoutInflater.inflate(R.layout.item_device_manage_recycleview, parent, false) + ) + } + + override fun getItemCount(): Int = dataRows.size + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + + holder.deviceStateView.text = rowsBean.onlineStateName + if (rowsBean.onlineState == "1") { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + } else { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_gray) + } + holder.deviceCodeView.text = rowsBean.devcode + holder.deviceTypeView.text = String.format("设备类型:${rowsBean.deviceTypeName}") + holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") + holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") + holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.dataHistoryButton.setOnClickListener { + listener!!.onHistoryClicked(position) + } + holder.editButton.setOnClickListener { + listener!!.onEditClicked(position) + } + holder.wellDetailButton.setOnClickListener { + listener!!.onWellDetailClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) + var deviceTypeView: TextView = view.findViewById(R.id.deviceTypeView) + var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) + var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) + var editButton: QMUIRoundButton = view.findViewById(R.id.editButton) + var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onHistoryClicked(position: Int) + + fun onEditClicked(position: Int) + + fun onWellDetailClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index eb24d44..a97b83f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -24,6 +24,7 @@ import com.casic.app.smartwell.sanxi.utils.Constant import com.casic.app.smartwell.sanxi.utils.DialogHelper import com.casic.app.smartwell.sanxi.view.AlarmManageActivity +import com.casic.app.smartwell.sanxi.view.DeviceManageActivity import com.casic.app.smartwell.sanxi.view.WellManageActivity import com.casic.app.smartwell.sanxi.view.WorkOrderManageActivity import com.casic.app.smartwell.sanxi.vm.AlarmViewModel @@ -326,7 +327,7 @@ } homeView.deviceDataLayout.setOnClickListener { -// requireContext().navigatePageTo() + requireContext().navigatePageTo() } homeView.orderDataLayout.setOnClickListener { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java b/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java new file mode 100644 index 0000000..fc9f820 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.sanxi.model; + +import java.util.List; + +public class DeviceListPageModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index bd311a4..0413d42 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -229,7 +229,7 @@ ): String /** - * 获取获取闸井列表 + * 获取闸井列表-分页 * * @param keywords 关键字 * @param wellType 窨井类型 @@ -360,6 +360,27 @@ ): String /** + * 获取设备列表-分页 + * + * @param keywords 关键字 + * @param wellType 窨井类型 + * @param deptid 部门ID + * @param limit 每页数据条数 + * @param offset 页码 + */ + @GET("/device/list") + suspend fun obtainDevicePageList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("deviceType") deviceType: String?, + @Query("isOnline") isOnline: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int, + @Query("sort") sort: String, + @Query("order") order: String + ): String + + /** * 获取工单详情 * * @param id 工单id diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 460648b..f64caf4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,6 +53,7 @@ android:theme="@style/Theme.BigImageActivity" /> + +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder( + parent: ViewGroup, viewType: Int + ): DeviceListAdapter.ItemViewHolder { + return ItemViewHolder( + layoutInflater.inflate(R.layout.item_device_manage_recycleview, parent, false) + ) + } + + override fun getItemCount(): Int = dataRows.size + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + + holder.deviceStateView.text = rowsBean.onlineStateName + if (rowsBean.onlineState == "1") { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + } else { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_gray) + } + holder.deviceCodeView.text = rowsBean.devcode + holder.deviceTypeView.text = String.format("设备类型:${rowsBean.deviceTypeName}") + holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") + holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") + holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.dataHistoryButton.setOnClickListener { + listener!!.onHistoryClicked(position) + } + holder.editButton.setOnClickListener { + listener!!.onEditClicked(position) + } + holder.wellDetailButton.setOnClickListener { + listener!!.onWellDetailClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) + var deviceTypeView: TextView = view.findViewById(R.id.deviceTypeView) + var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) + var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) + var editButton: QMUIRoundButton = view.findViewById(R.id.editButton) + var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onHistoryClicked(position: Int) + + fun onEditClicked(position: Int) + + fun onWellDetailClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index eb24d44..a97b83f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -24,6 +24,7 @@ import com.casic.app.smartwell.sanxi.utils.Constant import com.casic.app.smartwell.sanxi.utils.DialogHelper import com.casic.app.smartwell.sanxi.view.AlarmManageActivity +import com.casic.app.smartwell.sanxi.view.DeviceManageActivity import com.casic.app.smartwell.sanxi.view.WellManageActivity import com.casic.app.smartwell.sanxi.view.WorkOrderManageActivity import com.casic.app.smartwell.sanxi.vm.AlarmViewModel @@ -326,7 +327,7 @@ } homeView.deviceDataLayout.setOnClickListener { -// requireContext().navigatePageTo() + requireContext().navigatePageTo() } homeView.orderDataLayout.setOnClickListener { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java b/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java new file mode 100644 index 0000000..fc9f820 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.sanxi.model; + +import java.util.List; + +public class DeviceListPageModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index bd311a4..0413d42 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -229,7 +229,7 @@ ): String /** - * 获取获取闸井列表 + * 获取闸井列表-分页 * * @param keywords 关键字 * @param wellType 窨井类型 @@ -360,6 +360,27 @@ ): String /** + * 获取设备列表-分页 + * + * @param keywords 关键字 + * @param wellType 窨井类型 + * @param deptid 部门ID + * @param limit 每页数据条数 + * @param offset 页码 + */ + @GET("/device/list") + suspend fun obtainDevicePageList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("deviceType") deviceType: String?, + @Query("isOnline") isOnline: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int, + @Query("sort") sort: String, + @Query("order") order: String + ): String + + /** * 获取工单详情 * * @param id 工单id diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index e35e976..fe17f7b 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -231,7 +231,7 @@ } /** - * 获取获取闸井列表-分页 + * 获取闸井列表-分页 */ suspend fun obtainWellPageList( keywords: String?, wellType: String?, deptid: String?, offset: Int @@ -346,6 +346,24 @@ ) } + /** + * 获取设备列表-分页 + */ + suspend fun obtainDevicePageList( + keywords: String?, deviceType: String?, isOnline: String?, offset: Int + ): String { + return api.obtainDevicePageList( + AuthenticationHelper.token!!, + keywords, + deviceType, + isOnline, + Constant.PAGE_LIMIT, + offset, + "id", + "asc" + ) + } + // /** // * 获取工单详情 // */ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 460648b..f64caf4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,6 +53,7 @@ android:theme="@style/Theme.BigImageActivity" /> + +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder( + parent: ViewGroup, viewType: Int + ): DeviceListAdapter.ItemViewHolder { + return ItemViewHolder( + layoutInflater.inflate(R.layout.item_device_manage_recycleview, parent, false) + ) + } + + override fun getItemCount(): Int = dataRows.size + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + + holder.deviceStateView.text = rowsBean.onlineStateName + if (rowsBean.onlineState == "1") { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + } else { + holder.deviceStateView.setBackgroundResource(R.drawable.bg_text_tag_gray) + } + holder.deviceCodeView.text = rowsBean.devcode + holder.deviceTypeView.text = String.format("设备类型:${rowsBean.deviceTypeName}") + holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") + holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") + holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.dataHistoryButton.setOnClickListener { + listener!!.onHistoryClicked(position) + } + holder.editButton.setOnClickListener { + listener!!.onEditClicked(position) + } + holder.wellDetailButton.setOnClickListener { + listener!!.onWellDetailClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) + var deviceTypeView: TextView = view.findViewById(R.id.deviceTypeView) + var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) + var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) + var editButton: QMUIRoundButton = view.findViewById(R.id.editButton) + var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onHistoryClicked(position: Int) + + fun onEditClicked(position: Int) + + fun onWellDetailClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index eb24d44..a97b83f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -24,6 +24,7 @@ import com.casic.app.smartwell.sanxi.utils.Constant import com.casic.app.smartwell.sanxi.utils.DialogHelper import com.casic.app.smartwell.sanxi.view.AlarmManageActivity +import com.casic.app.smartwell.sanxi.view.DeviceManageActivity import com.casic.app.smartwell.sanxi.view.WellManageActivity import com.casic.app.smartwell.sanxi.view.WorkOrderManageActivity import com.casic.app.smartwell.sanxi.vm.AlarmViewModel @@ -326,7 +327,7 @@ } homeView.deviceDataLayout.setOnClickListener { -// requireContext().navigatePageTo() + requireContext().navigatePageTo() } homeView.orderDataLayout.setOnClickListener { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java b/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java new file mode 100644 index 0000000..fc9f820 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/model/DeviceListPageModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.sanxi.model; + +import java.util.List; + +public class DeviceListPageModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index bd311a4..0413d42 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -229,7 +229,7 @@ ): String /** - * 获取获取闸井列表 + * 获取闸井列表-分页 * * @param keywords 关键字 * @param wellType 窨井类型 @@ -360,6 +360,27 @@ ): String /** + * 获取设备列表-分页 + * + * @param keywords 关键字 + * @param wellType 窨井类型 + * @param deptid 部门ID + * @param limit 每页数据条数 + * @param offset 页码 + */ + @GET("/device/list") + suspend fun obtainDevicePageList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("deviceType") deviceType: String?, + @Query("isOnline") isOnline: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int, + @Query("sort") sort: String, + @Query("order") order: String + ): String + + /** * 获取工单详情 * * @param id 工单id diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index e35e976..fe17f7b 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -231,7 +231,7 @@ } /** - * 获取获取闸井列表-分页 + * 获取闸井列表-分页 */ suspend fun obtainWellPageList( keywords: String?, wellType: String?, deptid: String?, offset: Int @@ -346,6 +346,24 @@ ) } + /** + * 获取设备列表-分页 + */ + suspend fun obtainDevicePageList( + keywords: String?, deviceType: String?, isOnline: String?, offset: Int + ): String { + return api.obtainDevicePageList( + AuthenticationHelper.token!!, + keywords, + deviceType, + isOnline, + Constant.PAGE_LIMIT, + offset, + "id", + "asc" + ) + } + // /** // * 获取工单详情 // */ diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/view/DeviceManageActivity.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/view/DeviceManageActivity.kt new file mode 100644 index 0000000..33da83c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/view/DeviceManageActivity.kt @@ -0,0 +1,190 @@ +package com.casic.app.smartwell.sanxi.view + +import android.os.Handler +import android.view.View +import android.widget.Button +import android.widget.EditText +import android.widget.TextView +import androidx.core.view.GravityCompat +import androidx.drawerlayout.widget.DrawerLayout +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.sanxi.R +import com.casic.app.smartwell.sanxi.adapter.DeviceListAdapter +import com.casic.app.smartwell.sanxi.base.BaseActivity +import com.casic.app.smartwell.sanxi.extensions.show +import com.casic.app.smartwell.sanxi.extensions.showEmptyPage +import com.casic.app.smartwell.sanxi.model.DeviceListPageModel +import com.casic.app.smartwell.sanxi.utils.WeakReferenceHandler +import com.casic.app.smartwell.sanxi.vm.AuthenticateViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel +import kotlinx.android.synthetic.main.activity_device_manage.* +import kotlinx.android.synthetic.main.include_empty_view.* +import kotlinx.android.synthetic.main.include_select_title.* + +class DeviceManageActivity : BaseActivity(), DrawerLayout.DrawerListener { + + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var authenticateViewModel: AuthenticateViewModel + private lateinit var deviceListAdapter: DeviceListAdapter + private lateinit var deviceTypeView: TextView + private lateinit var ownerShipView: TextView + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var keywords = "" + private var deviceType = "" + + override fun initLayoutView(): Int = R.layout.activity_device_manage + + override fun setupTopBarLayout() { + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + if (rightDrawerLayout.isDrawerOpen(GravityCompat.END)) { + rightDrawerLayout.closeDrawer(GravityCompat.END) + } else { + rightDrawerLayout.openDrawer(GravityCompat.END) + } + } + rightDrawerLayout.addDrawerListener(this) + } + + override fun initData() { + weakReferenceHandler = WeakReferenceHandler(callback) + //初始化vm + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + obtainDeviceListByPage() + authenticateViewModel = ViewModelProvider(this).get(AuthenticateViewModel::class.java) + } + + override fun initEvent() { + resultRefreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + resultRefreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + deviceViewModel.deviceListPageModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + resultRefreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show() + } + dataBeans.addAll(dataRows!!) + resultRefreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022061601) + } + }) + } + + override fun onDrawerSlide(drawerView: View, slideOffset: Float) { + + } + + override fun onDrawerOpened(drawerView: View) { + val deviceCodeView = drawerView.findViewById(R.id.deviceCodeView) + deviceTypeView = drawerView.findViewById(R.id.deviceTypeView) + ownerShipView = drawerView.findViewById(R.id.ownerShipView) + val searchButton = drawerView.findViewById