|
@@ -10,8 +10,14 @@ import android.widget.TextView
|
|
|
import android.widget.Toast
|
|
|
import com.sybotan.android.demo.R
|
|
|
import com.sybotan.android.demo.activities.BaseActivity
|
|
|
+import com.sybotan.android.demo.bean.request.Position
|
|
|
+import com.sybotan.android.demo.bean.request.ReqDeviceJob
|
|
|
+import com.sybotan.android.demo.bean.result.ResDeviceModel
|
|
|
import com.sybotan.android.demo.entitiies.DeviceType
|
|
|
+import com.sybotan.android.demo.retrofit.BaseViewModelInterface
|
|
|
+import com.sybotan.android.demo.viewmodel.DeviceVM
|
|
|
import com.zbar.lib.CaptureActivity
|
|
|
+import com.sybotan.android.demo.bean.request.Z
|
|
|
|
|
|
class DeviceActivity : BaseActivity() {
|
|
|
companion object {
|
|
@@ -26,7 +32,6 @@ class DeviceActivity : BaseActivity() {
|
|
|
const val RES_CODE_POS = 4
|
|
|
}
|
|
|
|
|
|
- private var device: String = ""
|
|
|
private lateinit var infoMsgTv: TextView
|
|
|
private lateinit var infoOkIv: ImageView
|
|
|
|
|
@@ -36,6 +41,9 @@ class DeviceActivity : BaseActivity() {
|
|
|
private lateinit var qrOkIv: ImageView
|
|
|
private lateinit var qrInfoTv: TextView
|
|
|
|
|
|
+ private val qrCodes = mutableSetOf<String>()
|
|
|
+
|
|
|
+
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setContentView(R.layout.activity_device)
|
|
@@ -64,25 +72,39 @@ class DeviceActivity : BaseActivity() {
|
|
|
qrOkIv = findViewById(R.id.qrOkIv)
|
|
|
qrInfoTv = findViewById(R.id.qrInfoTv)
|
|
|
|
|
|
- /*val posCl = findViewById<ConstraintLayout>(R.id.positionCl)
|
|
|
- posCl.setOnClickListener {
|
|
|
- val intent = Intent(this, ::class.java)
|
|
|
- startActivityForResult(intent, INFO_REQ_CODE)
|
|
|
- }*/
|
|
|
-
|
|
|
val saveBtn = findViewById<Button>(R.id.saveBtn)
|
|
|
saveBtn.setOnClickListener {
|
|
|
- Toast.makeText(this@DeviceActivity, "hello", Toast.LENGTH_LONG).show()
|
|
|
+ val deivce = ReqDeviceJob(
|
|
|
+ spaceId = "12",
|
|
|
+ type = mType,
|
|
|
+ remark = mRemark,
|
|
|
+ position = Position(x = "1", y = "1",z = Z("2","wall"))
|
|
|
+ )
|
|
|
+ mDeviceModel.addDevice(deivce)
|
|
|
}
|
|
|
+
|
|
|
+ initViewModel()
|
|
|
}
|
|
|
|
|
|
- private val qrCodes = mutableSetOf<String>()
|
|
|
+ private lateinit var mDeviceModel: DeviceVM
|
|
|
+ private fun initViewModel() {
|
|
|
+ mDeviceModel = DeviceVM(BaseViewModelInterface { name, params ->
|
|
|
+ if (name == DeviceVM.DEVICE_ADD) {
|
|
|
+ val response = params as ResDeviceModel
|
|
|
+ println("response: $response")
|
|
|
+ }
|
|
|
+ }, this)
|
|
|
+ }
|
|
|
+
|
|
|
+ private var mType = ""
|
|
|
+ private var mRemark = ""
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
- // 设备信息
|
|
|
+ // 设备类型信息
|
|
|
if (requestCode == REQ_CODE_DEVICE && resultCode == RES_CODE_DEVICE) {
|
|
|
val bundle = data?.extras
|
|
|
val type = bundle?.getParcelable<DeviceType?>("type")
|
|
|
+ type?.let { mType = it.name }
|
|
|
deviceInfoTv.text = type?.name ?: ""
|
|
|
deviceOkIv.visibility = if (type != null) View.VISIBLE else View.INVISIBLE
|
|
|
}
|
|
@@ -99,10 +121,9 @@ class DeviceActivity : BaseActivity() {
|
|
|
// 记录文本信息
|
|
|
if (requestCode == REQ_CODE_INFO && resultCode == RES_CODE_INFO) {
|
|
|
val bundle = data?.extras
|
|
|
- val info = bundle?.getString("info") ?: ""
|
|
|
- infoMsgTv.text = info
|
|
|
- infoOkIv.visibility = if (info.isNotEmpty()) View.VISIBLE else View.INVISIBLE
|
|
|
- Toast.makeText(this, "info:$info", Toast.LENGTH_LONG).show()
|
|
|
+ mRemark = bundle?.getString("info") ?: ""
|
|
|
+ infoMsgTv.text = mRemark
|
|
|
+ infoOkIv.visibility = if (mRemark.isNotEmpty()) View.VISIBLE else View.INVISIBLE
|
|
|
}
|
|
|
}
|
|
|
}
|