ソースを参照

修复注册状态监听在onCreate有效,在onResume失效的问题

Frankensteinly 1 年間 前
コミット
00819cb87e

+ 1 - 1
app/src/main/java/com/grkj/iscs/base/BaseActivity.kt

@@ -15,7 +15,7 @@ abstract class BaseActivity<T : ViewBinding?> : AppCompatActivity() {
 
     protected var mBinding: T? = null
     abstract val viewBinding: T
-    var loadingProgressDialog: LoadingProgressDialog? = null
+    private var loadingProgressDialog: LoadingProgressDialog? = null
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)

+ 9 - 8
app/src/main/java/com/grkj/iscs/modbus/ModBusController.kt

@@ -186,17 +186,13 @@ object ModBusController {
             return null
         }
         val dockB = dockList.find { it.addr == byteArray[0] }
-        return dockB?.parseStatus(byteArray) ?: let {
-            val temp = DockBean(byteArray[0], null, mutableListOf())
-            dockList.add(temp)
-            temp.parseStatus(byteArray)
-        }
+        return dockB?.parseStatus(byteArray)
     }
 
     /**
      * 读取设备类型
      */
-    fun readDeviceType(done: ((res: List<ByteArray>) -> Unit)? = null) {
+    private fun readDeviceType(done: ((res: List<ByteArray>) -> Unit)? = null) {
         modBusManager?.sendToAll(MBFrame.READ_DEVICE_TYPE) { res ->
             done?.invoke(res)
         }
@@ -205,8 +201,13 @@ object ModBusController {
     /**
      * 更新设备类型
      */
-    fun updateDeviceType(idx: Byte?, type: Byte?) {
-        dockList.find { it.addr == idx }?.type = type
+    private fun updateDeviceType(idx: Byte, type: Byte?) {
+        val dock = dockList.find { it.addr == idx }
+        dock?.let {
+            it.type = type
+        } ?: let {
+            dockList.add(DockBean(idx, type, mutableListOf()))
+        }
     }
 
     /**