diff --git a/mobile/src/full/java/org/openhab/habdroid/core/FcmMessageListenerService.kt b/mobile/src/full/java/org/openhab/habdroid/core/FcmMessageListenerService.kt index b452de9827..07a0ed34cf 100644 --- a/mobile/src/full/java/org/openhab/habdroid/core/FcmMessageListenerService.kt +++ b/mobile/src/full/java/org/openhab/habdroid/core/FcmMessageListenerService.kt @@ -73,7 +73,7 @@ class FcmMessageListenerService : FirebaseMessagingService() { "hideNotification" -> { data["tag"]?.let { tag -> notifHelper.cancelNotificationsByTag(tag) } val id = CloudNotificationId(data["persistedId"].orEmpty(), data["reference-id"]) - notifHelper.cancelNotification(id.notificationId) + notifHelper.cancelNotificationById(id) } } } diff --git a/mobile/src/main/java/org/openhab/habdroid/core/NotificationHandlingReceiver.kt b/mobile/src/main/java/org/openhab/habdroid/core/NotificationHandlingReceiver.kt index eae4d20a1a..14658876f7 100644 --- a/mobile/src/main/java/org/openhab/habdroid/core/NotificationHandlingReceiver.kt +++ b/mobile/src/main/java/org/openhab/habdroid/core/NotificationHandlingReceiver.kt @@ -35,7 +35,7 @@ class NotificationHandlingReceiver : BroadcastReceiver() { when (intent.action) { ACTION_DISMISSED -> { Log.d(TAG, "Dismissed notification $notificationId") - NotificationHelper(context).updateGroupNotification() + NotificationHelper(context).handleNotificationDismissed(notificationId) } ACTION_NOTIF_ACTION -> { val cna = IntentCompat.getParcelableExtra( diff --git a/mobile/src/main/java/org/openhab/habdroid/core/NotificationHelper.kt b/mobile/src/main/java/org/openhab/habdroid/core/NotificationHelper.kt index 46d9e92ab5..ccb8db3601 100644 --- a/mobile/src/main/java/org/openhab/habdroid/core/NotificationHelper.kt +++ b/mobile/src/main/java/org/openhab/habdroid/core/NotificationHelper.kt @@ -54,18 +54,13 @@ class NotificationHelper(private val context: Context) { updateGroupNotification() } - fun cancelNotification(notificationId: Int) { - notificationManager.cancel(notificationId) + fun cancelNotificationById(id: CloudNotificationId) { + notificationManager.cancel(id.notificationId) if (HAS_GROUPING_SUPPORT) { val active = notificationManager.activeNotifications - if (notificationId != SUMMARY_NOTIFICATION_ID && countCloudNotifications(active) == 0) { + if (countCloudNotifications(active) == 0) { // Cancel summary when removing the last sub-notification notificationManager.cancel(SUMMARY_NOTIFICATION_ID) - } else if (notificationId == SUMMARY_NOTIFICATION_ID) { - // Cancel all sub-notifications when removing the summary - for (n in active) { - notificationManager.cancel(n.id) - } } else { updateGroupNotification() } @@ -80,7 +75,19 @@ class NotificationHelper(private val context: Context) { .forEach { sbn -> notificationManager.cancel(sbn.id) } } - fun updateGroupNotification() { + fun handleNotificationDismissed(notificationId: Int) { + if (!HAS_GROUPING_SUPPORT) { + return + } + if (notificationId == SUMMARY_NOTIFICATION_ID) { + // Cancel all sub-notifications when removing the summary + notificationManager.activeNotifications.forEach { notificationManager.cancel(it.id) } + } else { + updateGroupNotification() + } + } + + private fun updateGroupNotification() { if (!HAS_GROUPING_SUPPORT) { return }