delete invalid caldav events at sync

This commit is contained in:
tibbi 2017-08-20 18:38:33 +02:00
parent fe4ff6e276
commit e718c02275
1 changed files with 16 additions and 0 deletions

View File

@ -55,6 +55,7 @@ class CalDAVEventsHandler(val context: Context) {
fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
val importIdsMap = HashMap<String, Event>()
val fetchedEventIds = ArrayList<String>()
val existingEvents = context.dbHelper.getEventsFromCalDAVCalendar(calendarId)
existingEvents.forEach {
importIdsMap.put(it.importId, it)
@ -101,6 +102,7 @@ class CalDAVEventsHandler(val context: Context) {
event.endTS -= DAY
}
fetchedEventIds.add(importId)
if (importIdsMap.containsKey(event.importId)) {
val existingEvent = importIdsMap[importId]
val originalEventId = existingEvent!!.id
@ -120,6 +122,20 @@ class CalDAVEventsHandler(val context: Context) {
} finally {
cursor?.close()
}
val eventIdsToDelete = ArrayList<String>()
importIdsMap.keys.filter { !fetchedEventIds.contains(it) }.forEach {
val caldavEventId = it
existingEvents.forEach {
if (it.importId == caldavEventId) {
eventIdsToDelete.add(it.id.toString())
}
}
}
eventIdsToDelete.forEach {
context.dbHelper.deleteEvents(eventIdsToDelete.toTypedArray(), false)
}
}
fun addCalDAVEvent(event: Event) {