use a helper function for fetching proper calendar color_key, if it exists
This commit is contained in:
parent
0d5b40583d
commit
805823c58d
|
@ -73,11 +73,32 @@ class CalDAVHandler(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fillCalendarContentValues(eventType: EventType): ContentValues {
|
private fun fillCalendarContentValues(eventType: EventType): ContentValues {
|
||||||
|
val colorKey = getEventTypeColorKey(eventType)
|
||||||
return ContentValues().apply {
|
return ContentValues().apply {
|
||||||
|
put(CalendarContract.Calendars.CALENDAR_COLOR_KEY, colorKey)
|
||||||
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} = ?"
|
||||||
|
val selectionArgs = arrayOf(CalendarContract.Colors.TYPE_CALENDAR.toString(), eventType.color.toString())
|
||||||
|
|
||||||
|
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>()
|
||||||
|
|
Loading…
Reference in New Issue