切换家庭联动
This commit is contained in:
@@ -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>>
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user