切换家庭联动

This commit is contained in:
2026-05-16 17:18:05 +08:00
parent a8f202a906
commit 4c53c43f7b
23 changed files with 515 additions and 121 deletions

View File

@@ -7,6 +7,7 @@ import com.example.defenseapplication.bean.GetCodeBean
import bean.LoginBean
import bean.LoginRequest
import bean.RegisterRequest
import com.example.defenseapplication.bean.MessageGroup
import com.example.defenseapplication.bean.SwitchFamilyRequest
import retrofit2.http.Body
import retrofit2.http.GET
@@ -55,6 +56,12 @@ interface ApiService {
*/
@GET("/app/getdeviceList")
suspend fun getDeviceList(): GetCodeBean<List<DeviceBean>>
/**
* 查看消息列表
*/
@GET("/app/appMessage/list")
suspend fun getMessage(): GetCodeBean<List<MessageGroup>>
}

View File

@@ -0,0 +1,23 @@
package com.example.defenseapplication.utils
object FamilySwitchEvent {
private val listeners = mutableListOf<FamilySwitchListener>()
interface FamilySwitchListener {
fun onFamilySwitched(familyName: String)
}
fun addListener(listener: FamilySwitchListener) {
if (!listeners.contains(listener)) {
listeners.add(listener)
}
}
fun removeListener(listener: FamilySwitchListener) {
listeners.remove(listener)
}
fun notifyFamilySwitched(familyName: String) {
listeners.forEach { it.onFamilySwitched(familyName) }
}
}

View File

@@ -0,0 +1,44 @@
package com.example.defenseapplication.utils
object MessageStatusManager {
private var unreadCount = 0
private val listeners = mutableListOf<UnreadCountChangeListener>()
fun getUnreadCount(): Int {
return unreadCount
}
fun setUnreadCount(count: Int) {
unreadCount = if (count > 99) 99 else count
notifyListeners()
}
fun incrementUnreadCount() {
unreadCount++
if (unreadCount > 99) unreadCount = 99
notifyListeners()
}
fun clearUnreadCount() {
unreadCount = 0
notifyListeners()
}
fun addListener(listener: UnreadCountChangeListener) {
if (!listeners.contains(listener)) {
listeners.add(listener)
}
}
fun removeListener(listener: UnreadCountChangeListener) {
listeners.remove(listener)
}
private fun notifyListeners() {
listeners.forEach { it.onUnreadCountChanged(unreadCount) }
}
interface UnreadCountChangeListener {
fun onUnreadCountChanged(count: Int)
}
}