From 2d33c1f8f0868ff25f17a7f48da531d4d27d7abf Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 29 May 2023 04:41:09 +0530 Subject: [PATCH 1/2] 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() } From 75ffedca8176aaea6526079652f2945331487369 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 29 May 2023 05:32:18 +0530 Subject: [PATCH 2/2] Avoid shifting start, end times when switching calendars --- .../calendar/pro/activities/EventActivity.kt | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 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 1a14f01d1..e3044aa8c 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 @@ -1306,6 +1306,9 @@ class EventActivity : SimpleActivity() { // recreate the event if it was moved in a different CalDAV calendar if (mEvent.id != null && oldSource != newSource && oldSource != SOURCE_IMPORTED_ICS) { + if (mRepeatInterval > 0 && wasRepeatable) { + applyOriginalStartEndTimes() + } eventsHelper.deleteEvent(mEvent.id!!, true) mEvent.id = null } @@ -1386,19 +1389,7 @@ class EventActivity : SimpleActivity() { } EDIT_ALL_OCCURRENCES -> { ensureBackgroundThread { - // 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 - } + applyOriginalStartEndTimes() eventsHelper.updateEvent(mEvent, updateAtCalDAV = true, showToasts = true) { finish() } @@ -1408,6 +1399,22 @@ class EventActivity : SimpleActivity() { } } + private fun applyOriginalStartEndTimes() { + // Shift the start and end times of the first (original) event based on the changes made + val originalEvent = eventsDB.getEventWithId(mEvent.id!!) ?: return + 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 + } + } + private fun updateStartTexts() { updateStartDateText() updateStartTimeText()