properly display weekly events that occur multiple times a week

This commit is contained in:
tibbi 2017-04-15 21:27:21 +02:00
parent 0ce8380c12
commit db6c7e5738
3 changed files with 7 additions and 10 deletions

View File

@ -56,14 +56,9 @@ fun Context.scheduleNextEventReminder(event: Event) {
val reminderSeconds = event.getReminders().reversed().map { it * 60 } val reminderSeconds = event.getReminders().reversed().map { it * 60 }
reminderSeconds.forEach { reminderSeconds.forEach {
var startTS = event.startTS - it var startTS = event.startTS - it
if (event.repeatInterval == DAY) { if (event.repeatInterval == DAY || event.repeatInterval == WEEK) {
while (startTS < now || isOccurrenceIgnored(event, startTS, it)) {
startTS += event.repeatInterval
}
nextTS = Math.min(nextTS, startTS)
} else if (event.repeatInterval == WEEK) {
while (startTS < now || isOccurrenceIgnored(event, startTS, it) || isWrongDay(event, startTS, it)) { while (startTS < now || isOccurrenceIgnored(event, startTS, it) || isWrongDay(event, startTS, it)) {
startTS += event.repeatInterval startTS += DAY
} }
nextTS = Math.min(nextTS, startTS) nextTS = Math.min(nextTS, startTS)
} else if (event.repeatInterval == MONTH) { } 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 { private fun isWrongDay(event: Event, startTS: Int, reminderSeconds: Int): Boolean {
if (event.repeatInterval == DAY)
return false
val dateTime = Formatter.getDateTimeFromTS(startTS + reminderSeconds) val dateTime = Formatter.getDateTimeFromTS(startTS + reminderSeconds)
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt() val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
return event.repeatRule and power == 0 return event.repeatRule and power == 0

View File

@ -384,7 +384,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
for (event in events) { for (event in events) {
while (event.startTS < toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) { while (event.startTS < toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) {
if (event.startTS >= fromTS) { if (event.startTS >= fromTS) {
if (event.repeatInterval == DAY) { if (event.repeatInterval == WEEK) {
val dateTime = Formatter.getDateTimeFromTS(event.startTS) val dateTime = Formatter.getDateTimeFromTS(event.startTS)
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt() val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
if (event.repeatRule and power != 0) { if (event.repeatRule and power != 0) {

View File

@ -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 currStart = Formatter.getDateTimeFromTS(startTS)
val newStart: DateTime val newStart: DateTime
newStart = when (repeatInterval) { newStart = when (repeatInterval) {
DAY -> currStart.plusDays(1) DAY, WEEK -> currStart.plusDays(1) // step through weekly repetition by days too, as it can trigger multiple times a week
WEEK -> currStart.plusWeeks(1)
else -> { else -> {
if (repeatInterval % YEAR == 0) { if (repeatInterval % YEAR == 0) {
currStart.plusYears(repeatInterval / YEAR) currStart.plusYears(repeatInterval / YEAR)