From a4ee9eee52c020247cf096378330f6a9046229f3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 Mar 2017 19:39:29 +0100 Subject: [PATCH] properly delete just 1 event occurrence from event activity --- .../calendar/activities/EventActivity.kt | 5 +++-- .../calendar/helpers/DBHelper.kt | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index f2c536c7f..8c005b9a4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -260,10 +260,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { private fun deleteEvent() { DeleteEventDialog(this, arrayListOf(mEvent.id)) { + val db = DBHelper.newInstance(applicationContext, null) if (it) { - DBHelper.newInstance(applicationContext, this).deleteEvents(arrayOf(mEvent.id.toString())) + db.deleteEvents(arrayOf(mEvent.id.toString())) } else { - + db.deleteEventOccurrence(mEvent.id, mEventOccurrenceTS) } finish() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index c54ddd59c..b4c3e6428 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -181,6 +181,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont put(COL_IMPORT_ID, event.importId) put(COL_FLAGS, event.flags) put(COL_EVENT_TYPE, event.eventType) + put(COL_PARENT_EVENT_ID, 0) } } @@ -229,6 +230,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } } + private fun fillExceptionValues(parentEventId: Int, occurrenceTS: Int): ContentValues { + return ContentValues().apply { + put(COL_PARENT_EVENT_ID, parentEventId) + put(COL_OCCURRENCE_TIMESTAMP, occurrenceTS) + } + } + fun getEventTypeIdWithTitle(title: String): Int { val cols = arrayOf(COL_TYPE_ID) val selection = "$COL_TYPE_TITLE = ? COLLATE NOCASE" @@ -278,6 +286,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont mEventsListener?.eventsDeleted(ids.size) } + fun deleteEventOccurrence(parentEventId: Int, occurrenceTS: Int) { + val exceptionSelection = "$COL_PARENT_EVENT_ID = $parentEventId AND $COL_OCCURRENCE_TIMESTAMP = $occurrenceTS" + mDb.delete(EXCEPTIONS_TABLE_NAME, exceptionSelection, null) + + val values = fillExceptionValues(parentEventId, occurrenceTS) + mDb.insert(EXCEPTIONS_TABLE_NAME, null, values) + } + fun deleteEventTypes(ids: ArrayList, callback: (deletedCnt: Int) -> Unit) { var deleteIds = ids if (ids.contains(DBHelper.REGULAR_EVENT_TYPE_ID))