mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
adding a Room function for getting relevant events at reboot
This commit is contained in:
@ -78,7 +78,7 @@ fun Context.updateListWidget() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Context.scheduleAllEvents() {
|
fun Context.scheduleAllEvents() {
|
||||||
val events = dbHelper.getEventsAtReboot()
|
val events = eventsDB.getEventsAtReboot(DateTime.now().seconds())
|
||||||
events.forEach {
|
events.forEach {
|
||||||
scheduleNextEventReminder(it)
|
scheduleNextEventReminder(it)
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,14 @@ import android.database.sqlite.SQLiteDatabase
|
|||||||
import android.database.sqlite.SQLiteOpenHelper
|
import android.database.sqlite.SQLiteOpenHelper
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import androidx.collection.LongSparseArray
|
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.calendar.pro.models.Event
|
||||||
import com.simplemobiletools.commons.extensions.getIntValue
|
import com.simplemobiletools.commons.extensions.getIntValue
|
||||||
import com.simplemobiletools.commons.extensions.getLongValue
|
import com.simplemobiletools.commons.extensions.getLongValue
|
||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
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) {
|
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
|
||||||
private val MAIN_TABLE_NAME = "events"
|
private val MAIN_TABLE_NAME = "events"
|
||||||
@ -209,14 +211,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
return events
|
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> {
|
fun getEventsToExport(includePast: Boolean): ArrayList<Event> {
|
||||||
val currTime = getNowSeconds().toString()
|
val currTime = getNowSeconds().toString()
|
||||||
var events = ArrayList<Event>()
|
var events = ArrayList<Event>()
|
||||||
|
@ -47,6 +47,10 @@ interface EventsDao {
|
|||||||
@Query("SELECT * FROM events WHERE id IN (:ids)")
|
@Query("SELECT * FROM events WHERE id IN (:ids)")
|
||||||
fun getEventsWithIds(ids: List<Long>): List<Event>
|
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")
|
@Query("SELECT id FROM events")
|
||||||
fun getEventIds(): List<Long>
|
fun getEventIds(): List<Long>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user