列表,个人中心
This commit is contained in:
@@ -26,6 +26,8 @@ class DeviceDetailActivity :
|
||||
}
|
||||
|
||||
private var device: DeviceEntity? = null
|
||||
/** 当前正在提交的眼罩目标状态,0 表示打开,1 表示关闭。 */
|
||||
private var pendingCoverOn: Boolean? = null
|
||||
override fun createBinding(inflater: LayoutInflater): DeviceDetailLayoutBinding {
|
||||
return DeviceDetailLayoutBinding.inflate(inflater)
|
||||
}
|
||||
@@ -38,7 +40,7 @@ class DeviceDetailActivity :
|
||||
ImmersionBar.with(this)
|
||||
.statusBarView(binding.statusBarView)
|
||||
.statusBarDarkFont(true)
|
||||
.navigationBarColor(R.color.color_zhu)
|
||||
.navigationBarColor(R.color.white)
|
||||
.navigationBarDarkIcon(true)
|
||||
.init()
|
||||
}
|
||||
@@ -46,7 +48,7 @@ class DeviceDetailActivity :
|
||||
|
||||
override fun initView(savedInstanceState: Bundle?) {
|
||||
device = intent.getSerializableExtra(EXTRA_DEVICE) as? DeviceEntity
|
||||
binding.includedTitle.tvTitle.text = device?.name ?: "设备详情"
|
||||
binding.includeTitle.tvTitle.text = device?.name ?: "设备详情"
|
||||
val deviceNo = device?.deviceNo
|
||||
if (deviceNo.isNullOrBlank()) {
|
||||
showError("设备信息无效")
|
||||
@@ -57,7 +59,8 @@ class DeviceDetailActivity :
|
||||
listOf(
|
||||
binding.tvBind,
|
||||
binding.switchCtrl,
|
||||
binding.includedTitle.imgBack,
|
||||
binding.imgSwitchCtrl,
|
||||
binding.includeTitle.imgBack,
|
||||
).forEach { button ->
|
||||
button.setOnClickListener(this)
|
||||
}
|
||||
@@ -68,16 +71,23 @@ class DeviceDetailActivity :
|
||||
R.id.img_back ->{
|
||||
finish()
|
||||
}
|
||||
R.id.switch_ctrl ->{
|
||||
if(device?.status == "0"){
|
||||
showMessage("设备已经离线")
|
||||
return;
|
||||
}
|
||||
|
||||
R.id.img_switch_ctrl ->{
|
||||
val currentDevice = device ?: return
|
||||
// hoodCoverOn:0 表示打开,1 表示关闭;点击后发送切换后的目标状态。
|
||||
if (currentDevice.status == "0") {
|
||||
showMessage("设备已经离线")
|
||||
return
|
||||
}
|
||||
|
||||
// 根据当前服务端状态计算目标状态,再由图片按钮统一发起控制请求。
|
||||
val coverOn = currentDevice.hoodCoverOn != HOOD_COVER_ON
|
||||
pendingCoverOn = coverOn
|
||||
presenter?.controlEye(currentDevice.deviceNo, coverOn)
|
||||
}
|
||||
|
||||
R.id.switch_ctrl ->{
|
||||
// 开关控件仅保留展示用途,实际控制统一由图片按钮处理。
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,20 +101,31 @@ class DeviceDetailActivity :
|
||||
|
||||
override fun getDeviceDetailSuccess(device: DeviceEntity) {
|
||||
this.device = device
|
||||
binding.includedTitle.tvTitle.text = device.name
|
||||
binding.includeTitle.tvTitle.text = device.name
|
||||
binding.tvBind.text = "设备编号:${device.deviceNo}"
|
||||
binding.switchCtrl.isChecked = device.hoodCoverOn == HOOD_COVER_ON
|
||||
updateCoverControlState(device.hoodCoverOn == HOOD_COVER_ON)
|
||||
}
|
||||
|
||||
override fun controlEyeSuccess(message: String) {
|
||||
showMessage(message)
|
||||
val coverOn = pendingCoverOn ?: return
|
||||
pendingCoverOn = null
|
||||
device = device?.copy(
|
||||
hoodCoverOn = if (binding.switchCtrl.isChecked) {
|
||||
hoodCoverOn = if (coverOn) {
|
||||
HOOD_COVER_ON
|
||||
} else {
|
||||
HOOD_COVER_OFF
|
||||
}
|
||||
)
|
||||
updateCoverControlState(coverOn)
|
||||
}
|
||||
|
||||
/** 同步开关控件和图片按钮的视觉状态,避免请求成功前出现错误状态。 */
|
||||
private fun updateCoverControlState(coverOn: Boolean) {
|
||||
binding.switchCtrl.isChecked = coverOn
|
||||
binding.imgSwitchCtrl.setImageResource(
|
||||
if (coverOn) R.mipmap.icon_switch_on else R.mipmap.icon_switch_off
|
||||
)
|
||||
}
|
||||
|
||||
override fun bindDeviceSuccess(message: String) {
|
||||
|
||||
Reference in New Issue
Block a user