properly cancel the notification if updated and set in the past, fix #142
This commit is contained in:
parent
8460ed8aa6
commit
3b96c23584
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue