mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
allow fetching specific events with Room
This commit is contained in:
@@ -67,7 +67,7 @@ class EventActivity : SimpleActivity() {
|
||||
|
||||
val eventId = intent.getLongExtra(EVENT_ID, 0L)
|
||||
Thread {
|
||||
val event = dbHelper.getEventWithId(eventId)
|
||||
val event = eventsDB.getEventWithId(eventId)
|
||||
if (eventId != 0L && event == null) {
|
||||
finish()
|
||||
return@Thread
|
||||
|
@@ -3,7 +3,7 @@ package com.simplemobiletools.calendar.pro.activities
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsDB
|
||||
import com.simplemobiletools.calendar.pro.extensions.rescheduleReminder
|
||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
||||
import com.simplemobiletools.commons.extensions.showPickSecondsDialogHelper
|
||||
@@ -14,7 +14,7 @@ class SnoozeReminderActivity : AppCompatActivity() {
|
||||
|
||||
showPickSecondsDialogHelper(config.snoozeTime, true, cancelCallback = { dialogCancelled() }) {
|
||||
val eventId = intent.getLongExtra(EVENT_ID, 0L)
|
||||
val event = dbHelper.getEventWithId(eventId)
|
||||
val event = eventsDB.getEventWithId(eventId)
|
||||
config.snoozeTime = it / 60
|
||||
rescheduleReminder(event, it / 60)
|
||||
finishActivity()
|
||||
|
@@ -60,7 +60,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
|
||||
|
||||
private fun fillExceptionValues(parentEventId: Long, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String?, callback: (eventRepetitionException: EventRepetitionException) -> Unit) {
|
||||
val childEvent = getEventWithId(parentEventId) ?: return
|
||||
val childEvent = context.eventsDB.getEventWithId(parentEventId) ?: return
|
||||
|
||||
childEvent.apply {
|
||||
id = 0
|
||||
@@ -79,7 +79,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
|
||||
Thread {
|
||||
if (addToCalDAV && context.config.caldavSync) {
|
||||
val parentEvent = getEventWithId(parentEventId)
|
||||
val parentEvent = context.eventsDB.getEventWithId(parentEventId)
|
||||
if (parentEvent != null) {
|
||||
val newId = CalDAVHandler(context).insertEventRepeatException(parentEvent, occurrenceTS)
|
||||
val newImportId = "${parentEvent.source}-$newId"
|
||||
@@ -152,7 +152,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
fillExceptionValues(parentEventId, occurrenceTS, addToCalDAV, childImportId) {
|
||||
context.eventRepetitionExceptionsDB.insert(it)
|
||||
|
||||
val parentEvent = getEventWithId(parentEventId)
|
||||
val parentEvent = context.eventsDB.getEventWithId(parentEventId)
|
||||
if (parentEvent != null) {
|
||||
context.scheduleNextEventReminder(parentEvent, this)
|
||||
}
|
||||
@@ -164,7 +164,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
context.eventRepetitionsDB.updateEventRepetitionLimit(limitTS - time.hourOfDay, eventId)
|
||||
|
||||
if (context.config.caldavSync) {
|
||||
val event = getEventWithId(eventId)
|
||||
val event = context.eventsDB.getEventWithId(eventId)
|
||||
if (event?.getCalDAVCalendarId() != 0) {
|
||||
CalDAVHandler(context).updateCalDAVEvent(event!!)
|
||||
}
|
||||
@@ -199,18 +199,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs)
|
||||
}
|
||||
|
||||
fun getEventWithId(id: Long): Event? {
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
|
||||
val selectionArgs = arrayOf(id.toString())
|
||||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
val events = fillEvents(cursor)
|
||||
return if (events.isNotEmpty()) {
|
||||
events.first()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun getEventIdWithImportId(id: String): Long {
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_IMPORT_ID = ?"
|
||||
val selectionArgs = arrayOf(id)
|
||||
|
@@ -10,6 +10,9 @@ import com.simplemobiletools.calendar.pro.models.Event
|
||||
|
||||
@Dao
|
||||
interface EventsDao {
|
||||
@Query("SELECT * FROM events WHERE id = :id")
|
||||
fun getEventWithId(id: Long): Event?
|
||||
|
||||
@Query("SELECT * FROM events WHERE id IN (:ids)")
|
||||
fun getEventsWithIds(ids: List<Long>): List<Event>
|
||||
|
||||
|
@@ -4,10 +4,7 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.PowerManager
|
||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.notifyEvent
|
||||
import com.simplemobiletools.calendar.pro.extensions.scheduleNextEventReminder
|
||||
import com.simplemobiletools.calendar.pro.extensions.updateListWidget
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
@@ -30,7 +27,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
}
|
||||
|
||||
context.updateListWidget()
|
||||
val event = context.dbHelper.getEventWithId(id)
|
||||
val event = context.eventsDB.getEventWithId(id)
|
||||
if (event == null || event.getReminders().isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
@@ -3,14 +3,14 @@ package com.simplemobiletools.calendar.pro.services
|
||||
import android.app.IntentService
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsDB
|
||||
import com.simplemobiletools.calendar.pro.extensions.rescheduleReminder
|
||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
||||
|
||||
class SnoozeService : IntentService("Snooze") {
|
||||
override fun onHandleIntent(intent: Intent) {
|
||||
val eventId = intent.getLongExtra(EVENT_ID, 0L)
|
||||
val event = dbHelper.getEventWithId(eventId)
|
||||
val event = eventsDB.getEventWithId(eventId)
|
||||
rescheduleReminder(event, config.snoozeTime)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user