diff --git a/app/src/main/java/de/bollwerk/app/notification/NotificationHelper.kt b/app/src/main/java/de/bollwerk/app/notification/NotificationHelper.kt index 5c5b53e..a218475 100644 --- a/app/src/main/java/de/bollwerk/app/notification/NotificationHelper.kt +++ b/app/src/main/java/de/bollwerk/app/notification/NotificationHelper.kt @@ -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() private val activeSenderNamesById = mutableMapOf() @@ -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)