From b83605bb4bb18ccfa1b73cae2865eebdf5f6f33b Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 13 Jun 2018 12:09:41 +0200 Subject: [PATCH] fix #243, allow deleting future occurrences of repeating events --- .../calendar/activities/EventActivity.kt | 4 +--- .../calendar/adapters/DayEventsAdapter.kt | 4 +++- .../calendar/adapters/EventListAdapter.kt | 4 +++- .../com/simplemobiletools/calendar/helpers/DBHelper.kt | 10 ++++++++++ 4 files changed, 17 insertions(+), 5 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 5192677ec..6f43608ed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -565,9 +565,7 @@ class EventActivity : SimpleActivity() { DeleteEventDialog(this, arrayListOf(mEvent.id)) { when (it) { DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true) - DELETE_FUTURE_OCCURRENCES -> { - - } + DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id, mEventOccurrenceTS) DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true) } finish() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt index a3e19e0e1..c9604bd46 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt @@ -129,7 +129,9 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList, r } } DELETE_FUTURE_OCCURRENCES -> { - + eventIds.forEachIndexed { index, value -> + activity.dbHelper.addEventRepeatLimit(value, timestamps[index]) + } } DELETE_ALL_OCCURRENCES -> { val eventIDs = Array(eventIds.size, { i -> (eventIds[i].toString()) }) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt index dbeec802a..2ffa05084 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt @@ -225,7 +225,9 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList { - + eventIds.forEachIndexed { index, value -> + activity.dbHelper.addEventRepeatLimit(value, timestamps[index]) + } } DELETE_ALL_OCCURRENCES -> { val eventIDs = Array(eventIds.size, { i -> (eventIds[i].toString()) }) 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 c84a05fe8..17d0220aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -16,6 +16,7 @@ import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.getLongValue import com.simplemobiletools.commons.extensions.getStringValue +import com.simplemobiletools.commons.helpers.DAY_SECONDS import org.joda.time.DateTime import java.util.* import kotlin.collections.ArrayList @@ -552,6 +553,15 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } } + fun addEventRepeatLimit(eventId: Int, limitTS: Int) { + val values = ContentValues() + values.put(COL_REPEAT_LIMIT, limitTS - DAY_SECONDS) + + val selection = "$COL_EVENT_ID = ?" + val selectionArgs = arrayOf(eventId.toString()) + mDb.update(META_TABLE_NAME, values, selection, selectionArgs) + } + fun deleteEventTypes(eventTypes: ArrayList, deleteEvents: Boolean, callback: (deletedCnt: Int) -> Unit) { var deleteIds = eventTypes.filter { it.caldavCalendarId == 0 }.map { it.id } deleteIds = deleteIds.filter { it != DBHelper.REGULAR_EVENT_TYPE_ID } as ArrayList