From 403f7c0631b25ea2b66f012256fa3a562b676cd7 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 24 Jul 2021 20:36:02 -0400 Subject: [PATCH] Make sure the notification is cancelled --- .../main/java/be/mygod/vpnhotspot/ServiceNotification.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt b/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt index 587a0160..cabea3aa 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt @@ -62,11 +62,9 @@ object ServiceNotification { } } fun stopForeground(service: Service) = synchronized(this) { - deviceCountsMap.remove(service) - if (deviceCountsMap.isEmpty()) service.stopForeground(true) else { - service.stopForeground(false) - manager.notify(NOTIFICATION_ID, buildNotification(service)) - } + val shutdown = deviceCountsMap.remove(service) != null && deviceCountsMap.isEmpty() + service.stopForeground(shutdown) + if (shutdown) manager.cancel(NOTIFICATION_ID) else manager.notify(NOTIFICATION_ID, buildNotification(service)) } fun updateNotificationChannels() {