From dec585de0b5457258ed7abc1f9728340c4528286 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 22 Aug 2017 22:08:52 +0200 Subject: [PATCH] select the proper color key at updating calendar color, if available --- .../calendar/helpers/CalDAVHandler.kt | 20 +++++++++++++++++++ 1 file changed, 20 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 2125b20a5..2eb4150b0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVHandler.kt @@ -74,10 +74,30 @@ class CalDAVHandler(val context: Context) { private fun fillCalendarContentValues(eventType: EventType): ContentValues { return ContentValues().apply { + put(CalendarContract.Calendars.CALENDAR_COLOR_KEY, getEventTypeColorKey(eventType)) put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, eventType.title) } } + private fun getEventTypeColorKey(eventType: EventType): Int { + val uri = CalendarContract.Colors.CONTENT_URI + val projection = arrayOf(CalendarContract.Colors.COLOR_KEY) + val selection = "${CalendarContract.Colors.COLOR_TYPE} = ? AND ${CalendarContract.Colors.COLOR} = ? AND ${CalendarContract.Colors.ACCOUNT_NAME} = ?" + val selectionArgs = arrayOf(CalendarContract.Colors.TYPE_CALENDAR.toString(), eventType.color.toString(), eventType.caldavEmail) + + var cursor: Cursor? = null + try { + cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) + if (cursor?.moveToFirst() == true) { + return cursor.getStringValue(CalendarContract.Colors.COLOR_KEY).toInt() + } + } finally { + cursor?.close() + } + + return 1 + } + private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) { val importIdsMap = HashMap() val fetchedEventIds = ArrayList()