update the event importId and source after creating and syncing with caldav

This commit is contained in:
tibbi 2017-08-15 23:27:48 +02:00
parent f4c28d26f0
commit 77a6a0fa9d
4 changed files with 18 additions and 4 deletions

View File

@ -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 durationMinutes = (event.endTS - event.startTS) / 1000 / 60
val uri = CalendarContract.Events.CONTENT_URI val uri = CalendarContract.Events.CONTENT_URI
val values = ContentValues().apply { 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<Int> { fun Context.getCalDAVEventReminders(eventId: Long): List<Int> {

View File

@ -417,6 +417,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) 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<String> { fun getImportIds(): ArrayList<String> {
val ids = ArrayList<String>() val ids = ArrayList<String>()
val columns = arrayOf(COL_IMPORT_ID) val columns = arrayOf(COL_IMPORT_ID)

View File

@ -38,7 +38,7 @@ class IcsExporter {
} }
out.writeLn("$STATUS$CONFIRMED") 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) fillReminders(event, out)
fillIgnoredOccurrences(event, out) fillIgnoredOccurrences(event, out)

View File

@ -105,7 +105,7 @@ class Parser {
val interval = getInterval(repeatInterval) val interval = getInterval(repeatInterval)
val repeatLimit = getRepeatLimitString(event) val repeatLimit = getRepeatLimitString(event)
val byDay = getByDay(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 { private fun getFreq(interval: Int): String {