From fd4214ccf328ac2daf631fdd0d84a2db682a9fef Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Thu, 11 Jul 2019 18:44:26 +0200 Subject: [PATCH] Fixed minor bugs regarding notification cancellation --- .../magisk/model/download/NotificationService.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/NotificationService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/NotificationService.kt index 59d25698d..726022cd7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/NotificationService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/NotificationService.kt @@ -15,14 +15,14 @@ abstract class NotificationService : Service() { abstract val defaultNotification: NotificationCompat.Builder private val manager get() = getSystemService() - private val hasNotifications get() = notifications.isEmpty() + private val hasNotifications get() = notifications.isNotEmpty() private val notifications = Collections.synchronizedMap(mutableMapOf()) override fun onTaskRemoved(rootIntent: Intent?) { super.onTaskRemoved(rootIntent) - notifications.values.forEach { cancel(it.hashCode()) } + notifications.forEach { cancel(it.key) } notifications.clear() } @@ -45,15 +45,12 @@ abstract class NotificationService : Service() { id: Int, editBody: (NotificationCompat.Builder) -> NotificationCompat.Builder? = { null } ) { - val currentNotification = remove(id)?.run(editBody) ?: let { - cancel(id) - return - } + val currentNotification = remove(id)?.run(editBody) updateForeground() cancel(id) - notify(nextInt(), currentNotification.build()) + currentNotification?.let { notify(nextInt(), it.build()) } if (!hasNotifications) { stopForeground(true)