Files
SecurityDefenseDevice/app/src/main/java/com/example/defenseapplication/utils/MessageStatusManager.kt
2026-05-16 17:18:05 +08:00

44 lines
1.0 KiB
Kotlin

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