adding a Room function for getting relevant events at reboot
This commit is contained in:
parent
8861cbde1a
commit
b97cbf6ce9
3 changed files with 9 additions and 11 deletions
|
@ -78,7 +78,7 @@ fun Context.updateListWidget() {
|
|||
}
|
||||
|
||||
fun Context.scheduleAllEvents() {
|
||||
val events = dbHelper.getEventsAtReboot()
|
||||
val events = eventsDB.getEventsAtReboot(DateTime.now().seconds())
|
||||
events.forEach {
|
||||
scheduleNextEventReminder(it)
|
||||
}
|
||||
|
|
|
@ -6,12 +6,14 @@ import android.database.sqlite.SQLiteDatabase
|
|||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import android.text.TextUtils
|
||||
import androidx.collection.LongSparseArray
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventTypesDB
|
||||
import com.simplemobiletools.calendar.pro.extensions.isTsOnProperDay
|
||||
import com.simplemobiletools.calendar.pro.extensions.isXWeeklyRepetition
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
import com.simplemobiletools.commons.extensions.getLongValue
|
||||
import com.simplemobiletools.commons.extensions.getStringValue
|
||||
import org.joda.time.DateTime
|
||||
|
||||
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
|
||||
private val MAIN_TABLE_NAME = "events"
|
||||
|
@ -209,14 +211,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return events
|
||||
}
|
||||
|
||||
fun getEventsAtReboot(): List<Event> {
|
||||
//val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ? OR $COL_REPEAT_INTERVAL != 0) AND $COL_START_TS != 0"
|
||||
val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ?) AND $COL_START_TS != 0"
|
||||
val selectionArgs = arrayOf(DateTime.now().seconds().toString())
|
||||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
return fillEvents(cursor)
|
||||
}
|
||||
|
||||
fun getEventsToExport(includePast: Boolean): ArrayList<Event> {
|
||||
val currTime = getNowSeconds().toString()
|
||||
var events = ArrayList<Event>()
|
||||
|
|
|
@ -47,6 +47,10 @@ interface EventsDao {
|
|||
@Query("SELECT * FROM events WHERE id IN (:ids)")
|
||||
fun getEventsWithIds(ids: List<Long>): List<Event>
|
||||
|
||||
//val selection = "$COL_REMINDER_MINUTES != -1 AND ($COL_START_TS > ? OR $COL_REPEAT_INTERVAL != 0) AND $COL_START_TS != 0"
|
||||
@Query("SELECT * FROM events WHERE reminder_1_minutes != -1 AND (start_ts > :currentTS OR repeat_interval != 0) AND start_ts != 0")
|
||||
fun getEventsAtReboot(currentTS: Long): List<Event>
|
||||
|
||||
@Query("SELECT id FROM events")
|
||||
fun getEventIds(): List<Long>
|
||||
|
||||
|
|
Loading…
Reference in a new issue