fix(notification): wire up updateBadgeCount to launcher badge via setNumber()

This commit is contained in:
Jens Reinemann 2026-05-18 22:10:04 +02:00
parent ab5aad8f3e
commit 6fc37ee203

View file

@ -29,6 +29,8 @@ internal class NotificationHelper @Inject constructor(
private var isMessagingAreaVisible: Boolean = false
@Volatile
private var isAppInForeground: Boolean = false
@Volatile
private var currentBadgeCount: Int = 0
private val activeSenderNotificationIds = mutableSetOf<Int>()
private val activeSenderNamesById = mutableMapOf<Int, String>()
@ -136,7 +138,7 @@ internal class NotificationHelper @Inject constructor(
.setContentTitle("Bollwerk")
.setContentText(contentText)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setNumber(senderCount)
.setNumber(currentBadgeCount)
.setAutoCancel(false)
.setOngoing(true)
.setContentIntent(pendingIntent)
@ -185,7 +187,7 @@ internal class NotificationHelper @Inject constructor(
.setContentTitle("Bollwerk")
.setContentText(remainingText)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setNumber(remainingCount)
.setNumber(currentBadgeCount)
.setAutoCancel(false)
.setOngoing(true)
.setContentIntent(buildMessagesPendingIntent())
@ -197,8 +199,16 @@ internal class NotificationHelper @Inject constructor(
/// Aktualisiert den Launcher-Badge-Zähler für ungelesene Nachrichten.
fun updateBadgeCount(count: Int) {
// Badge-Logik ist mit der vereinheitlichten Notification redundant.
// Kein separater Badge-Notification nötig, da die FG-Notification immer sichtbar ist.
currentBadgeCount = count
val hasActiveMessageNotifications = synchronized(activeSenderNotificationIds) {
activeSenderNotificationIds.isNotEmpty()
}
if (!hasActiveMessageNotifications) {
val notificationManager = NotificationManagerCompat.from(context)
try {
notificationManager.notify(MessagingService.NOTIFICATION_ID, buildIdleNotification())
} catch (_: SecurityException) {}
}
}
fun cancelAllMessageNotifications() {
@ -240,6 +250,7 @@ internal class NotificationHelper @Inject constructor(
.setOngoing(true)
.setSilent(true)
.setPriority(NotificationCompat.PRIORITY_MIN)
.setNumber(currentBadgeCount)
.setShowWhen(false)
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setContentIntent(openAppIntent)