From 77a6a0fa9d58c312b6338ff983a3c5b81cc60d5e Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 15 Aug 2017 23:27:48 +0200 Subject: [PATCH] update the event importId and source after creating and syncing with caldav --- .../simplemobiletools/calendar/extensions/Context.kt | 8 ++++++-- .../com/simplemobiletools/calendar/helpers/DBHelper.kt | 10 ++++++++++ .../simplemobiletools/calendar/helpers/IcsExporter.kt | 2 +- .../com/simplemobiletools/calendar/helpers/Parser.kt | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 2d6e326ab..985a8bd63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -337,7 +337,7 @@ fun Context.fetchCalDAVCalendarEvents(calendarId: Long, eventTypeId: Int) { } } -fun Context.addCalDAVEvent(event: Event, calendarId: Int) { +fun Context.addCalDAVEvent(event: Event, calendarId: Long) { val durationMinutes = (event.endTS - event.startTS) / 1000 / 60 val uri = CalendarContract.Events.CONTENT_URI val values = ContentValues().apply { @@ -356,7 +356,11 @@ fun Context.addCalDAVEvent(event: Event, calendarId: Int) { } } - contentResolver.insert(uri, values) + val newUri = contentResolver.insert(uri, values) + val eventRemoteID = java.lang.Long.parseLong(newUri.lastPathSegment) + + val importId = getCalDAVEventImportId(calendarId, eventRemoteID) + dbHelper.updateEventImportIdAndSource(event.id, importId, "$CALDAV-$calendarId") } fun Context.getCalDAVEventReminders(eventId: Long): List { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 9d33fa999..de77a8a2c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -417,6 +417,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) } + fun updateEventImportIdAndSource(eventId: Int, importId: String, source: String) { + val values = ContentValues() + values.put(COL_IMPORT_ID, importId) + values.put(COL_EVENT_SOURCE, source) + + val selection = "$MAIN_TABLE_NAME.$COL_ID = ?" + val selectionArgs = arrayOf(eventId.toString()) + mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) + } + fun getImportIds(): ArrayList { val ids = ArrayList() val columns = arrayOf(COL_IMPORT_ID) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt index 68a0baf2a..845155f9a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt @@ -38,7 +38,7 @@ class IcsExporter { } out.writeLn("$STATUS$CONFIRMED") - Parser().getShortRepeatInterval(event).let { if (it.isNotEmpty()) out.writeLn(it) } + Parser().getShortRepeatInterval(event).let { if (it.isNotEmpty()) out.writeLn("$RRULE$it") } fillReminders(event, out) fillIgnoredOccurrences(event, out) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Parser.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Parser.kt index 7aa275c18..a71d506cd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Parser.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Parser.kt @@ -105,7 +105,7 @@ class Parser { val interval = getInterval(repeatInterval) val repeatLimit = getRepeatLimitString(event) val byDay = getByDay(event) - return "$RRULE$FREQ=$freq;$INTERVAL=$interval$repeatLimit$byDay" + return "$FREQ=$freq;$INTERVAL=$interval$repeatLimit$byDay" } private fun getFreq(interval: Int): String {