fix reminders of non-repeating events
This commit is contained in:
parent
508b64377d
commit
ace487eae4
|
@ -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)
|
||||
|
|
|
@ -34,8 +34,6 @@ 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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue