moving more functions into Room
This commit is contained in:
parent
771f66ac8e
commit
85d614f690
4 changed files with 15 additions and 24 deletions
|
@ -305,7 +305,7 @@ class CalDAVHandler(val context: Context) {
|
|||
}
|
||||
|
||||
private fun setupCalDAVEventImportId(event: Event) {
|
||||
context.dbHelper.updateEventImportIdAndSource(event.id!!, event.importId, "$CALDAV-${event.getCalDAVCalendarId()}")
|
||||
context.eventsDB.updateEventImportIdAndSource(event.importId, "$CALDAV-${event.getCalDAVCalendarId()}", event.id!!)
|
||||
}
|
||||
|
||||
private fun fillEventContentValues(event: Event): ContentValues {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.simplemobiletools.calendar.pro.helpers
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
|
@ -82,7 +81,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
if (parentEvent != null) {
|
||||
val newId = CalDAVHandler(context).insertEventRepeatException(parentEvent, occurrenceTS)
|
||||
val newImportId = "${parentEvent.source}-$newId"
|
||||
updateEventImportIdAndSource(childEventId, newImportId, parentEvent.source)
|
||||
context.eventsDB.updateEventImportIdAndSource(newImportId, parentEvent.source, childEventId)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
|
@ -100,25 +99,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
}
|
||||
|
||||
fun deleteEventsWithType(eventTypeId: Long) {
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_EVENT_TYPE = ?"
|
||||
val selectionArgs = arrayOf(eventTypeId.toString())
|
||||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
val events = fillEvents(cursor)
|
||||
val eventIDs = events.mapNotNull { it.id }.toMutableList()
|
||||
EventsHelper(context).deleteEvents(eventIDs, true)
|
||||
}
|
||||
|
||||
fun updateEventImportIdAndSource(eventId: Long, importId: String, source: String) {
|
||||
val values = ContentValues()
|
||||
values.put(COL_IMPORT_ID, importId)
|
||||
values.put(COL_EVENT_SOURCE, source)
|
||||
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
|
||||
val selectionArgs = arrayOf(eventId.toString())
|
||||
mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs)
|
||||
}
|
||||
|
||||
fun getEventsWithSearchQuery(text: String, callback: (searchedText: String, events: List<Event>) -> Unit) {
|
||||
Thread {
|
||||
val searchQuery = "%$text%"
|
||||
|
|
|
@ -55,7 +55,7 @@ class EventsHelper(val context: Context) {
|
|||
|
||||
for (eventTypeId in deleteIds) {
|
||||
if (deleteEvents) {
|
||||
context.dbHelper.deleteEventsWithType(eventTypeId!!)
|
||||
EventsHelper(context).deleteEventsWithType(eventTypeId!!)
|
||||
} else {
|
||||
context.eventsDB.resetEventsWithType(eventTypeId!!)
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ class EventsHelper(val context: Context) {
|
|||
|
||||
fun deleteAllEvents() {
|
||||
val eventIds = context.eventsDB.getEventIds().toMutableList()
|
||||
EventsHelper(context).deleteEvents(eventIds, true)
|
||||
deleteEvents(eventIds, true)
|
||||
}
|
||||
|
||||
fun deleteEvent(id: Long, deleteFromCalDAV: Boolean) = deleteEvents(arrayListOf(id), deleteFromCalDAV)
|
||||
|
@ -168,6 +168,11 @@ class EventsHelper(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
fun deleteEventsWithType(eventTypeId: Long) {
|
||||
val eventIds = context.eventsDB.getEventIdsByEventType(eventTypeId).toMutableList()
|
||||
deleteEvents(eventIds, true)
|
||||
}
|
||||
|
||||
fun addEventRepeatLimit(eventId: Long, limitTS: Int) {
|
||||
val time = Formatter.getDateTimeFromTS(limitTS)
|
||||
context.eventRepetitionsDB.updateEventRepetitionLimit(limitTS - time.hourOfDay, eventId)
|
||||
|
|
|
@ -26,6 +26,9 @@ interface EventsDao {
|
|||
@Query("SELECT * FROM events WHERE id IN (:ids) AND import_id != \"\"")
|
||||
fun getEventsByIdsWithImportIds(ids: List<Long>): List<Event>
|
||||
|
||||
@Query("SELECT id FROM events WHERE event_type = :eventTypeId")
|
||||
fun getEventIdsByEventType(eventTypeId: Long): List<Long>
|
||||
|
||||
@Query("SELECT * FROM events WHERE id IN (:ids)")
|
||||
fun getEventsWithIds(ids: List<Long>): List<Event>
|
||||
|
||||
|
@ -47,6 +50,9 @@ interface EventsDao {
|
|||
@Query("UPDATE events SET event_type = $REGULAR_EVENT_TYPE_ID WHERE event_type = :eventTypeId")
|
||||
fun resetEventsWithType(eventTypeId: Long)
|
||||
|
||||
@Query("UPDATE events SET import_id = :importId AND source = :source WHERE id = :id")
|
||||
fun updateEventImportIdAndSource(importId: String, source: String, id: Long)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertOrUpdate(event: Event): Long
|
||||
|
||||
|
|
Loading…
Reference in a new issue