select the proper color key at updating calendar color, if available

This commit is contained in:
tibbi 2017-08-22 22:08:52 +02:00
parent 6031a4596b
commit dec585de0b
1 changed files with 20 additions and 0 deletions

View File

@ -74,10 +74,30 @@ class CalDAVHandler(val context: Context) {
private fun fillCalendarContentValues(eventType: EventType): ContentValues { private fun fillCalendarContentValues(eventType: EventType): ContentValues {
return ContentValues().apply { return ContentValues().apply {
put(CalendarContract.Calendars.CALENDAR_COLOR_KEY, getEventTypeColorKey(eventType))
put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, eventType.title) 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) { private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
val importIdsMap = HashMap<String, Event>() val importIdsMap = HashMap<String, Event>()
val fetchedEventIds = ArrayList<String>() val fetchedEventIds = ArrayList<String>()