From 3ed2c4e4728f22f7ee662b30c480a04eb72a7a09 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 15 Aug 2017 21:19:25 +0200 Subject: [PATCH] update existing caldav event if it changed --- .../calendar/extensions/Context.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 8f6664eda..e00cd5954 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -268,11 +268,10 @@ fun Context.getCalDAVCalendars(ids: String = ""): List { } fun Context.fetchCalDAVCalendarEvents(calendarId: Long, eventTypeId: Int) { - val importIdsMap = HashMap() + val importIdsMap = HashMap() val existingEvents = dbHelper.getEventsFromCalDAVCalendar(calendarId) existingEvents.forEach { - it.id = 0 - importIdsMap.put(it.importId, it.hashCode()) + importIdsMap.put(it.importId, it) } val uri = CalendarContract.Events.CONTENT_URI @@ -316,9 +315,18 @@ fun Context.fetchCalDAVCalendarEvents(calendarId: Long, eventTypeId: Int) { event.endTS -= DAY } - if (importIdsMap[importId] != event.hashCode()) { + if (importIdsMap.containsKey(event.importId)) { + val existingEvent = importIdsMap[importId] + val originalEventId = existingEvent!!.id + existingEvent.id = 0 + if (existingEvent.hashCode() != event.hashCode()) { + event.id = originalEventId + dbHelper.update(event) { + } + } + } else { dbHelper.insert(event) { - + importIdsMap.put(event.importId, event) } } } while (cursor.moveToNext())