mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-25 16:07:47 +01:00
delete invalid caldav events at sync
This commit is contained in:
parent
fe4ff6e276
commit
e718c02275
@ -55,6 +55,7 @@ class CalDAVEventsHandler(val context: Context) {
|
|||||||
|
|
||||||
fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
|
fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
|
||||||
val importIdsMap = HashMap<String, Event>()
|
val importIdsMap = HashMap<String, Event>()
|
||||||
|
val fetchedEventIds = ArrayList<String>()
|
||||||
val existingEvents = context.dbHelper.getEventsFromCalDAVCalendar(calendarId)
|
val existingEvents = context.dbHelper.getEventsFromCalDAVCalendar(calendarId)
|
||||||
existingEvents.forEach {
|
existingEvents.forEach {
|
||||||
importIdsMap.put(it.importId, it)
|
importIdsMap.put(it.importId, it)
|
||||||
@ -101,6 +102,7 @@ class CalDAVEventsHandler(val context: Context) {
|
|||||||
event.endTS -= DAY
|
event.endTS -= DAY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchedEventIds.add(importId)
|
||||||
if (importIdsMap.containsKey(event.importId)) {
|
if (importIdsMap.containsKey(event.importId)) {
|
||||||
val existingEvent = importIdsMap[importId]
|
val existingEvent = importIdsMap[importId]
|
||||||
val originalEventId = existingEvent!!.id
|
val originalEventId = existingEvent!!.id
|
||||||
@ -120,6 +122,20 @@ class CalDAVEventsHandler(val context: Context) {
|
|||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
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) {
|
fun addCalDAVEvent(event: Event) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user