From 2fe79374e8bd445d873aec148d1810d7ad452ed9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 23 Apr 2017 17:34:05 +0200 Subject: [PATCH] add the initial implementation of events repeating x times --- .../calendar/helpers/DBHelper.kt | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) 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 5506c945d..2a984f209 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -388,22 +388,33 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val startTimes = SparseIntArray(events.size) events.forEach { startTimes.put(it.id, it.startTS) - while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) { - if (it.startTS >= fromTS) { - if (it.repeatInterval % WEEK == 0) { - if (it.startTS.isTsOnValidDay(it)) { + if (it.repeatLimit >= 0) { + // events repeating by x days etc + while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) { + if (it.startTS >= fromTS) { + if (it.repeatInterval % WEEK == 0) { + if (it.startTS.isTsOnValidDay(it)) { + newEvents.add(it.copy()) + } + } else { newEvents.add(it.copy()) } - } else { + } else if (getRunningEvents && (it.startTS <= fromTS && it.endTS >= toTS)) { newEvents.add(it.copy()) } - } else if (getRunningEvents && (it.startTS <= fromTS && it.endTS >= toTS)) { - newEvents.add(it.copy()) + it.addIntervalTime() + } + } else { + // events repeating x times + while (it.startTS < toTS && it.repeatLimit < 0) { + newEvents.add(it.copy()) + it.addIntervalTime() + it.repeatLimit++ } - it.addIntervalTime() } } + // check if weekly repeatable events are on the current day val filteredEvents = ArrayList(newEvents.size) newEvents.forEach { if (it.repeatInterval != 0 && it.repeatInterval % WEEK == 0) { @@ -506,7 +517,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont do { val id = cursor.getIntValue(COL_ID) val startTS = cursor.getIntValue(COL_START_TS) - var endTS = cursor.getIntValue(COL_END_TS) + val endTS = cursor.getIntValue(COL_END_TS) val reminder1Minutes = cursor.getIntValue(COL_REMINDER_MINUTES) val reminder2Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_2) val reminder3Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_3)