select the proper color key at updating calendar color, if available
This commit is contained in:
parent
6031a4596b
commit
dec585de0b
1 changed files with 20 additions and 0 deletions
|
@ -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<String, Event>()
|
||||
val fetchedEventIds = ArrayList<String>()
|
||||
|
|
Loading…
Reference in a new issue