From 2d33c1f8f0868ff25f17a7f48da531d4d27d7abf Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 29 May 2023 04:41:09 +0530 Subject: [PATCH] Properly handle `Update all occurrences` option Closes https://github.com/SimpleMobileTools/Simple-Calendar/issues/981 The events were moved forward because the start and end timestamps from the repeating occurrence were saved instead of the original start and end times. The call to `eventsHelper.addEventRepeatLimit()` was removed because I believe it was added there by mistake and the changes were overwritten anyways due to the next call to `eventsHelper.updateEvent()`. Another reason to remove it is to avoid triggering a CalDAV update which may interfere with the event update. --- .../calendar/pro/activities/EventActivity.kt | 14 +++++++++++++- .../calendar/pro/activities/TaskActivity.kt | 11 ++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index 44a7e245d..1a14f01d1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -1386,7 +1386,19 @@ class EventActivity : SimpleActivity() { } EDIT_ALL_OCCURRENCES -> { ensureBackgroundThread { - eventsHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS) + // Shift the start and end times of the first (original) event based on the changes made + val originalEvent = eventsDB.getEventWithId(mEvent.id!!) ?: return@ensureBackgroundThread + val originalStartTS = originalEvent.startTS + val originalEndTS = originalEvent.endTS + val oldStartTS = mOriginalStartTS + val oldEndTS = mOriginalEndTS + + mEvent.apply { + val startTSDelta = oldStartTS - startTS + val endTSDelta = oldEndTS - endTS + startTS = originalStartTS - startTSDelta + endTS = originalEndTS - endTSDelta + } eventsHelper.updateEvent(mEvent, updateAtCalDAV = true, showToasts = true) { finish() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt index 9dc569daf..8479b7bf6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt @@ -502,7 +502,16 @@ class TaskActivity : SimpleActivity() { } EDIT_ALL_OCCURRENCES -> { ensureBackgroundThread { - eventsHelper.addEventRepeatLimit(mTask.id!!, mTaskOccurrenceTS) + // Shift the start and end times of the first (original) event based on the changes made + val originalEvent = eventsDB.getTaskWithId(mTask.id!!) ?: return@ensureBackgroundThread + val originalStartTS = originalEvent.startTS + val oldStartTS = mOriginalStartTS + + mTask.apply { + val startTSDelta = oldStartTS - startTS + startTS = originalStartTS - startTSDelta + endTS = startTS + } eventsHelper.updateEvent(mTask, updateAtCalDAV = false, showToasts = true) { finish() }