properly handle importing CalDAV repeating event exception, related to #294
This commit is contained in:
parent
e2655f57cf
commit
b94dbe9f27
|
@ -208,6 +208,8 @@ class CalDAVHandler(val context: Context) {
|
||||||
CalendarContract.Events.DURATION,
|
CalendarContract.Events.DURATION,
|
||||||
CalendarContract.Events.ALL_DAY,
|
CalendarContract.Events.ALL_DAY,
|
||||||
CalendarContract.Events.RRULE,
|
CalendarContract.Events.RRULE,
|
||||||
|
CalendarContract.Events.ORIGINAL_ID,
|
||||||
|
CalendarContract.Events.ORIGINAL_INSTANCE_TIME,
|
||||||
CalendarContract.Events.EVENT_LOCATION)
|
CalendarContract.Events.EVENT_LOCATION)
|
||||||
|
|
||||||
val selection = "${CalendarContract.Events.CALENDAR_ID} = $calendarId"
|
val selection = "${CalendarContract.Events.CALENDAR_ID} = $calendarId"
|
||||||
|
@ -224,6 +226,8 @@ class CalDAVHandler(val context: Context) {
|
||||||
val allDay = cursor.getIntValue(CalendarContract.Events.ALL_DAY)
|
val allDay = cursor.getIntValue(CalendarContract.Events.ALL_DAY)
|
||||||
val rrule = cursor.getStringValue(CalendarContract.Events.RRULE) ?: ""
|
val rrule = cursor.getStringValue(CalendarContract.Events.RRULE) ?: ""
|
||||||
val location = cursor.getStringValue(CalendarContract.Events.EVENT_LOCATION) ?: ""
|
val location = cursor.getStringValue(CalendarContract.Events.EVENT_LOCATION) ?: ""
|
||||||
|
val originalId = cursor.getStringValue(CalendarContract.Events.ORIGINAL_ID)
|
||||||
|
val originalInstanceTime = cursor.getLongValue(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
|
||||||
val reminders = getCalDAVEventReminders(id)
|
val reminders = getCalDAVEventReminders(id)
|
||||||
|
|
||||||
if (endTS == 0) {
|
if (endTS == 0) {
|
||||||
|
@ -232,10 +236,11 @@ class CalDAVHandler(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val importId = getCalDAVEventImportId(calendarId, id)
|
val importId = getCalDAVEventImportId(calendarId, id)
|
||||||
|
val source = "$CALDAV-$calendarId"
|
||||||
val repeatRule = Parser().parseRepeatInterval(rrule, startTS)
|
val repeatRule = Parser().parseRepeatInterval(rrule, startTS)
|
||||||
val event = Event(0, startTS, endTS, title, description, reminders.getOrElse(0, { -1 }),
|
val event = Event(0, startTS, endTS, title, description, reminders.getOrElse(0, { -1 }),
|
||||||
reminders.getOrElse(1, { -1 }), reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval,
|
reminders.getOrElse(1, { -1 }), reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval,
|
||||||
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = "$CALDAV-$calendarId",
|
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = source,
|
||||||
location = location)
|
location = location)
|
||||||
|
|
||||||
if (event.getIsAllDay() && endTS > startTS) {
|
if (event.getIsAllDay() && endTS > startTS) {
|
||||||
|
@ -255,6 +260,15 @@ class CalDAVHandler(val context: Context) {
|
||||||
} else {
|
} else {
|
||||||
context.dbHelper.insert(event, false) {
|
context.dbHelper.insert(event, false) {
|
||||||
importIdsMap.put(event.importId, event)
|
importIdsMap.put(event.importId, event)
|
||||||
|
|
||||||
|
// if the event is an exception from another events repeat rule, find the original parent event
|
||||||
|
if (originalInstanceTime != 0L) {
|
||||||
|
val parentImportId = "$source-$originalId"
|
||||||
|
val parentEventId = context.dbHelper.getEventIdWithImportId(parentImportId)
|
||||||
|
if (parentEventId != 0) {
|
||||||
|
context.dbHelper.addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
|
|
|
@ -565,12 +565,24 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
val cursor = getEventsCursor(selection, selectionArgs)
|
val cursor = getEventsCursor(selection, selectionArgs)
|
||||||
val events = fillEvents(cursor)
|
val events = fillEvents(cursor)
|
||||||
return if (events.isNotEmpty()) {
|
return if (events.isNotEmpty()) {
|
||||||
events[0]
|
events.first()
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getEventIdWithImportId(id: String): Int {
|
||||||
|
val selection = "$MAIN_TABLE_NAME.$COL_IMPORT_ID = ?"
|
||||||
|
val selectionArgs = arrayOf(id)
|
||||||
|
val cursor = getEventsCursor(selection, selectionArgs)
|
||||||
|
val events = fillEvents(cursor)
|
||||||
|
return if (events.isNotEmpty()) {
|
||||||
|
events.first().id
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: MutableList<Event>) -> Unit) {
|
fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: MutableList<Event>) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
getEventsInBackground(fromTS, toTS, eventId, callback)
|
getEventsInBackground(fromTS, toTS, eventId, callback)
|
||||||
|
|
Loading…
Reference in New Issue