Hide event colors setting when there are no colors available

This commit is contained in:
Naveen
2023-04-11 15:23:08 +05:30
parent 8506513871
commit 885f551c83

View File

@@ -835,8 +835,7 @@ class EventActivity : SimpleActivity() {
hideKeyboard() hideKeyboard()
ensureBackgroundThread { ensureBackgroundThread {
val eventType = eventsHelper.getEventTypeWithCalDAVCalendarId(calendarId = mEventCalendarId)!! val eventType = eventsHelper.getEventTypeWithCalDAVCalendarId(calendarId = mEventCalendarId)!!
val eventColorsMap = calDAVHelper.getAvailableCalDAVCalendarColors(eventType, Colors.TYPE_EVENT) val eventColors = getEventColors(eventType)
val eventColors = eventColorsMap.keys.toIntArray()
runOnUiThread { runOnUiThread {
val currentColor = if (mEventColor == 0) { val currentColor = if (mEventColor == 0) {
eventType.color eventType.color
@@ -964,9 +963,6 @@ class EventActivity : SimpleActivity() {
event_caldav_calendar_image.beVisible() event_caldav_calendar_image.beVisible()
event_caldav_calendar_holder.beVisible() event_caldav_calendar_holder.beVisible()
event_caldav_calendar_divider.beVisible() event_caldav_calendar_divider.beVisible()
event_caldav_color_image.beVisible()
event_caldav_color_holder.beVisible()
event_caldav_color_divider.beVisible()
val calendars = calDAVHelper.getCalDAVCalendars("", true).filter { val calendars = calDAVHelper.getCalDAVCalendars("", true).filter {
it.canWrite() && config.getSyncedCalendarIdsAsList().contains(it.id) it.canWrite() && config.getSyncedCalendarIdsAsList().contains(it.id)
@@ -1005,9 +1001,6 @@ class EventActivity : SimpleActivity() {
event_type_holder.beVisibleIf(currentCalendar == null) event_type_holder.beVisibleIf(currentCalendar == null)
event_caldav_calendar_divider.beVisibleIf(currentCalendar == null) event_caldav_calendar_divider.beVisibleIf(currentCalendar == null)
event_caldav_calendar_email.beGoneIf(currentCalendar == null) event_caldav_calendar_email.beGoneIf(currentCalendar == null)
event_caldav_color_image.beGoneIf(currentCalendar == null)
event_caldav_color_holder.beGoneIf(currentCalendar == null)
event_caldav_color_divider.beGoneIf(currentCalendar == null)
if (currentCalendar == null) { if (currentCalendar == null) {
mEventCalendarId = STORED_LOCALLY_ONLY mEventCalendarId = STORED_LOCALLY_ONLY
@@ -1020,11 +1013,20 @@ class EventActivity : SimpleActivity() {
event_caldav_calendar_holder.apply { event_caldav_calendar_holder.apply {
setPadding(paddingLeft, mediumMargin, paddingRight, mediumMargin) setPadding(paddingLeft, mediumMargin, paddingRight, mediumMargin)
} }
event_caldav_color_image.beGone()
event_caldav_color_holder.beGone()
event_caldav_color_divider.beGone()
} else { } else {
event_caldav_calendar_email.text = currentCalendar.accountName event_caldav_calendar_email.text = currentCalendar.accountName
ensureBackgroundThread { ensureBackgroundThread {
val calendarColor = eventsHelper.getEventTypeWithCalDAVCalendarId(currentCalendar.id)?.color ?: currentCalendar.color val eventType = eventsHelper.getEventTypeWithCalDAVCalendarId(currentCalendar.id)
val calendarColor = eventType?.color ?: currentCalendar.color
val canCustomizeColors = if (eventType != null) {
getEventColors(eventType).isNotEmpty()
} else {
false
}
runOnUiThread { runOnUiThread {
event_caldav_calendar_name.apply { event_caldav_calendar_name.apply {
@@ -1035,7 +1037,13 @@ class EventActivity : SimpleActivity() {
event_caldav_calendar_holder.apply { event_caldav_calendar_holder.apply {
setPadding(paddingLeft, 0, paddingRight, 0) setPadding(paddingLeft, 0, paddingRight, 0)
} }
updateEventColorInfo(calendarColor)
event_caldav_color_image.beVisibleIf(canCustomizeColors)
event_caldav_color_holder.beVisibleIf(canCustomizeColors)
event_caldav_color_divider.beVisibleIf(canCustomizeColors)
if (canCustomizeColors) {
updateEventColorInfo(calendarColor)
}
} }
} }
} }
@@ -1050,6 +1058,10 @@ class EventActivity : SimpleActivity() {
event_caldav_color.setFillWithStroke(eventColor, getProperBackgroundColor()) event_caldav_color.setFillWithStroke(eventColor, getProperBackgroundColor())
} }
private fun getEventColors(eventType: EventType): IntArray {
return calDAVHelper.getAvailableCalDAVCalendarColors(eventType, Colors.TYPE_EVENT).keys.toIntArray()
}
private fun resetTime() { private fun resetTime() {
if (mEventEndDateTime.isBefore(mEventStartDateTime) && if (mEventEndDateTime.isBefore(mEventStartDateTime) &&
mEventStartDateTime.dayOfMonth() == mEventEndDateTime.dayOfMonth() && mEventStartDateTime.dayOfMonth() == mEventEndDateTime.dayOfMonth() &&