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