add event to CalDAV if sync is on

This commit is contained in:
tibbi 2017-08-18 15:18:10 +02:00
parent d8ed0c49d4
commit ab21bcd1a8
4 changed files with 8 additions and 5 deletions

View File

@ -508,7 +508,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
offset = getCurrentOffset()
isDstIncluded = TimeZone.getDefault().inDaylightTime(Date())
lastUpdated = System.currentTimeMillis()
source = SOURCE_SIMPLE_CALENDAR
source = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0) SOURCE_SIMPLE_CALENDAR else "$CALDAV-${config.lastUsedCaldavCalendar}"
}
storeEvent(wasRepeatable)

View File

@ -122,7 +122,8 @@ class CalDAVEventsHandler(val context: Context) {
}
}
fun addCalDAVEvent(event: Event, calendarId: Int) {
fun addCalDAVEvent(event: Event) {
val calendarId = event.getCalDAVCalendarId()
val uri = CalendarContract.Events.CONTENT_URI
val values = ContentValues().apply {
put(CalendarContract.Events.CALENDAR_ID, calendarId)
@ -167,7 +168,7 @@ class CalDAVEventsHandler(val context: Context) {
fun deleteCalDAVEvent(event: Event) {
val uri = CalendarContract.Events.CONTENT_URI
val contentUri = ContentUris.withAppendedId(uri, event.getCalDAVId())
val contentUri = ContentUris.withAppendedId(uri, event.getCalDAVEventId())
context.contentResolver.delete(contentUri, null, null)
}

View File

@ -194,7 +194,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
context.scheduleReminder(event, this)
if (addToCalDAV) {
CalDAVEventsHandler(context).addCalDAVEvent(event)
}
callback(event.id)

View File

@ -105,5 +105,7 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
}
}
fun getCalDAVId() = (importId.split("-").lastOrNull() ?: "0").toString().toLong()
fun getCalDAVEventId() = (importId.split("-").lastOrNull() ?: "0").toString().toLong()
fun getCalDAVCalendarId() = (source.split("-").lastOrNull() ?: "0").toString().toInt()
}