fix(#517): review round 1 - close picker on external navigation, proper load/failure states, wait for stored hidden views
This commit is contained in:
1 parent
d943937b3a
commit
bbcb8e00ed
7 files changed
+18
-15
No files matched your search
@@ -355,6 +355,7 @@ fun CalendarHost(
|
||||
fun dismissCoveringOverlays(keepCreate: Boolean = false) {
|
||||
showSettings = false
|
||||
showSearch = false
|
||||
showViewCalendars = false
|
||||
showCalendars = false
|
||||
showBackup = false
|
||||
detailKey = null
|
||||
@@ -615,7 +616,9 @@ fun CalendarHost(
|
||||
onOpenDrawer = { switchScope.launch { drawerState.open() } },
|
||||
onOpenSearch = onOpenSearch,
|
||||
showTodayButton = todayInToolbar,
|
||||
hiddenInView = (filterState as? FilterUiState.Success)?.hiddenOnlyIn(view) ?: 0,
|
||||
hiddenInView = remember(filterState, view) {
|
||||
(filterState as? FilterUiState.Success)?.hiddenOnlyIn(view) ?: 0
|
||||
},
|
||||
onOpenViewCalendars = { showViewCalendars = true },
|
||||
)
|
||||
},
|
||||
|
||||
@@ -137,7 +137,8 @@ fun CalendarsScreen(
|
||||
val calendars by viewModel.calendars.collectAsStateWithLifecycle()
|
||||
val deleteLockedIds by viewModel.deleteLockedCalendarIds.collectAsStateWithLifecycle()
|
||||
val error by viewModel.error.collectAsStateWithLifecycle()
|
||||
val hiddenViews by viewModel.hiddenViews.collectAsStateWithLifecycle()
|
||||
val loadedHiddenViews by viewModel.hiddenViews.collectAsStateWithLifecycle()
|
||||
val hiddenViews = loadedHiddenViews.orEmpty()
|
||||
|
||||
// null = list; NEW_CALENDAR_ID = create; any other id = edit that calendar.
|
||||
// [editorSession] bumps on every open so the editor's field state resets for
|
||||
@@ -147,7 +148,8 @@ fun CalendarsScreen(
|
||||
// A synced calendar has no editor; tapping it opens its hidden-views picker.
|
||||
var hidingId by rememberSaveable { mutableStateOf<Long?>(null) }
|
||||
|
||||
if (editorId != null) {
|
||||
// The editor and the picker seed from the stored hidden views, so both wait for the first read.
|
||||
if (editorId != null && loadedHiddenViews != null) {
|
||||
val editing = calendars.firstOrNull { it.id == editorId }
|
||||
CalendarEditor(
|
||||
sessionKey = editorSession,
|
||||
@@ -194,7 +196,7 @@ fun CalendarsScreen(
|
||||
// Gone while the picker was up; an empty list is one still loading, not a deletion.
|
||||
if (calendar == null && calendars.isNotEmpty()) {
|
||||
LaunchedEffect(id) { hidingId = null }
|
||||
} else if (calendar != null) {
|
||||
} else if (calendar != null && loadedHiddenViews != null) {
|
||||
HiddenViewsPicker(
|
||||
calendarName = calendar.displayName.orUnnamed(),
|
||||
hidden = hiddenViews[id].orEmpty(),
|
||||
|
||||
@@ -106,13 +106,13 @@ class CalendarsViewModel @Inject constructor(
|
||||
initialValue = emptySet(),
|
||||
)
|
||||
|
||||
/** The views each calendar is hidden in (#270). */
|
||||
val hiddenViews: StateFlow<Map<Long, Set<CalendarView>>> =
|
||||
/** The views each calendar is hidden in (#270); null until first read. */
|
||||
val hiddenViews: StateFlow<Map<Long, Set<CalendarView>>?> =
|
||||
settingsPrefs.perCalendarHiddenViews
|
||||
.catch { emit(emptyMap()) }
|
||||
.stateWhileSubscribed(
|
||||
scope = viewModelScope,
|
||||
initialValue = emptyMap(),
|
||||
initialValue = null,
|
||||
)
|
||||
|
||||
fun setHiddenIn(id: Long, view: CalendarView, hidden: Boolean) = write {
|
||||
|
||||
@@ -105,7 +105,7 @@ private fun FilterList(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FilterLoading(modifier: Modifier = Modifier) {
|
||||
internal fun FilterLoading(modifier: Modifier = Modifier) {
|
||||
Column(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
@@ -126,7 +126,7 @@ private fun FilterLoading(modifier: Modifier = Modifier) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FilterMessage(reason: FailureReason, modifier: Modifier = Modifier) {
|
||||
internal fun FilterMessage(reason: FailureReason, modifier: Modifier = Modifier) {
|
||||
val msg = when (reason) {
|
||||
FailureReason.NoCalendarsConfigured -> R.string.state_failure_no_calendars
|
||||
FailureReason.AllCalendarsHidden -> R.string.state_failure_all_hidden
|
||||
|
||||
@@ -27,7 +27,7 @@ sealed interface FilterUiState {
|
||||
* hidden everywhere from the drawer, or not listed, don't count.
|
||||
*/
|
||||
fun hiddenOnlyIn(view: CalendarView): Int {
|
||||
val listed = groups.flatMap { group -> group.calendars.map { it.id } }
|
||||
val listed = groups.flatMapTo(mutableSetOf()) { group -> group.calendars.map { it.id } }
|
||||
return hiddenViews.calendarsHiddenIn(view).count { it in listed && it !in hidden }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import de.jeanlucmakiola.calendula.ui.common.CalendarColorChip
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarView
|
||||
import de.jeanlucmakiola.calendula.ui.common.accountGroupTitle
|
||||
import de.jeanlucmakiola.calendula.ui.common.calendarsHiddenIn
|
||||
import de.jeanlucmakiola.calendula.ui.common.label
|
||||
import de.jeanlucmakiola.calendula.ui.common.orUnnamed
|
||||
import de.jeanlucmakiola.floret.components.FullScreenPicker
|
||||
import de.jeanlucmakiola.floret.components.GroupedHint
|
||||
@@ -32,13 +31,13 @@ fun ViewCalendarsPicker(
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
FullScreenPicker(
|
||||
title = stringResource(R.string.view_calendars_title, view.label()),
|
||||
title = stringResource(R.string.view_calendars_action),
|
||||
onDismiss = onDismiss,
|
||||
predictiveBack = true,
|
||||
) {
|
||||
when (state) {
|
||||
FilterUiState.Loading -> Unit
|
||||
is FilterUiState.Failure -> GroupedHint(stringResource(R.string.state_failure_provider), verticalPadding = 8.dp)
|
||||
FilterUiState.Loading -> FilterLoading()
|
||||
is FilterUiState.Failure -> FilterMessage(state.reason)
|
||||
is FilterUiState.Success -> {
|
||||
// Seeded once, then ahead of the store: the picker is the only
|
||||
// writer while open, so a quick second tap still flips.
|
||||
|
||||
@@ -873,7 +873,6 @@
|
||||
<item quantity="one">Calendars in this view, %d hidden</item>
|
||||
<item quantity="other">Calendars in this view, %d hidden</item>
|
||||
</plurals>
|
||||
<string name="view_calendars_title">Hide in %1$s</string>
|
||||
<string name="view_calendars_hint">Checked calendars stay out of this view only. Reminders, search and widgets still include them.</string>
|
||||
<string name="view_calendars_hidden_everywhere">Hidden in every view from the menu</string>
|
||||
<string name="color_name_mauve">Mauve</string>
|
||||
|
||||
Reference in new issue
Block a user