设备(1)
This commit is contained in:
@@ -8,8 +8,12 @@ import com.example.defenseapplication.databinding.ItemDeviceBinding
|
||||
|
||||
data class DeviceUi(
|
||||
val name: String,
|
||||
val status: String,
|
||||
val deviceId: String = ""
|
||||
) {
|
||||
val isOnline: Boolean
|
||||
)
|
||||
get() = status == "1"
|
||||
}
|
||||
|
||||
class DeviceAdapter(
|
||||
private val onItemClick: (DeviceUi) -> Unit = {}
|
||||
@@ -39,12 +43,27 @@ class DeviceAdapter(
|
||||
|
||||
fun bind(item: DeviceUi) {
|
||||
binding.tvDeviceType.text = item.name
|
||||
if (item.isOnline) {
|
||||
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.green))
|
||||
binding.tvDeviceName.text = "\u25CF 正在运行"
|
||||
} else {
|
||||
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.red))
|
||||
binding.tvDeviceName.text = "\u25CF 离线"
|
||||
when (item.status) {
|
||||
"1" -> {
|
||||
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.green))
|
||||
binding.tvDeviceName.text = "\u25CF 在线"
|
||||
}
|
||||
"0" -> {
|
||||
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.red))
|
||||
binding.tvDeviceName.text = "\u25CF 离线"
|
||||
}
|
||||
"2" -> {
|
||||
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.orange))
|
||||
binding.tvDeviceName.text = "\u25CF 故障"
|
||||
}
|
||||
"3" -> {
|
||||
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.gray))
|
||||
binding.tvDeviceName.text = "\u25CF 到期"
|
||||
}
|
||||
else -> {
|
||||
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.gray))
|
||||
binding.tvDeviceName.text = "\u25CF 未知"
|
||||
}
|
||||
}
|
||||
binding.root.setOnClickListener {
|
||||
onItemClick(item)
|
||||
|
||||
Reference in New Issue
Block a user