mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-18 04:40:36 +01:00
properly update event type color
- before updating the color, check if the color has a key - if it does, we update the CALENDAR_COLOR_KEY column (which will also update the CALENDAR_COLOR column internally) - if it does not have a key (ie, if it is not a defined color), we update the CALENDAR_COLOR column and set the CALENDAR_COLOR_KEY to empty string - one note here is that transparent color (0) is not usually a defined color and setting CALENDAR_COLOR to 0 can cause some Calendar apps (like Google Calendar) to convert this to black color (#FF00000).
This commit is contained in:
parent
52c22e2a98
commit
528e0878bf
@ -85,22 +85,37 @@ class CalDAVHelper(val context: Context) {
|
|||||||
return calendars
|
return calendars
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the calendars color or title has changed
|
|
||||||
fun updateCalDAVCalendar(eventType: EventType) {
|
fun updateCalDAVCalendar(eventType: EventType) {
|
||||||
val uri = Calendars.CONTENT_URI
|
val uri = ContentUris.withAppendedId(Calendars.CONTENT_URI, eventType.caldavCalendarId.toLong())
|
||||||
val newUri = ContentUris.withAppendedId(uri, eventType.caldavCalendarId.toLong())
|
|
||||||
val values = ContentValues().apply {
|
val values = ContentValues().apply {
|
||||||
put(Calendars.CALENDAR_COLOR, eventType.color)
|
val colorKey = getCalDAVColorKey(eventType)
|
||||||
|
if (colorKey != null) {
|
||||||
|
put(Calendars.CALENDAR_COLOR_KEY, getCalDAVColorKey(eventType))
|
||||||
|
} else {
|
||||||
|
put(Calendars.CALENDAR_COLOR, eventType.color)
|
||||||
|
put(Calendars.CALENDAR_COLOR_KEY, "")
|
||||||
|
}
|
||||||
put(Calendars.CALENDAR_DISPLAY_NAME, eventType.title)
|
put(Calendars.CALENDAR_DISPLAY_NAME, eventType.title)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.contentResolver.update(newUri, values, null, null)
|
context.contentResolver.update(uri, values, null, null)
|
||||||
context.eventTypesDB.insertOrUpdate(eventType)
|
context.eventTypesDB.insertOrUpdate(eventType)
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getCalDAVColorKey(eventType: EventType): String? {
|
||||||
|
val colors = getAvailableCalDAVCalendarColors(eventType)
|
||||||
|
val colorKey = colors.indexOf(eventType.color)
|
||||||
|
return if (colorKey > 0) {
|
||||||
|
colorKey.toString()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun getAvailableCalDAVCalendarColors(eventType: EventType): ArrayList<Int> {
|
fun getAvailableCalDAVCalendarColors(eventType: EventType): ArrayList<Int> {
|
||||||
val colors = SparseIntArray()
|
val colors = SparseIntArray()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user