properly cancel the notification if updated and set in the past, fix #142

This commit is contained in:
tibbi 2017-04-17 17:06:22 +02:00
parent 8460ed8aa6
commit 3b96c23584
1 changed files with 7 additions and 1 deletions

View File

@ -70,8 +70,10 @@ fun Context.scheduleNextEventReminder(event: Event) {
}
}
if (nextTS == 0 || nextTS < now || nextTS == Int.MAX_VALUE)
if (nextTS == 0 || nextTS < now || nextTS == Int.MAX_VALUE) {
cancelNotification(event.id)
return
}
if (event.repeatLimit == 0 || event.repeatLimit > nextTS)
scheduleEventIn(nextTS, event)
@ -115,6 +117,10 @@ fun Context.scheduleEventIn(notifTS: Int, event: Event) {
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, notifInMs, pendingIntent)
}
fun Context.cancelNotification(id: Int) {
getNotificationIntent(this, id).cancel()
}
private fun getNotificationIntent(context: Context, eventId: Int): PendingIntent {
val intent = Intent(context, NotificationReceiver::class.java)
intent.putExtra(EVENT_ID, eventId)