diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditViewModel.kt index 5f6e6ae5..0265933f 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditViewModel.kt @@ -308,7 +308,7 @@ class EventEditViewModel @Inject constructor( val resolvedId = resolveEventCalendar(form.calendarId, external.hints, allCalendars) // A colour is scoped to the calendar it came from, so one that came with // a requested calendar the form couldn't take goes, as on [setCalendar]. - val requestRefused = form.calendarId == null && + val requestRefused = form.calendarId == null && resolvedId != null && external.hints.requested.let { it != null && it != resolvedId } val resolved = form.copy(calendarId = resolvedId).let { if (requestRefused) it.copy(colorKey = null, color = null) else it diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt index 0e58158f..da1309b5 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt @@ -37,6 +37,7 @@ import de.jeanlucmakiola.calendula.data.reminders.ReminderScanner import de.jeanlucmakiola.calendula.domain.CalendarSource import de.jeanlucmakiola.calendula.domain.EventFormField import de.jeanlucmakiola.calendula.domain.DefaultCalendarRef +import de.jeanlucmakiola.calendula.domain.effectiveDefaultCalendar import de.jeanlucmakiola.calendula.domain.FontRole import de.jeanlucmakiola.calendula.domain.isEventTarget import de.jeanlucmakiola.calendula.domain.contacts.SpecialDateType @@ -91,54 +92,52 @@ class SettingsViewModel @Inject constructor( ) private fun Preferences.toUiState(calendars: List): SettingsUiState { - val defaultCalendar = this[SettingsKeys.defaultNewEventCalendar]?.find(calendars) - return toUiState(calendars, defaultCalendar) + val storedDefault = this[SettingsKeys.defaultNewEventCalendar] + return SettingsUiState( + themeMode = this[SettingsKeys.themeMode], + dynamicColor = this[SettingsKeys.dynamicColor] && dynamicColorAvailable, + dynamicColorAvailable = dynamicColorAvailable, + softenColors = this[SettingsKeys.softenCalendarColors], + weekStart = this[SettingsKeys.weekStart], + timeFormat = this[SettingsKeys.timeFormat], + showHourGrid = this[SettingsKeys.showHourGrid], + multiDayCount = this[SettingsKeys.multiDayCount], + pastEventDisplay = this[SettingsKeys.pastEventDisplay], + dimCompletedEvents = this[SettingsKeys.dimCompletedEvents], + showWeekNumbers = this[SettingsKeys.showWeekNumbers], + monthShowStartTimes = this[SettingsKeys.monthShowStartTimes], + todayButtonInToolbar = this[SettingsKeys.todayButtonInToolbar], + dragToReschedule = this[SettingsKeys.dragToReschedule], + tapOpensEditor = this[SettingsKeys.tapOpensEditor], + agendaScreenRange = this[SettingsKeys.agendaScreenRange], + agendaShowToday = this[SettingsKeys.agendaShowToday], + agendaShowRangeBar = this[SettingsKeys.agendaShowRangeBar], + defaultView = this[SettingsKeys.defaultView], + quickSwitchConfig = this[SettingsKeys.quickSwitchConfig], + monthViewStyle = this[SettingsKeys.monthViewStyle], + timelineScale = this[SettingsKeys.timelineScale], + timelineHours = timelineHours, + drawerViewOrder = this[SettingsKeys.drawerViewOrder], + defaultFormFields = this[SettingsKeys.defaultFormFields], + autofocusEventTitle = this[SettingsKeys.autofocusEventTitle], + defaultEventDurationMinutes = this[SettingsKeys.defaultEventDurationMinutes], + perCalendarEventDuration = this[SettingsKeys.perCalendarEventDuration], + remindersEnabled = this[SettingsKeys.remindersEnabled], + defaultReminderMinutes = this[SettingsKeys.defaultReminderMinutes], + defaultAllDayReminderMinutes = this[SettingsKeys.defaultAllDayReminderMinutes], + allDayReminderTimeMinutes = this[SettingsKeys.allDayReminderTimeMinutes], + snoozeMinutes = this[SettingsKeys.snoozeMinutes], + perCalendarReminderOverride = this[SettingsKeys.perCalendarReminderOverride], + perCalendarAllDayReminderOverride = this[SettingsKeys.perCalendarAllDayReminderOverride], + writableCalendars = calendars.filter { it.canModifyContents && it.isVisibleInSystem }, + eventTargetCalendars = calendars.filter { it.isEventTarget }, + defaultNewEventCalendar = effectiveDefaultCalendar(storedDefault, calendars), + unavailableDefaultCalendar = storedDefault?.find(calendars)?.takeUnless { it.isEventTarget }, + allowColorOnUnsupportedCalendars = this[SettingsKeys.allowColorOnUnsupportedCalendars], + managedCalendarIds = specialDatesCalendars.values.toSet(), + ) } - private fun Preferences.toUiState(calendars: List, defaultCalendar: CalendarSource?) = SettingsUiState( - themeMode = this[SettingsKeys.themeMode], - dynamicColor = this[SettingsKeys.dynamicColor] && dynamicColorAvailable, - dynamicColorAvailable = dynamicColorAvailable, - softenColors = this[SettingsKeys.softenCalendarColors], - weekStart = this[SettingsKeys.weekStart], - timeFormat = this[SettingsKeys.timeFormat], - showHourGrid = this[SettingsKeys.showHourGrid], - multiDayCount = this[SettingsKeys.multiDayCount], - pastEventDisplay = this[SettingsKeys.pastEventDisplay], - dimCompletedEvents = this[SettingsKeys.dimCompletedEvents], - showWeekNumbers = this[SettingsKeys.showWeekNumbers], - monthShowStartTimes = this[SettingsKeys.monthShowStartTimes], - todayButtonInToolbar = this[SettingsKeys.todayButtonInToolbar], - dragToReschedule = this[SettingsKeys.dragToReschedule], - tapOpensEditor = this[SettingsKeys.tapOpensEditor], - agendaScreenRange = this[SettingsKeys.agendaScreenRange], - agendaShowToday = this[SettingsKeys.agendaShowToday], - agendaShowRangeBar = this[SettingsKeys.agendaShowRangeBar], - defaultView = this[SettingsKeys.defaultView], - quickSwitchConfig = this[SettingsKeys.quickSwitchConfig], - monthViewStyle = this[SettingsKeys.monthViewStyle], - timelineScale = this[SettingsKeys.timelineScale], - timelineHours = timelineHours, - drawerViewOrder = this[SettingsKeys.drawerViewOrder], - defaultFormFields = this[SettingsKeys.defaultFormFields], - autofocusEventTitle = this[SettingsKeys.autofocusEventTitle], - defaultEventDurationMinutes = this[SettingsKeys.defaultEventDurationMinutes], - perCalendarEventDuration = this[SettingsKeys.perCalendarEventDuration], - remindersEnabled = this[SettingsKeys.remindersEnabled], - defaultReminderMinutes = this[SettingsKeys.defaultReminderMinutes], - defaultAllDayReminderMinutes = this[SettingsKeys.defaultAllDayReminderMinutes], - allDayReminderTimeMinutes = this[SettingsKeys.allDayReminderTimeMinutes], - snoozeMinutes = this[SettingsKeys.snoozeMinutes], - perCalendarReminderOverride = this[SettingsKeys.perCalendarReminderOverride], - perCalendarAllDayReminderOverride = this[SettingsKeys.perCalendarAllDayReminderOverride], - writableCalendars = calendars.filter { it.canModifyContents && it.isVisibleInSystem }, - eventTargetCalendars = calendars.filter { it.isEventTarget }, - defaultNewEventCalendar = defaultCalendar?.takeIf { it.isEventTarget }, - unavailableDefaultCalendar = defaultCalendar?.takeUnless { it.isEventTarget }, - allowColorOnUnsupportedCalendars = this[SettingsKeys.allowColorOnUnsupportedCalendars], - managedCalendarIds = specialDatesCalendars.values.toSet(), - ) - /** * The app-wide custom-font choice (issue #19). Its own flow — both this * screen and [MainActivity] (which builds the typography) read it