From db6c7e573847bd764c4436a07ae1f9fead2ac505 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 15 Apr 2017 21:27:21 +0200 Subject: [PATCH] properly display weekly events that occur multiple times a week --- .../simplemobiletools/calendar/extensions/Context.kt | 12 +++++------- .../simplemobiletools/calendar/helpers/DBHelper.kt | 2 +- .../com/simplemobiletools/calendar/models/Event.kt | 3 +-- 3 files changed, 7 insertions(+), 10 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 25540708b..bc105788b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -56,14 +56,9 @@ fun Context.scheduleNextEventReminder(event: Event) { val reminderSeconds = event.getReminders().reversed().map { it * 60 } reminderSeconds.forEach { var startTS = event.startTS - it - if (event.repeatInterval == DAY) { - while (startTS < now || isOccurrenceIgnored(event, startTS, it)) { - startTS += event.repeatInterval - } - nextTS = Math.min(nextTS, startTS) - } else if (event.repeatInterval == WEEK) { + if (event.repeatInterval == DAY || event.repeatInterval == WEEK) { while (startTS < now || isOccurrenceIgnored(event, startTS, it) || isWrongDay(event, startTS, it)) { - startTS += event.repeatInterval + startTS += DAY } nextTS = Math.min(nextTS, startTS) } else if (event.repeatInterval == MONTH) { @@ -87,6 +82,9 @@ private fun isOccurrenceIgnored(event: Event, startTS: Int, reminderSeconds: Int } private fun isWrongDay(event: Event, startTS: Int, reminderSeconds: Int): Boolean { + if (event.repeatInterval == DAY) + return false + val dateTime = Formatter.getDateTimeFromTS(startTS + reminderSeconds) val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt() return event.repeatRule and power == 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 1ebd91292..1ffff596c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -384,7 +384,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont for (event in events) { while (event.startTS < toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) { if (event.startTS >= fromTS) { - if (event.repeatInterval == DAY) { + if (event.repeatInterval == WEEK) { val dateTime = Formatter.getDateTimeFromTS(event.startTS) val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt() if (event.repeatRule and power != 0) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt index ae7a03e30..93ee49d7d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt @@ -20,8 +20,7 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var val currStart = Formatter.getDateTimeFromTS(startTS) val newStart: DateTime newStart = when (repeatInterval) { - DAY -> currStart.plusDays(1) - WEEK -> currStart.plusWeeks(1) + DAY, WEEK -> currStart.plusDays(1) // step through weekly repetition by days too, as it can trigger multiple times a week else -> { if (repeatInterval % YEAR == 0) { currStart.plusYears(repeatInterval / YEAR)