add the initial implementation of events repeating x times

This commit is contained in:
tibbi
2017-04-23 17:34:05 +02:00
parent 0e557ca7a6
commit 2fe79374e8

View File

@@ -388,22 +388,33 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val startTimes = SparseIntArray(events.size) val startTimes = SparseIntArray(events.size)
events.forEach { events.forEach {
startTimes.put(it.id, it.startTS) startTimes.put(it.id, it.startTS)
while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) { if (it.repeatLimit >= 0) {
if (it.startTS >= fromTS) { // events repeating by x days etc
if (it.repeatInterval % WEEK == 0) { while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) {
if (it.startTS.isTsOnValidDay(it)) { if (it.startTS >= fromTS) {
if (it.repeatInterval % WEEK == 0) {
if (it.startTS.isTsOnValidDay(it)) {
newEvents.add(it.copy())
}
} else {
newEvents.add(it.copy()) newEvents.add(it.copy())
} }
} else { } else if (getRunningEvents && (it.startTS <= fromTS && it.endTS >= toTS)) {
newEvents.add(it.copy()) newEvents.add(it.copy())
} }
} else if (getRunningEvents && (it.startTS <= fromTS && it.endTS >= toTS)) { it.addIntervalTime()
newEvents.add(it.copy()) }
} 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<Event>(newEvents.size) val filteredEvents = ArrayList<Event>(newEvents.size)
newEvents.forEach { newEvents.forEach {
if (it.repeatInterval != 0 && it.repeatInterval % WEEK == 0) { if (it.repeatInterval != 0 && it.repeatInterval % WEEK == 0) {
@@ -506,7 +517,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
do { do {
val id = cursor.getIntValue(COL_ID) val id = cursor.getIntValue(COL_ID)
val startTS = cursor.getIntValue(COL_START_TS) 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 reminder1Minutes = cursor.getIntValue(COL_REMINDER_MINUTES)
val reminder2Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_2) val reminder2Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_2)
val reminder3Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_3) val reminder3Minutes = cursor.getIntValue(COL_REMINDER_MINUTES_3)