Skip to content

Commit aff984b

Browse files
committed
Disable CalDAV event color modification
See: - #188 - #421 (comment)
1 parent eacae27 commit aff984b

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

app/src/main/kotlin/org/fossify/calendar/helpers/CalDAVHelper.kt

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import android.annotation.SuppressLint
44
import android.content.ContentUris
55
import android.content.ContentValues
66
import android.content.Context
7-
import android.graphics.Color
8-
import android.provider.CalendarContract
97
import android.provider.CalendarContract.*
108
import android.widget.Toast
119
import org.fossify.calendar.R
@@ -18,7 +16,6 @@ import org.fossify.commons.helpers.PERMISSION_WRITE_CALENDAR
1816
import org.joda.time.DateTimeZone
1917
import org.joda.time.format.DateTimeFormat
2018
import kotlin.math.max
21-
import kotlin.math.min
2219

2320
@SuppressLint("MissingPermission")
2421
class CalDAVHelper(val context: Context) {
@@ -118,15 +115,6 @@ class CalDAVHelper(val context: Context) {
118115
return colors[eventType.color]
119116
}
120117

121-
// darkens the given color to ensure that white text is clearly visible on top of it
122-
private fun getDisplayColorFromColor(color: Int): Int {
123-
val hsv = FloatArray(3)
124-
Color.colorToHSV(color, hsv)
125-
hsv[1] = min(hsv[1] * SATURATION_ADJUST, 1.0f)
126-
hsv[2] = hsv[2] * INTENSITY_ADJUST
127-
return Color.HSVToColor(hsv)
128-
}
129-
130118
@SuppressLint("MissingPermission")
131119
fun getAvailableCalDAVCalendarColors(eventType: EventType, colorType: Int = Colors.TYPE_CALENDAR): Map<Int, String> {
132120
val colors = mutableMapOf<Int, String>()
@@ -138,12 +126,7 @@ class CalDAVHelper(val context: Context) {
138126
context.queryCursor(uri, projection, selection, selectionArgs) { cursor ->
139127
val colorKey = cursor.getStringValue(Colors.COLOR_KEY)
140128
val color = cursor.getIntValue(Colors.COLOR)
141-
val displayColor = if (colorType == Colors.TYPE_CALENDAR) {
142-
color
143-
} else {
144-
getDisplayColorFromColor(color)
145-
}
146-
colors[displayColor] = colorKey
129+
colors[color] = colorKey
147130
}
148131
return colors.toSortedMap(HsvColorComparator())
149132
}
@@ -216,12 +199,7 @@ class CalDAVHelper(val context: Context) {
216199
val attendees = getCalDAVEventAttendees(id, calendar)
217200
val availability = cursor.getIntValue(Events.AVAILABILITY)
218201
val status = cursor.getIntValue(Events.STATUS)
219-
val color = cursor.getIntValueOrNull(Events.EVENT_COLOR)
220-
val displayColor = if (color != null) {
221-
getDisplayColorFromColor(color)
222-
} else {
223-
0
224-
}
202+
val color = cursor.getIntValueOrNull(Events.EVENT_COLOR) ?: 0
225203

226204
if (endTS == 0L) {
227205
val duration = cursor.getStringValue(Events.DURATION) ?: ""
@@ -243,7 +221,7 @@ class CalDAVHelper(val context: Context) {
243221
reminder1?.type ?: REMINDER_NOTIFICATION, reminder2?.type ?: REMINDER_NOTIFICATION,
244222
reminder3?.type ?: REMINDER_NOTIFICATION, repeatRule.repeatInterval, repeatRule.repeatRule,
245223
repeatRule.repeatLimit, ArrayList(), attendees, importId, eventTimeZone, allDay, eventTypeId,
246-
source = source, availability = availability, color = displayColor, status = status
224+
source = source, availability = availability, color = color, status = status
247225
)
248226

249227
if (event.getIsAllDay()) {
@@ -597,9 +575,4 @@ class CalDAVHelper(val context: Context) {
597575
private fun getCalDAVEventImportId(calendarId: Int, eventId: Long) = "$CALDAV-$calendarId-$eventId"
598576

599577
private fun refreshCalDAVCalendar(event: Event) = context.refreshCalDAVCalendars(event.getCalDAVCalendarId().toString(), false)
600-
601-
companion object {
602-
private const val INTENSITY_ADJUST = 0.8f
603-
private const val SATURATION_ADJUST = 1.3f
604-
}
605578
}

0 commit comments

Comments
 (0)