fixing some event repeating exceptions related to caldav sync handling

This commit is contained in:
tibbi 2018-12-04 16:13:49 +01:00
parent c4ba7d1165
commit e4be55a797
3 changed files with 18 additions and 11 deletions

View File

@ -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 the event is an exception from another events repeat rule, find the original parent event
if (originalInstanceTime != 0L) { if (originalInstanceTime != 0L) {
val parentImportId = "$source-$originalId" val parentImportId = "$source-$originalId"
val parentEventId = context.eventsDB.getEventIdWithImportId(parentImportId) val parentEvent = context.eventsDB.getEventWithImportId(parentImportId)
if (parentEventId != null) { val originalDayCode = Formatter.getDayCodeFromTS(originalInstanceTime / 1000L)
event.parentId = parentEventId if (parentEvent != null && !parentEvent.repetitionExceptions.contains(originalDayCode)) {
eventsHelper.addEventRepetitionException(parentEventId, originalInstanceTime / 1000L, false) event.parentId = parentEvent.id!!
parentEvent.addRepetitionException(originalDayCode)
activity!!.eventsDB.insertOrUpdate(parentEvent)
event.parentId = parentEvent.id!!
eventsHelper.insertEvent(null, event, false)
continue continue
} }
} }

View File

@ -172,14 +172,9 @@ class IcsImporter(val activity: SimpleActivity) {
} else { } else {
// if an event contains the RECURRENCE-ID field, it is an exception to a recurring event, so update its parent too // 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) val parentEvent = activity.eventsDB.getEventWithImportId(event.importId)
if (parentEvent != null) { if (parentEvent != null && !parentEvent.repetitionExceptions.contains(curRecurrenceDayCode)) {
if (parentEvent.repetitionExceptions.contains(curRecurrenceDayCode)) { parentEvent.addRepetitionException(curRecurrenceDayCode)
continue
}
parentEvent.repetitionExceptions.add(curRecurrenceDayCode)
activity.eventsDB.insertOrUpdate(parentEvent) activity.eventsDB.insertOrUpdate(parentEvent)
event.parentId = parentEvent.id!! event.parentId = parentEvent.id!!
eventsToInsert.add(event) eventsToInsert.add(event)
} }

View File

@ -154,6 +154,13 @@ data class Event(
isPastEvent = endTSToCheck < getNowSeconds() isPastEvent = endTSToCheck < getNowSeconds()
} }
fun addRepetitionException(daycode: String) {
var newRepetitionExceptions = repetitionExceptions
newRepetitionExceptions.add(daycode)
newRepetitionExceptions = newRepetitionExceptions.distinct().toMutableList() as ArrayList<String>
repetitionExceptions = newRepetitionExceptions
}
var isPastEvent: Boolean var isPastEvent: Boolean
get() = flags and FLAG_IS_PAST_EVENT != 0 get() = flags and FLAG_IS_PAST_EVENT != 0
set(isPastEvent) { set(isPastEvent) {