move running event fetching in Room

This commit is contained in:
tibbi 2018-11-16 15:28:10 +01:00
parent 50c6826ec0
commit 69a23c0d5f
3 changed files with 9 additions and 16 deletions

View File

@ -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)
}
}

View File

@ -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<Event> {
val events = ArrayList<Event>()
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<Event> {
val currTime = getNowSeconds().toString()
var events = ArrayList<Event>()

View File

@ -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<Event> {
val ts = getNowSeconds()
val events = eventsDB.getOneTimeEventsFromTo(ts, ts).toMutableList() as ArrayList<Event>
events.addAll(getRepeatableEventsFor(ts, ts))
return events
}
}