From ab21bcd1a8c730a62f1293ddfb5480ee63fd22a0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 18 Aug 2017 15:18:10 +0200 Subject: [PATCH] add event to CalDAV if sync is on --- .../simplemobiletools/calendar/activities/EventActivity.kt | 2 +- .../calendar/helpers/CalDAVEventsHandler.kt | 5 +++-- .../com/simplemobiletools/calendar/helpers/DBHelper.kt | 2 +- .../kotlin/com/simplemobiletools/calendar/models/Event.kt | 4 +++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index df78741b0..25dc854a7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt index b83222e60..1ab4ccb74 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt @@ -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) } 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 fd96367e0..cb0a26a0b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt index cbec0fe19..84f94f98c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt @@ -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() }