update existing caldav event if it changed

This commit is contained in:
tibbi 2017-08-15 21:19:25 +02:00
parent 8c4a8ec2a2
commit 3ed2c4e472
1 changed files with 13 additions and 5 deletions

View File

@ -268,11 +268,10 @@ fun Context.getCalDAVCalendars(ids: String = ""): List<CalDAVCalendar> {
}
fun Context.fetchCalDAVCalendarEvents(calendarId: Long, eventTypeId: Int) {
val importIdsMap = HashMap<String, Int>()
val importIdsMap = HashMap<String, Event>()
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())