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

View File

@ -107,15 +107,16 @@ fun Context.scheduleEventIn(notifTS: Long, event: Event, activity: SimpleActivit
return return
} }
val newNotifTS = notifTS + 1000
if (activity != null) { 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())) val msg = String.format(getString(R.string.reminder_triggers_in), formatSecondsToTimeString(secondsTillNotification.toInt()))
activity.toast(msg) activity.toast(msg)
} }
val pendingIntent = getNotificationIntent(applicationContext, event) val pendingIntent = getNotificationIntent(applicationContext, event)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager 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) { fun Context.cancelNotification(id: Int) {