fix #175, properly handle the reminders of all-day events

This commit is contained in:
tibbi 2017-06-03 22:22:38 +02:00
parent 8fad741fcc
commit 242f959200
2 changed files with 13 additions and 3 deletions

View File

@ -69,8 +69,8 @@ fun Context.scheduleNextEventReminder(event: Event, dbHelper: DBHelper) {
if (it.isNotEmpty()) {
for (curEvent in it) {
for (curReminder in reminderSeconds) {
if (curEvent.startTS - curReminder > now) {
scheduleEventIn((curEvent.startTS - curReminder) * 1000L, curEvent)
if (curEvent.getEventStartTS() - curReminder > now) {
scheduleEventIn((curEvent.getEventStartTS() - curReminder) * 1000L, curEvent)
return@getEvents
}
}
@ -165,7 +165,8 @@ fun Context.notifyEvent(event: Event) {
val pendingIntent = getPendingIntent(this, event)
val startTime = Formatter.getTimeFromTS(this, event.startTS)
val endTime = Formatter.getTimeFromTS(this, event.endTS)
val notification = getNotification(this, pendingIntent, event, "${getFormattedEventTime(startTime, endTime)} ${event.description}")
val timeRange = if (event.isAllDay) getString(R.string.all_day) else getFormattedEventTime(startTime, endTime)
val notification = getNotification(this, pendingIntent, event, "$timeRange ${event.description}")
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(event.id, notification)
}

View File

@ -93,4 +93,13 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
val isAllDay = flags and FLAG_ALL_DAY != 0
fun getReminders() = setOf(reminder1Minutes, reminder2Minutes, reminder3Minutes).filter { it != REMINDER_OFF }
// properly return the start time of all-day events as midnight
fun getEventStartTS(): Int {
return if (isAllDay) {
Formatter.getDateTimeFromTS(startTS).withTime(0, 0, 0, 0).seconds()
} else {
startTS
}
}
}