|
|
@@ -1,15 +1,10 @@
|
|
|
package com.grkj.iscs.view.fragment
|
|
|
|
|
|
-import com.google.gson.Gson
|
|
|
-import com.google.gson.reflect.TypeToken
|
|
|
import com.grkj.iscs.R
|
|
|
import com.grkj.iscs.databinding.FragmentDeviceStatusBinding
|
|
|
import com.grkj.iscs.extentions.setSelected
|
|
|
import com.grkj.iscs.extentions.setVisibleWithHolder
|
|
|
import com.grkj.iscs.modbus.ModBusController
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
|
|
|
-import com.grkj.iscs.util.SPUtils
|
|
|
-import com.grkj.iscs.util.log.LogUtil
|
|
|
import com.grkj.iscs.view.base.BaseMvpFragment
|
|
|
import com.grkj.iscs.view.fragment.DockTestFragment.DockTestBean
|
|
|
import com.grkj.iscs.view.iview.IDeviceStatusView
|
|
|
@@ -21,18 +16,17 @@ import com.zhy.adapter.recyclerview.base.ViewHolder
|
|
|
* 设备状态页
|
|
|
*/
|
|
|
class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPresenter, FragmentDeviceStatusBinding>() {
|
|
|
-
|
|
|
- private var mKeyDockList = mutableListOf<DockTestBean>()
|
|
|
- private var mRowList = mutableListOf<KeyDockStatusBO>()
|
|
|
+ private var mRowKeyList = mutableListOf<KeyDockStatusBO>()
|
|
|
+ private var mRowLockList = mutableListOf<LockDockStatusBO>()
|
|
|
|
|
|
override val viewBinding: FragmentDeviceStatusBinding
|
|
|
get() = FragmentDeviceStatusBinding.inflate(layoutInflater)
|
|
|
|
|
|
override fun initView() {
|
|
|
- initData()
|
|
|
+ presenter?.initData(mRowKeyList, mRowLockList)
|
|
|
|
|
|
mBinding?.rvKey?.adapter = object :
|
|
|
- CommonAdapter<KeyDockStatusBO>(requireActivity(), R.layout.item_rv_key_dock_status, mRowList) {
|
|
|
+ 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" })
|
|
|
@@ -70,33 +64,25 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- private fun initData() {
|
|
|
- val dockConfigJson = SPUtils.getDockConfig(requireActivity())
|
|
|
- if (!dockConfigJson.isNullOrEmpty()) {
|
|
|
- val tempList: MutableList<DockTestBean> =
|
|
|
- Gson().fromJson(dockConfigJson, object : TypeToken<MutableList<DockTestBean>>() {}.type)
|
|
|
- if (tempList.isNotEmpty()) {
|
|
|
- mKeyDockList.addAll(tempList.filter { it.type == DOCK_TYPE_KEY })
|
|
|
- mKeyDockList.forEach { dock ->
|
|
|
- try {
|
|
|
- mRowList.find { it.row == dock.row.toInt() }?.let {
|
|
|
- it.dockList.add(dock)
|
|
|
- } ?: let {
|
|
|
- mRowList.add(KeyDockStatusBO(dock.row.toInt(), mutableListOf(dock)))
|
|
|
- }
|
|
|
- } catch (e: Exception) {
|
|
|
- LogUtil.e("Device status data error : ${e.message}")
|
|
|
+ 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))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
mBinding?.rvKey?.adapter?.notifyDataSetChanged()
|
|
|
+ mBinding?.rvLock?.adapter?.notifyDataSetChanged()
|
|
|
}
|
|
|
|
|
|
override fun initPresenter(): DeviceStatusPresenter {
|
|
|
@@ -107,4 +93,9 @@ class DeviceStatusFragment : BaseMvpFragment<IDeviceStatusView, DeviceStatusPres
|
|
|
val row: Int,
|
|
|
val dockList: MutableList<DockTestBean>
|
|
|
)
|
|
|
+
|
|
|
+ data class LockDockStatusBO(
|
|
|
+ val row: Int,
|
|
|
+ var dock: DockTestBean
|
|
|
+ )
|
|
|
}
|