diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt index 358f41092..27364571f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt @@ -301,8 +301,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { if (uri.path.startsWith("/events")) { // intents like content://com.android.calendar/events/1756 val eventId = uri.lastPathSegment - val id = dbHelper.getEventIdWithLastImportId(eventId) - if (id != 0L) { + val id = eventsDB.getEventIdWithLastImportId("%-$eventId") + if (id != null) { Intent(this, EventActivity::class.java).apply { putExtra(EVENT_ID, id) startActivity(this) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHandler.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHandler.kt index d608aea63..baf6d217e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHandler.kt @@ -9,10 +9,7 @@ import android.provider.CalendarContract import android.provider.CalendarContract.Reminders import android.util.SparseIntArray import com.simplemobiletools.calendar.pro.activities.SimpleActivity -import com.simplemobiletools.calendar.pro.extensions.config -import com.simplemobiletools.calendar.pro.extensions.dbHelper -import com.simplemobiletools.calendar.pro.extensions.refreshCalDAVCalendars -import com.simplemobiletools.calendar.pro.extensions.scheduleCalDAVSync +import com.simplemobiletools.calendar.pro.extensions.* import com.simplemobiletools.calendar.pro.models.CalDAVCalendar import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.EventType @@ -232,8 +229,8 @@ class CalDAVHandler(val context: Context) { // if the event is an exception from another events repeat rule, find the original parent event if (originalInstanceTime != 0L) { val parentImportId = "$source-$originalId" - val parentEventId = context.dbHelper.getEventIdWithImportId(parentImportId) - if (parentEventId != 0L) { + val parentEventId = context.eventsDB.getEventIdWithImportId(parentImportId) + if (parentEventId != null) { event.parentId = parentEventId context.dbHelper.addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt(), false, event.importId) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt index 33b635b91..5962522bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt @@ -199,30 +199,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) } - fun getEventIdWithImportId(id: String): Long { - val selection = "$MAIN_TABLE_NAME.$COL_IMPORT_ID = ?" - val selectionArgs = arrayOf(id) - val cursor = getEventsCursor(selection, selectionArgs) - val events = fillEvents(cursor) - return if (events.isNotEmpty()) { - events.minBy { it.id!! }?.id ?: 0L - } else { - 0L - } - } - - fun getEventIdWithLastImportId(id: String): Long { - val selection = "$MAIN_TABLE_NAME.$COL_IMPORT_ID LIKE ?" - val selectionArgs = arrayOf("%-$id") - val cursor = getEventsCursor(selection, selectionArgs) - val events = fillEvents(cursor) - return if (events.isNotEmpty()) { - events.minBy { it.id!! }?.id ?: 0L - } else { - 0L - } - } - fun getEventsWithSearchQuery(text: String, callback: (searchedText: String, events: List) -> Unit) { Thread { val searchQuery = "%$text%" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt index 3bf224a23..946f7cbc6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt @@ -13,6 +13,12 @@ interface EventsDao { @Query("SELECT * FROM events WHERE id = :id") fun getEventWithId(id: Long): Event? + @Query("SELECT id FROM events WHERE import_id = :importId") + fun getEventIdWithImportId(importId: String): Long? + + @Query("SELECT id FROM events WHERE import_id LIKE :importId") + fun getEventIdWithLastImportId(importId: String): Long? + @Query("SELECT * FROM events WHERE id IN (:ids)") fun getEventsWithIds(ids: List): List