切换家庭联动

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

@@ -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)
}
}