From 0d5b40583d46b0bbafe854d99335d24e81e82bce Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 22 Aug 2017 15:31:43 +0200 Subject: [PATCH] implement updating remote caldav calendar name --- .../calendar/helpers/CalDAVHandler.kt | 14 ++++++++++++++ .../simplemobiletools/calendar/helpers/DBHelper.kt | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt index 17d40d8d0..5cfb75da5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.calendar.extensions.hasCalendarPermission import com.simplemobiletools.calendar.extensions.scheduleCalDAVSync import com.simplemobiletools.calendar.models.CalDAVCalendar import com.simplemobiletools.calendar.models.Event +import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.getLongValue import com.simplemobiletools.commons.extensions.getStringValue @@ -64,6 +65,19 @@ class CalDAVHandler(val context: Context) { return calendars } + fun updateCalDAVCalendar(eventType: EventType): Boolean { + val uri = CalendarContract.Calendars.CONTENT_URI + val values = fillCalendarContentValues(eventType) + val newUri = ContentUris.withAppendedId(uri, eventType.caldavCalendarId.toLong()) + return context.contentResolver.update(newUri, values, null, null) == 1 + } + + private fun fillCalendarContentValues(eventType: EventType): ContentValues { + return ContentValues().apply { + put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, eventType.title) + } + } + private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) { val importIdsMap = HashMap() val fetchedEventIds = ArrayList() 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 9fa1e2768..7d11fee81 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -271,6 +271,18 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } fun updateEventType(eventType: EventType): Int { + return if (eventType.caldavCalendarId != 0) { + if (CalDAVHandler(context).updateCalDAVCalendar(eventType)) { + updateLocalEventType(eventType) + } else { + -1 + } + } else { + updateLocalEventType(eventType) + } + } + + private fun updateLocalEventType(eventType: EventType): Int { val selectionArgs = arrayOf(eventType.id.toString()) val values = fillEventTypeValues(eventType) val selection = "$COL_TYPE_ID = ?"