diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt index 8c2440535..3f761bf0e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt @@ -227,10 +227,15 @@ class CalDAVHelper(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.eventsDB.getEventIdWithImportId(parentImportId) - if (parentEventId != null) { - event.parentId = parentEventId - eventsHelper.addEventRepetitionException(parentEventId, originalInstanceTime / 1000L, false) + val parentEvent = context.eventsDB.getEventWithImportId(parentImportId) + val originalDayCode = Formatter.getDayCodeFromTS(originalInstanceTime / 1000L) + if (parentEvent != null && !parentEvent.repetitionExceptions.contains(originalDayCode)) { + event.parentId = parentEvent.id!! + parentEvent.addRepetitionException(originalDayCode) + activity!!.eventsDB.insertOrUpdate(parentEvent) + + event.parentId = parentEvent.id!! + eventsHelper.insertEvent(null, event, false) continue } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt index 41d27bcd3..21001d23c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt @@ -172,14 +172,9 @@ class IcsImporter(val activity: SimpleActivity) { } else { // if an event contains the RECURRENCE-ID field, it is an exception to a recurring event, so update its parent too val parentEvent = activity.eventsDB.getEventWithImportId(event.importId) - if (parentEvent != null) { - if (parentEvent.repetitionExceptions.contains(curRecurrenceDayCode)) { - continue - } - - parentEvent.repetitionExceptions.add(curRecurrenceDayCode) + if (parentEvent != null && !parentEvent.repetitionExceptions.contains(curRecurrenceDayCode)) { + parentEvent.addRepetitionException(curRecurrenceDayCode) activity.eventsDB.insertOrUpdate(parentEvent) - event.parentId = parentEvent.id!! eventsToInsert.add(event) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt index f814534f3..01e617bd5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Event.kt @@ -154,6 +154,13 @@ data class Event( isPastEvent = endTSToCheck < getNowSeconds() } + fun addRepetitionException(daycode: String) { + var newRepetitionExceptions = repetitionExceptions + newRepetitionExceptions.add(daycode) + newRepetitionExceptions = newRepetitionExceptions.distinct().toMutableList() as ArrayList + repetitionExceptions = newRepetitionExceptions + } + var isPastEvent: Boolean get() = flags and FLAG_IS_PAST_EVENT != 0 set(isPastEvent) {