delay notifications by 1 second to avoid glitches at rescheduling and triggering

This commit is contained in:
tibbi 2018-09-21 21:27:29 +02:00
parent 295c5efe69
commit d0e98c7e09
1 changed files with 3 additions and 2 deletions

View File

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