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 (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
}
}

View file

@ -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)
}

View file

@ -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<String>
repetitionExceptions = newRepetitionExceptions
}
var isPastEvent: Boolean
get() = flags and FLAG_IS_PAST_EVENT != 0
set(isPastEvent) {