From ace487eae4417849645b13d3d7bdc24bb8da7172 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Tue, 7 Feb 2017 16:06:40 +0100 Subject: [PATCH] fix reminders of non-repeating events --- .../com/simplemobiletools/calendar/extensions/Context.kt | 6 ++++-- .../calendar/receivers/NotificationReceiver.kt | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index f13636501..4cc9bcbbe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -45,12 +45,12 @@ fun Context.scheduleNextEventReminder(event: Event) { if (event.getReminders().isEmpty()) return + val now = System.currentTimeMillis() / 1000 + 3 var nextTS = Int.MAX_VALUE val reminderSeconds = event.getReminders().reversed().map { it * 60 } reminderSeconds.forEach { var startTS = event.startTS - it - val now = System.currentTimeMillis() / 1000 + 5 if (event.repeatInterval == DAY || event.repeatInterval == WEEK || event.repeatInterval == BIWEEK) { while (startTS < now) { startTS += event.repeatInterval @@ -60,10 +60,12 @@ fun Context.scheduleNextEventReminder(event: Event) { nextTS = Math.min(nextTS, getNewTS(startTS, true)) } else if (event.repeatInterval == YEAR) { nextTS = Math.min(nextTS, getNewTS(startTS, false)) + } else if (startTS > now) { + nextTS = Math.min(nextTS, startTS) } } - if (nextTS == 0) + if (nextTS == 0 || nextTS < now || nextTS == Int.MAX_VALUE) return if (event.repeatLimit == 0 || event.repeatLimit > nextTS) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt index bb73818ba..b16f9828e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/receivers/NotificationReceiver.kt @@ -34,9 +34,7 @@ class NotificationReceiver : BroadcastReceiver() { val endTime = Formatter.getTimeFromTS(context, event.endTS) val notification = getNotification(context, pendingIntent, event.title, "${getEventTime(startTime, endTime)} ${event.description}") notificationManager.notify(id, notification) - - if (event.repeatInterval != 0) - context.scheduleNextEventReminder(event) + context.scheduleNextEventReminder(event) } private fun getEventTime(startTime: String, endTime: String) = if (startTime == endTime) startTime else "$startTime - $endTime"