Browse Source

Merge remote-tracking branch 'origin/master'

lihao1 3 years ago
parent
commit
2486a85221

+ 24 - 6
demo/src/main/java/com/sybotan/android/demo/activities/poc/DeviceActivity.kt

@@ -39,6 +39,8 @@ class DeviceActivity : BaseActivity() {
     private lateinit var qrInfoTv: TextView
 
     private val qrCodes = mutableSetOf<String>()
+    private var spaceId = ""
+    private var position: Position? = null
 
 
     override fun onCreate(savedInstanceState: Bundle?) {
@@ -47,8 +49,8 @@ class DeviceActivity : BaseActivity() {
 
         val intent = intent
         val bundle = intent.getBundleExtra("equip")
-        val spaceId = bundle.getString("spaceId")
-        val position = bundle.getSerializable("position") as Position
+        spaceId = bundle?.getString("spaceId") ?: ""
+        position = bundle?.getSerializable("position") as? Position
 
         val deviceCl = findViewById<ConstraintLayout>(R.id.deviceCl)
         deviceOkIv = findViewById(R.id.deviceOkIv)
@@ -77,12 +79,28 @@ class DeviceActivity : BaseActivity() {
 
         val saveBtn = findViewById<Button>(R.id.saveBtn)
         saveBtn.setOnClickListener {
+            val id = spaceId
+            if (id.isEmpty()) {
+                return@setOnClickListener
+            }
+            val type = mType
+            if (type.isEmpty()) {
+                return@setOnClickListener
+            }
+            val remark = mRemark
+            if (remark.isEmpty()) {
+                return@setOnClickListener
+            }
+
+            val pos = position ?: return@setOnClickListener
+
             val deivce = ReqDeviceJob(
-                spaceId = spaceId,
-                type = mType,
-                remark = mRemark,
-                position = position
+                spaceId = id,
+                type = type,
+                remark = remark,
+                position = pos
             )
+            
             mDeviceModel.addDevice(deivce)
         }