fix reminders of non-repeating events

This commit is contained in:
Tibor Kaputa 2017-02-07 16:06:40 +01:00
parent 508b64377d
commit ace487eae4
2 changed files with 5 additions and 5 deletions

View File

@ -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)

View File

@ -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"