Fixed minor bugs regarding notification cancellation
This commit is contained in:
parent
0785945635
commit
fd4214ccf3
@ -15,14 +15,14 @@ abstract class NotificationService : Service() {
|
|||||||
abstract val defaultNotification: NotificationCompat.Builder
|
abstract val defaultNotification: NotificationCompat.Builder
|
||||||
|
|
||||||
private val manager get() = getSystemService<NotificationManager>()
|
private val manager get() = getSystemService<NotificationManager>()
|
||||||
private val hasNotifications get() = notifications.isEmpty()
|
private val hasNotifications get() = notifications.isNotEmpty()
|
||||||
|
|
||||||
private val notifications =
|
private val notifications =
|
||||||
Collections.synchronizedMap(mutableMapOf<Int, NotificationCompat.Builder>())
|
Collections.synchronizedMap(mutableMapOf<Int, NotificationCompat.Builder>())
|
||||||
|
|
||||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||||
super.onTaskRemoved(rootIntent)
|
super.onTaskRemoved(rootIntent)
|
||||||
notifications.values.forEach { cancel(it.hashCode()) }
|
notifications.forEach { cancel(it.key) }
|
||||||
notifications.clear()
|
notifications.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,15 +45,12 @@ abstract class NotificationService : Service() {
|
|||||||
id: Int,
|
id: Int,
|
||||||
editBody: (NotificationCompat.Builder) -> NotificationCompat.Builder? = { null }
|
editBody: (NotificationCompat.Builder) -> NotificationCompat.Builder? = { null }
|
||||||
) {
|
) {
|
||||||
val currentNotification = remove(id)?.run(editBody) ?: let {
|
val currentNotification = remove(id)?.run(editBody)
|
||||||
cancel(id)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
updateForeground()
|
updateForeground()
|
||||||
|
|
||||||
cancel(id)
|
cancel(id)
|
||||||
notify(nextInt(), currentNotification.build())
|
currentNotification?.let { notify(nextInt(), it.build()) }
|
||||||
|
|
||||||
if (!hasNotifications) {
|
if (!hasNotifications) {
|
||||||
stopForeground(true)
|
stopForeground(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user