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