move running event fetching in Room
This commit is contained in:
parent
50c6826ec0
commit
69a23c0d5f
|
@ -78,7 +78,7 @@ fun Context.updateListWidget() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.scheduleAllEvents() {
|
fun Context.scheduleAllEvents() {
|
||||||
val events = eventsDB.getEventsAtReboot(DateTime.now().seconds())
|
val events = eventsDB.getEventsAtReboot(getNowSeconds())
|
||||||
events.forEach {
|
events.forEach {
|
||||||
scheduleNextEventReminder(it)
|
scheduleNextEventReminder(it)
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ fun Context.getRepetitionText(seconds: Int) = when (seconds) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.notifyRunningEvents() {
|
fun Context.notifyRunningEvents() {
|
||||||
dbHelper.getRunningEvents().filter { it.getReminders().isNotEmpty() }.forEach {
|
eventsHelper.getRunningEvents().filter { it.getReminders().isNotEmpty() }.forEach {
|
||||||
notifyEvent(it)
|
notifyEvent(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,19 +53,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
|
|
||||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
|
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> {
|
fun getEventsToExport(includePast: Boolean): ArrayList<Event> {
|
||||||
val currTime = getNowSeconds().toString()
|
val currTime = getNowSeconds().toString()
|
||||||
var events = ArrayList<Event>()
|
var events = ArrayList<Event>()
|
||||||
|
|
|
@ -8,7 +8,6 @@ import com.simplemobiletools.calendar.pro.extensions.*
|
||||||
import com.simplemobiletools.calendar.pro.models.Event
|
import com.simplemobiletools.calendar.pro.models.Event
|
||||||
import com.simplemobiletools.calendar.pro.models.EventRepetitionException
|
import com.simplemobiletools.calendar.pro.models.EventRepetitionException
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
import com.simplemobiletools.calendar.pro.models.EventType
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class EventsHelper(val context: Context) {
|
class EventsHelper(val context: Context) {
|
||||||
private val config = context.config
|
private val config = context.config
|
||||||
|
@ -405,4 +404,11 @@ class EventsHelper(val context: Context) {
|
||||||
}
|
}
|
||||||
return events
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue