修改识别模式
This commit is contained in:
@@ -30,6 +30,7 @@ import com.example.defenseapplication.bean.FamilyBean
|
||||
import com.example.defenseapplication.bean.SwitchFamilyRequest
|
||||
import com.example.defenseapplication.databinding.HomeMenuFragmentBinding
|
||||
import com.example.defenseapplication.utils.DeviceIdEvent
|
||||
import com.example.defenseapplication.utils.DeviceUpdateEvent
|
||||
import com.example.defenseapplication.utils.FamilySwitchEvent
|
||||
import com.example.defenseapplication.utils.MessageStatusManager
|
||||
import com.example.defenseapplication.utils.RetrofitNetwork
|
||||
@@ -154,6 +155,12 @@ class HomeMenuFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private val deviceUpdateListener = object : DeviceUpdateEvent.DeviceUpdateListener {
|
||||
override fun onDeviceUpdated(deviceId: String) {
|
||||
refreshDeviceList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateFamilyDisplayText(familyName: String) {
|
||||
val familyBean = familyBeanList.find { it.parentName == familyName }
|
||||
val isAdmin = familyBean?.role == "appadmin"
|
||||
@@ -212,6 +219,7 @@ class HomeMenuFragment : Fragment() {
|
||||
|
||||
MessageStatusManager.addListener(unreadCountChangeListener)
|
||||
FamilySwitchEvent.addListener(familySwitchListener)
|
||||
DeviceUpdateEvent.addListener(deviceUpdateListener)
|
||||
updateUnreadCountUI(MessageStatusManager.getUnreadCount())
|
||||
}
|
||||
|
||||
@@ -448,7 +456,7 @@ class HomeMenuFragment : Fragment() {
|
||||
|
||||
private fun updateDeviceList() {
|
||||
val deviceUiList = deviceBeanList.map {
|
||||
DeviceUi(it.deviceName, it.status, it.id)
|
||||
DeviceUi(it.deviceName ?: "", it.status ?: "", it.id ?: "")
|
||||
}
|
||||
|
||||
if (deviceUiList.isEmpty()) {
|
||||
@@ -518,6 +526,7 @@ class HomeMenuFragment : Fragment() {
|
||||
binding.rvDeviceList.adapter = null
|
||||
MessageStatusManager.removeListener(unreadCountChangeListener)
|
||||
FamilySwitchEvent.removeListener(familySwitchListener)
|
||||
DeviceUpdateEvent.removeListener(deviceUpdateListener)
|
||||
_binding = null // 避免内存泄漏
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user