From d0e98c7e095e02ebe2db3cc6dff5ec599e1a2811 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 21 Sep 2018 21:27:29 +0200 Subject: [PATCH] delay notifications by 1 second to avoid glitches at rescheduling and triggering --- .../com/simplemobiletools/calendar/extensions/Context.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 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 ccbb4314c..c03dde088 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -107,15 +107,16 @@ fun Context.scheduleEventIn(notifTS: Long, event: Event, activity: SimpleActivit return } + val newNotifTS = notifTS + 1000 if (activity != null) { - val secondsTillNotification = (notifTS - System.currentTimeMillis()) / 1000 + val secondsTillNotification = (newNotifTS - System.currentTimeMillis()) / 1000 val msg = String.format(getString(R.string.reminder_triggers_in), formatSecondsToTimeString(secondsTillNotification.toInt())) activity.toast(msg) } val pendingIntent = getNotificationIntent(applicationContext, event) val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager - AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, notifTS, pendingIntent) + AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, newNotifTS, pendingIntent) } fun Context.cancelNotification(id: Int) {