From 69a23c0d5fc2a0589c61b37d8026cdf674a40a6c Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 16 Nov 2018 15:28:10 +0100 Subject: [PATCH] move running event fetching in Room --- .../calendar/pro/extensions/Context.kt | 4 ++-- .../calendar/pro/helpers/DBHelper.kt | 13 ------------- .../calendar/pro/helpers/EventsHelper.kt | 8 +++++++- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index fa06f454c..ca29d108c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -78,7 +78,7 @@ fun Context.updateListWidget() { } fun Context.scheduleAllEvents() { - val events = eventsDB.getEventsAtReboot(DateTime.now().seconds()) + val events = eventsDB.getEventsAtReboot(getNowSeconds()) events.forEach { scheduleNextEventReminder(it) } @@ -154,7 +154,7 @@ fun Context.getRepetitionText(seconds: Int) = when (seconds) { } fun Context.notifyRunningEvents() { - dbHelper.getRunningEvents().filter { it.getReminders().isNotEmpty() }.forEach { + eventsHelper.getRunningEvents().filter { it.getReminders().isNotEmpty() }.forEach { notifyEvent(it) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt index 4e624bc38..bdc06447c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt @@ -53,19 +53,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {} - fun getRunningEvents(): List { - val events = ArrayList() - val ts = getNowSeconds() - //val selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS NULL AND $COL_START_TS != 0" - val selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_START_TS != 0" - val selectionArgs = arrayOf(ts.toString(), ts.toString()) - val cursor = getEventsCursor(selection, selectionArgs) - events.addAll(fillEvents(cursor)) - - //events.addAll(getRepeatableEventsFor(ts, ts)) - return events - } - fun getEventsToExport(includePast: Boolean): ArrayList { val currTime = getNowSeconds().toString() var events = ArrayList() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt index 65ff2e186..7ee0646d0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt @@ -8,7 +8,6 @@ import com.simplemobiletools.calendar.pro.extensions.* import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.EventRepetitionException import com.simplemobiletools.calendar.pro.models.EventType -import java.util.* class EventsHelper(val context: Context) { private val config = context.config @@ -405,4 +404,11 @@ class EventsHelper(val context: Context) { } return events } + + fun getRunningEvents(): List { + val ts = getNowSeconds() + val events = eventsDB.getOneTimeEventsFromTo(ts, ts).toMutableList() as ArrayList + events.addAll(getRepeatableEventsFor(ts, ts)) + return events + } }