couple more fixes related to caldav syncing repeatable event exceptions

This commit is contained in:
tibbi 2018-01-10 19:56:13 +01:00
parent 93c24298cc
commit db5c847035
2 changed files with 16 additions and 13 deletions

View File

@ -240,8 +240,8 @@ class CalDAVHandler(val context: Context) {
val repeatRule = Parser().parseRepeatInterval(rrule, startTS)
val event = Event(0, startTS, endTS, title, description, reminders.getOrElse(0, { -1 }),
reminders.getOrElse(1, { -1 }), reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval,
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = source,
location = location)
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, lastUpdated = System.currentTimeMillis(),
source = source, location = location)
if (event.getIsAllDay() && endTS > startTS) {
event.endTS -= DAY
@ -258,16 +258,19 @@ class CalDAVHandler(val context: Context) {
}
}
} else {
context.dbHelper.insert(event, false) {
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) {
event.parentId = parentEventId
context.dbHelper.addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt())
}
}
// 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())
}
if (title.isNotEmpty()) {
context.dbHelper.insert(event, false) {
importIdsMap.put(event.importId, event)
}
}
}

View File

@ -202,7 +202,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
fun insert(event: Event, addToCalDAV: Boolean, callback: (id: Int) -> Unit) {
if (event.startTS > event.endTS || event.title.trim().isEmpty()) {
if (event.startTS > event.endTS) {
callback(0)
return
}
@ -577,7 +577,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val cursor = getEventsCursor(selection, selectionArgs)
val events = fillEvents(cursor)
return if (events.isNotEmpty()) {
events.first().id
events.minBy { it.id }?.id ?: 0
} else {
0
}