|
|
@@ -1,6 +1,9 @@
|
|
|
package com.grkj.iscs.view.fragment
|
|
|
|
|
|
import android.content.Context
|
|
|
+import android.content.res.ColorStateList
|
|
|
+import android.view.View
|
|
|
+import androidx.core.content.ContextCompat
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.grkj.iscs.R
|
|
|
import com.grkj.iscs.databinding.FragmentDeviceStatusBinding
|
|
|
@@ -21,7 +24,8 @@ import com.zhy.adapter.recyclerview.base.ViewHolder
|
|
|
/**
|
|
|
* 硬件状态页
|
|
|
*/
|
|
|
-class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPresenter, FragmentDeviceStatusBinding>() {
|
|
|
+class DeviceStatusFragment :
|
|
|
+ BaseMvpFragment<IDeviceStatusView, DeviceStatusPresenter, FragmentDeviceStatusBinding>() {
|
|
|
private var mRowList = mutableListOf<DockStatusBO>()
|
|
|
|
|
|
override val viewBinding: FragmentDeviceStatusBinding
|
|
|
@@ -31,8 +35,14 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
presenter?.initData(mRowList)
|
|
|
|
|
|
val adapter = MultiItemTypeAdapter(requireContext(), mRowList)
|
|
|
- adapter.addItemViewDelegate(KeyDockItemDelegate(presenter))
|
|
|
- adapter.addItemViewDelegate(LockDockItemDelegate(presenter, requireContext()))
|
|
|
+ adapter.addItemViewDelegate(KeyDockItemDelegate(requireContext(), presenter))
|
|
|
+ adapter.addItemViewDelegate(
|
|
|
+ LockDockItemDelegate(
|
|
|
+ requireContext(),
|
|
|
+ presenter,
|
|
|
+ requireContext()
|
|
|
+ )
|
|
|
+ )
|
|
|
adapter.addItemViewDelegate(EmptyItemDelegate())
|
|
|
mBinding?.rvDock?.adapter = adapter
|
|
|
}
|
|
|
@@ -51,7 +61,13 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
val dockList: MutableList<DockTestBean>
|
|
|
)
|
|
|
|
|
|
- class KeyDockItemDelegate(var presenter: DeviceStatusPresenter?): ItemViewDelegate<DockStatusBO> {
|
|
|
+ class KeyDockItemDelegate(var context: Context, var presenter: DeviceStatusPresenter?) :
|
|
|
+ ItemViewDelegate<DockStatusBO> {
|
|
|
+ private val statusCloseTintColor =
|
|
|
+ ContextCompat.getColor(context, R.color.common_status_red)
|
|
|
+ private val statusOpenTintColor =
|
|
|
+ ContextCompat.getColor(context, R.color.common_status_green)
|
|
|
+
|
|
|
override fun getItemViewLayoutId(): Int {
|
|
|
return R.layout.item_rv_key_dock_status
|
|
|
}
|
|
|
@@ -59,14 +75,30 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
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.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)
|
|
|
@@ -79,6 +111,38 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
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?.getView<View>(R.id.v_buckle_status_1)?.backgroundTintList =
|
|
|
+ if (presenter?.getKeyBuckleLockEnabled(
|
|
|
+ row.dockList.find { it.column == "1" }?.address,
|
|
|
+ true
|
|
|
+ ) == true
|
|
|
+ ) ColorStateList.valueOf(statusCloseTintColor) else ColorStateList.valueOf(
|
|
|
+ statusOpenTintColor
|
|
|
+ )
|
|
|
+ holder?.getView<View>(R.id.v_buckle_status_2)?.backgroundTintList =
|
|
|
+ if (presenter?.getKeyBuckleLockEnabled(
|
|
|
+ row.dockList.find { it.column == "1" }?.address,
|
|
|
+ true
|
|
|
+ ) == true
|
|
|
+ ) ColorStateList.valueOf(statusCloseTintColor) else ColorStateList.valueOf(
|
|
|
+ statusOpenTintColor
|
|
|
+ )
|
|
|
+ holder?.getView<View>(R.id.v_buckle_status_3)?.backgroundTintList =
|
|
|
+ if (presenter?.getKeyBuckleLockEnabled(
|
|
|
+ row.dockList.find { it.column == "1" }?.address,
|
|
|
+ true
|
|
|
+ ) == true
|
|
|
+ ) ColorStateList.valueOf(statusCloseTintColor) else ColorStateList.valueOf(
|
|
|
+ statusOpenTintColor
|
|
|
+ )
|
|
|
+ holder?.getView<View>(R.id.v_buckle_status_4)?.backgroundTintList =
|
|
|
+ if (presenter?.getKeyBuckleLockEnabled(
|
|
|
+ row.dockList.find { it.column == "1" }?.address,
|
|
|
+ true
|
|
|
+ ) == true
|
|
|
+ ) ColorStateList.valueOf(statusCloseTintColor) else ColorStateList.valueOf(
|
|
|
+ statusOpenTintColor
|
|
|
+ )
|
|
|
holder?.setOnClickListener(R.id.tv_repair_1) {
|
|
|
presenter?.repairKey(row.dockList.find { it.column == "1" }?.address, true)
|
|
|
}
|
|
|
@@ -98,7 +162,18 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class LockDockItemDelegate(var presenter: DeviceStatusPresenter?, var ctx: Context): ItemViewDelegate<DockStatusBO> {
|
|
|
+ class LockDockItemDelegate(
|
|
|
+ var context: Context,
|
|
|
+ var presenter: DeviceStatusPresenter?,
|
|
|
+ var ctx: Context
|
|
|
+ ) : ItemViewDelegate<DockStatusBO> {
|
|
|
+ private val statusCloseTintColor =
|
|
|
+ ContextCompat.getColor(context, R.color.common_status_red)
|
|
|
+ private val statusOpenTintColor =
|
|
|
+ ContextCompat.getColor(context, R.color.common_status_green)
|
|
|
+ private val statusNotLightTintColor =
|
|
|
+ ContextCompat.getColor(context, R.color.common_status_not_light)
|
|
|
+
|
|
|
override fun getItemViewLayoutId(): Int {
|
|
|
return R.layout.item_rv_lock_dock_status
|
|
|
}
|
|
|
@@ -106,9 +181,32 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
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) {
|
|
|
+ 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))
|
|
|
+ holder?.setSelected(
|
|
|
+ R.id.root,
|
|
|
+ ModBusController.isLockExist(row.dockList[0].address, lockIdx)
|
|
|
+ )
|
|
|
+ ColorStateList.valueOf(statusNotLightTintColor).let {
|
|
|
+ holder?.getView<View>(R.id.v_buckle_status_close)?.backgroundTintList = it
|
|
|
+ holder?.getView<View>(R.id.v_buckle_status_open)?.backgroundTintList = it
|
|
|
+ }
|
|
|
+ (presenter?.getLockBuckleLockEnabled(
|
|
|
+ row.dockList[0].address,
|
|
|
+ lockIdx
|
|
|
+ ) == true).let {
|
|
|
+ if (it) {
|
|
|
+ holder?.getView<View>(R.id.v_buckle_status_close)?.backgroundTintList =
|
|
|
+ ColorStateList.valueOf(statusCloseTintColor)
|
|
|
+ } else {
|
|
|
+ holder?.getView<View>(R.id.v_buckle_status_open)?.backgroundTintList =
|
|
|
+ ColorStateList.valueOf(statusOpenTintColor)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -118,7 +216,7 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class EmptyItemDelegate: ItemViewDelegate<DockStatusBO> {
|
|
|
+ class EmptyItemDelegate : ItemViewDelegate<DockStatusBO> {
|
|
|
override fun getItemViewLayoutId(): Int {
|
|
|
return R.layout.item_rv_empty_dock_status
|
|
|
}
|