|
@@ -1,101 +1,133 @@
|
|
|
package com.grkj.iscs.view.fragment
|
|
package com.grkj.iscs.view.fragment
|
|
|
|
|
|
|
|
|
|
+import android.content.Context
|
|
|
|
|
+import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.grkj.iscs.R
|
|
import com.grkj.iscs.R
|
|
|
import com.grkj.iscs.databinding.FragmentDeviceStatusBinding
|
|
import com.grkj.iscs.databinding.FragmentDeviceStatusBinding
|
|
|
import com.grkj.iscs.extentions.setSelected
|
|
import com.grkj.iscs.extentions.setSelected
|
|
|
import com.grkj.iscs.extentions.setVisibleWithHolder
|
|
import com.grkj.iscs.extentions.setVisibleWithHolder
|
|
|
import com.grkj.iscs.modbus.ModBusController
|
|
import com.grkj.iscs.modbus.ModBusController
|
|
|
|
|
+import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
|
|
|
|
|
+import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
|
|
|
import com.grkj.iscs.view.base.BaseMvpFragment
|
|
import com.grkj.iscs.view.base.BaseMvpFragment
|
|
|
import com.grkj.iscs.view.fragment.DockTestFragment.DockTestBean
|
|
import com.grkj.iscs.view.fragment.DockTestFragment.DockTestBean
|
|
|
import com.grkj.iscs.view.iview.IDeviceStatusView
|
|
import com.grkj.iscs.view.iview.IDeviceStatusView
|
|
|
import com.grkj.iscs.view.presenter.DeviceStatusPresenter
|
|
import com.grkj.iscs.view.presenter.DeviceStatusPresenter
|
|
|
import com.zhy.adapter.recyclerview.CommonAdapter
|
|
import com.zhy.adapter.recyclerview.CommonAdapter
|
|
|
|
|
+import com.zhy.adapter.recyclerview.MultiItemTypeAdapter
|
|
|
|
|
+import com.zhy.adapter.recyclerview.base.ItemViewDelegate
|
|
|
import com.zhy.adapter.recyclerview.base.ViewHolder
|
|
import com.zhy.adapter.recyclerview.base.ViewHolder
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 设备状态页
|
|
* 设备状态页
|
|
|
*/
|
|
*/
|
|
|
class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPresenter, FragmentDeviceStatusBinding>() {
|
|
class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPresenter, FragmentDeviceStatusBinding>() {
|
|
|
- private var mRowKeyList = mutableListOf<KeyDockStatusBO>()
|
|
|
|
|
- private var mRowLockList = mutableListOf<LockDockStatusBO>()
|
|
|
|
|
|
|
+ private var mRowList = mutableListOf<DockStatusBO>()
|
|
|
|
|
|
|
|
override val viewBinding: FragmentDeviceStatusBinding
|
|
override val viewBinding: FragmentDeviceStatusBinding
|
|
|
get() = FragmentDeviceStatusBinding.inflate(layoutInflater)
|
|
get() = FragmentDeviceStatusBinding.inflate(layoutInflater)
|
|
|
|
|
|
|
|
override fun initView() {
|
|
override fun initView() {
|
|
|
- presenter?.initData(mRowKeyList, mRowLockList)
|
|
|
|
|
-
|
|
|
|
|
- mBinding?.rvKey?.adapter = object :
|
|
|
|
|
- CommonAdapter<KeyDockStatusBO>(requireActivity(), R.layout.item_rv_key_dock_status, mRowKeyList) {
|
|
|
|
|
- override fun convert(holder: ViewHolder, row: KeyDockStatusBO, position: Int) {
|
|
|
|
|
- holder.setVisibleWithHolder(R.id.ll_left, row.dockList.any { it.column == "1" })
|
|
|
|
|
- holder.setVisibleWithHolder(R.id.ll_right, row.dockList.any { it.column == "2" })
|
|
|
|
|
- holder.setSelected(R.id.iv_key_1, ModBusController.isKeyExist(row.dockList.find { it.column == "1" }?.address, true))
|
|
|
|
|
- holder.setSelected(R.id.iv_key_2, ModBusController.isKeyExist(row.dockList.find { it.column == "1" }?.address, false))
|
|
|
|
|
- holder.setSelected(R.id.iv_key_3, ModBusController.isKeyExist(row.dockList.find { it.column == "2" }?.address, true))
|
|
|
|
|
- holder.setSelected(R.id.iv_key_4, ModBusController.isKeyExist(row.dockList.find { it.column == "2" }?.address, false))
|
|
|
|
|
- val status1 = presenter?.getKeyStatus(row.dockList.find { it.column == "1" }?.address, true)
|
|
|
|
|
- val status2 = presenter?.getKeyStatus(row.dockList.find { it.column == "1" }?.address, false)
|
|
|
|
|
- val status3 = presenter?.getKeyStatus(row.dockList.find { it.column == "2" }?.address, true)
|
|
|
|
|
- val status4 = presenter?.getKeyStatus(row.dockList.find { it.column == "2" }?.address, false)
|
|
|
|
|
- holder.setSelected(R.id.rl_status_1, status1?.first == true)
|
|
|
|
|
- holder.setSelected(R.id.rl_status_2, status2?.first == true)
|
|
|
|
|
- holder.setSelected(R.id.rl_status_3, status3?.first == true)
|
|
|
|
|
- holder.setSelected(R.id.rl_status_4, status4?.first == true)
|
|
|
|
|
- holder.setText(R.id.tv_status_1, status1?.second)
|
|
|
|
|
- holder.setText(R.id.tv_status_2, status2?.second)
|
|
|
|
|
- holder.setText(R.id.tv_status_3, status3?.second)
|
|
|
|
|
- holder.setText(R.id.tv_status_4, status4?.second)
|
|
|
|
|
- holder.setVisibleWithHolder(R.id.tv_repair_1, status1?.first == false)
|
|
|
|
|
- holder.setVisibleWithHolder(R.id.tv_repair_2, status2?.first == false)
|
|
|
|
|
- holder.setVisibleWithHolder(R.id.tv_repair_3, status3?.first == false)
|
|
|
|
|
- holder.setVisibleWithHolder(R.id.tv_repair_4, status4?.first == false)
|
|
|
|
|
- holder.setOnClickListener(R.id.tv_repair_1) {
|
|
|
|
|
- presenter?.repairKey(row.dockList.find { it.column == "1" }?.address, true)
|
|
|
|
|
- }
|
|
|
|
|
- holder.setOnClickListener(R.id.tv_repair_2) {
|
|
|
|
|
- presenter?.repairKey(row.dockList.find { it.column == "1" }?.address, false)
|
|
|
|
|
- }
|
|
|
|
|
- holder.setOnClickListener(R.id.tv_repair_3) {
|
|
|
|
|
- presenter?.repairKey(row.dockList.find { it.column == "2" }?.address, true)
|
|
|
|
|
- }
|
|
|
|
|
- holder.setOnClickListener(R.id.tv_repair_4) {
|
|
|
|
|
- presenter?.repairKey(row.dockList.find { it.column == "2" }?.address, false)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ presenter?.initData(mRowList)
|
|
|
|
|
|
|
|
- mBinding?.rvLock?.adapter = object :
|
|
|
|
|
- CommonAdapter<LockDockStatusBO>(requireActivity(), R.layout.item_rv_lock_dock_status, mRowLockList) {
|
|
|
|
|
- override fun convert(holder: ViewHolder, row: LockDockStatusBO, position: Int) {
|
|
|
|
|
- val rv = holder.getView<androidx.recyclerview.widget.RecyclerView>(R.id.rv_root)
|
|
|
|
|
- rv.adapter = object :
|
|
|
|
|
- CommonAdapter<Int>(requireActivity(), R.layout.item_rv_lock_dock_child_status, row.dock.deviceList) {
|
|
|
|
|
- override fun convert(holder: ViewHolder, lockIdx: Int, position: Int) {
|
|
|
|
|
- holder.setSelected(R.id.root, ModBusController.isLockExist(row.dock.address, lockIdx))
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ val adapter = MultiItemTypeAdapter(requireContext(), mRowList)
|
|
|
|
|
+ adapter.addItemViewDelegate(KeyDockItemDelegate(presenter))
|
|
|
|
|
+ adapter.addItemViewDelegate(LockDockItemDelegate(presenter, requireContext()))
|
|
|
|
|
+ adapter.addItemViewDelegate(EmptyItemDelegate())
|
|
|
|
|
+ mBinding?.rvDock?.adapter = adapter
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
super.onResume()
|
|
|
- mBinding?.rvKey?.adapter?.notifyDataSetChanged()
|
|
|
|
|
- mBinding?.rvLock?.adapter?.notifyDataSetChanged()
|
|
|
|
|
|
|
+ mBinding?.rvDock?.adapter?.notifyDataSetChanged()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun initPresenter(): DeviceStatusPresenter {
|
|
override fun initPresenter(): DeviceStatusPresenter {
|
|
|
return DeviceStatusPresenter()
|
|
return DeviceStatusPresenter()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- data class KeyDockStatusBO(
|
|
|
|
|
|
|
+ data class DockStatusBO(
|
|
|
val row: Int,
|
|
val row: Int,
|
|
|
val dockList: MutableList<DockTestBean>
|
|
val dockList: MutableList<DockTestBean>
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- data class LockDockStatusBO(
|
|
|
|
|
- val row: Int,
|
|
|
|
|
- var dock: DockTestBean
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ class KeyDockItemDelegate(var presenter: DeviceStatusPresenter?): ItemViewDelegate<DockStatusBO> {
|
|
|
|
|
+ override fun getItemViewLayoutId(): Int {
|
|
|
|
|
+ return R.layout.item_rv_key_dock_status
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun convert(holder: ViewHolder?, row: DockStatusBO, position: Int) {
|
|
|
|
|
+ holder?.setVisibleWithHolder(R.id.ll_left, row.dockList.any { it.column == "1" })
|
|
|
|
|
+ holder?.setVisibleWithHolder(R.id.ll_right, row.dockList.any { it.column == "2" })
|
|
|
|
|
+ holder?.setSelected(R.id.iv_key_1, ModBusController.isKeyExist(row.dockList.find { it.column == "1" }?.address, true))
|
|
|
|
|
+ holder?.setSelected(R.id.iv_key_2, ModBusController.isKeyExist(row.dockList.find { it.column == "1" }?.address, false))
|
|
|
|
|
+ holder?.setSelected(R.id.iv_key_3, ModBusController.isKeyExist(row.dockList.find { it.column == "2" }?.address, true))
|
|
|
|
|
+ holder?.setSelected(R.id.iv_key_4, ModBusController.isKeyExist(row.dockList.find { it.column == "2" }?.address, false))
|
|
|
|
|
+ val status1 = presenter?.getKeyStatus(row.dockList.find { it.column == "1" }?.address, true)
|
|
|
|
|
+ val status2 = presenter?.getKeyStatus(row.dockList.find { it.column == "1" }?.address, false)
|
|
|
|
|
+ val status3 = presenter?.getKeyStatus(row.dockList.find { it.column == "2" }?.address, true)
|
|
|
|
|
+ val status4 = presenter?.getKeyStatus(row.dockList.find { it.column == "2" }?.address, false)
|
|
|
|
|
+ holder?.setSelected(R.id.rl_status_1, status1?.first == true)
|
|
|
|
|
+ holder?.setSelected(R.id.rl_status_2, status2?.first == true)
|
|
|
|
|
+ holder?.setSelected(R.id.rl_status_3, status3?.first == true)
|
|
|
|
|
+ holder?.setSelected(R.id.rl_status_4, status4?.first == true)
|
|
|
|
|
+ holder?.setText(R.id.tv_status_1, status1?.second)
|
|
|
|
|
+ holder?.setText(R.id.tv_status_2, status2?.second)
|
|
|
|
|
+ holder?.setText(R.id.tv_status_3, status3?.second)
|
|
|
|
|
+ holder?.setText(R.id.tv_status_4, status4?.second)
|
|
|
|
|
+ holder?.setVisibleWithHolder(R.id.tv_repair_1, status1?.first == false)
|
|
|
|
|
+ holder?.setVisibleWithHolder(R.id.tv_repair_2, status2?.first == false)
|
|
|
|
|
+ holder?.setVisibleWithHolder(R.id.tv_repair_3, status3?.first == false)
|
|
|
|
|
+ holder?.setVisibleWithHolder(R.id.tv_repair_4, status4?.first == false)
|
|
|
|
|
+ holder?.setOnClickListener(R.id.tv_repair_1) {
|
|
|
|
|
+ presenter?.repairKey(row.dockList.find { it.column == "1" }?.address, true)
|
|
|
|
|
+ }
|
|
|
|
|
+ holder?.setOnClickListener(R.id.tv_repair_2) {
|
|
|
|
|
+ presenter?.repairKey(row.dockList.find { it.column == "1" }?.address, false)
|
|
|
|
|
+ }
|
|
|
|
|
+ holder?.setOnClickListener(R.id.tv_repair_3) {
|
|
|
|
|
+ presenter?.repairKey(row.dockList.find { it.column == "2" }?.address, true)
|
|
|
|
|
+ }
|
|
|
|
|
+ holder?.setOnClickListener(R.id.tv_repair_4) {
|
|
|
|
|
+ presenter?.repairKey(row.dockList.find { it.column == "2" }?.address, false)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun isForViewType(item: DockStatusBO?, position: Int): Boolean {
|
|
|
|
|
+ return item?.dockList?.any { it.type == DOCK_TYPE_KEY } == true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class LockDockItemDelegate(var presenter: DeviceStatusPresenter?, var ctx: Context): ItemViewDelegate<DockStatusBO> {
|
|
|
|
|
+ override fun getItemViewLayoutId(): Int {
|
|
|
|
|
+ return R.layout.item_rv_lock_dock_status
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun convert(holder: ViewHolder?, row: DockStatusBO, position: Int) {
|
|
|
|
|
+ val rv = holder?.getView<RecyclerView>(R.id.rv_root)
|
|
|
|
|
+ rv?.adapter = object :
|
|
|
|
|
+ CommonAdapter<Int>(ctx, R.layout.item_rv_lock_dock_child_status, row.dockList[0].deviceList) {
|
|
|
|
|
+ override fun convert(holder: ViewHolder?, lockIdx: Int, position: Int) {
|
|
|
|
|
+ holder?.setSelected(R.id.root, ModBusController.isLockExist(row.dockList[0].address, lockIdx))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun isForViewType(item: DockStatusBO?, position: Int): Boolean {
|
|
|
|
|
+ return item?.dockList?.any { it.type == DOCK_TYPE_LOCK } == true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class EmptyItemDelegate: ItemViewDelegate<DockStatusBO> {
|
|
|
|
|
+ override fun getItemViewLayoutId(): Int {
|
|
|
|
|
+ return R.layout.item_rv_empty_dock_status
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun convert(holder: ViewHolder?, row: DockStatusBO, position: Int) {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun isForViewType(item: DockStatusBO?, position: Int): Boolean {
|
|
|
|
|
+ return item?.dockList?.isEmpty() == true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|