fix(#517): review round 2 - close picker for every external request, clearer title, provider write first
This commit is contained in:
1 parent
bbcb8e00ed
commit
dda0164c9f
7 files changed
+24
-16
No files matched your search
@@ -272,9 +272,9 @@ class SettingsPrefs @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/** Hide [calendarId] in [views] only (#270); an empty set shows it everywhere again. */
|
||||
suspend fun setCalendarHiddenViews(calendarId: Long, views: Set<CalendarView>) {
|
||||
prefs.update(SettingsKeys.perCalendarHiddenViews) { current -> current.withHiddenViews(calendarId, views) }
|
||||
/** Show [calendarId] in every view again (#270), e.g. once it is deleted. */
|
||||
suspend fun clearCalendarHiddenViews(calendarId: Long) {
|
||||
prefs.update(SettingsKeys.perCalendarHiddenViews) { current -> current - calendarId }
|
||||
}
|
||||
|
||||
/** Hide or show [calendarId] in one [view], against the stored set rather than a snapshot of it. */
|
||||
|
||||
@@ -348,6 +348,12 @@ fun CalendarHost(
|
||||
}
|
||||
}
|
||||
|
||||
// The view-calendars picker is its own window over everything here, so a
|
||||
// reminder tap, an insert request or an .ics file opening under it closes it.
|
||||
LaunchedEffect(detailKey != null || importUri != null || importForm != null) {
|
||||
if (detailKey != null || importUri != null || importForm != null) showViewCalendars = false
|
||||
}
|
||||
|
||||
// Close every overlay that can sit over the calendar, so an externally
|
||||
// requested destination (a widget/shortcut/QS-tile launch) is revealed on
|
||||
// top instead of underneath whatever the user had open. The create form,
|
||||
|
||||
@@ -161,8 +161,7 @@ class CalendarsViewModel @Inject constructor(
|
||||
hiddenChanges: Map<CalendarView, Boolean>,
|
||||
) = write {
|
||||
val id = repository.createLocalCalendar(displayName, color, description)
|
||||
// The calendar exists now; a failed pref write must not read as a failed create.
|
||||
bestEffort { settingsPrefs.applyCalendarHiddenChanges(id, hiddenChanges) }
|
||||
settingsPrefs.applyCalendarHiddenChanges(id, hiddenChanges)
|
||||
}
|
||||
|
||||
fun updateCalendar(
|
||||
@@ -172,15 +171,14 @@ class CalendarsViewModel @Inject constructor(
|
||||
description: String?,
|
||||
hiddenChanges: Map<CalendarView, Boolean>,
|
||||
) = write {
|
||||
// First: it doesn't depend on the provider, so a failed provider write shouldn't lose it.
|
||||
settingsPrefs.applyCalendarHiddenChanges(id, hiddenChanges)
|
||||
repository.updateCalendar(id, displayName, color, description)
|
||||
settingsPrefs.applyCalendarHiddenChanges(id, hiddenChanges)
|
||||
}
|
||||
|
||||
fun deleteCalendar(id: Long) = write {
|
||||
repository.deleteCalendar(id)
|
||||
// Tidy-up only: the delete already landed, so a failure here isn't its failure.
|
||||
bestEffort { settingsPrefs.setCalendarHiddenViews(id, emptySet()) }
|
||||
bestEffort { settingsPrefs.clearCalendarHiddenViews(id) }
|
||||
}
|
||||
|
||||
private suspend fun bestEffort(block: suspend () -> Unit) {
|
||||
|
||||
@@ -31,7 +31,7 @@ fun ViewCalendarsPicker(
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
FullScreenPicker(
|
||||
title = stringResource(R.string.view_calendars_action),
|
||||
title = stringResource(R.string.view_calendars_title),
|
||||
onDismiss = onDismiss,
|
||||
predictiveBack = true,
|
||||
) {
|
||||
|
||||
@@ -868,10 +868,11 @@
|
||||
<string name="calendars_hide_in_views_none">Shown in every view</string>
|
||||
<string name="calendars_hidden_in">Hidden in %1$s</string>
|
||||
<string name="filter_hidden_in_view">Hidden in this view</string>
|
||||
<string name="view_calendars_action">Calendars in this view</string>
|
||||
<string name="view_calendars_action">Hide calendars in this view</string>
|
||||
<string name="view_calendars_title">Hide in this view</string>
|
||||
<plurals name="view_calendars_action_hidden">
|
||||
<item quantity="one">Calendars in this view, %d hidden</item>
|
||||
<item quantity="other">Calendars in this view, %d hidden</item>
|
||||
<item quantity="one">Hide calendars in this view, %d hidden</item>
|
||||
<item quantity="other">Hide calendars in this view, %d hidden</item>
|
||||
</plurals>
|
||||
<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>
|
||||
|
||||
@@ -622,14 +622,17 @@ class SettingsPrefsTest {
|
||||
) = runTest {
|
||||
val prefs = testSettings(tempDir)
|
||||
assertThat(prefs.perCalendarHiddenViews.first()).isEmpty()
|
||||
prefs.setCalendarHiddenViews(7L, setOf(CalendarView.Month, CalendarView.Agenda))
|
||||
prefs.setCalendarHiddenViews(9L, setOf(CalendarView.MultiDay))
|
||||
prefs.applyCalendarHiddenChanges(7L, listOf(CalendarView.Month, CalendarView.Agenda).associateWith { true })
|
||||
prefs.applyCalendarHiddenChanges(9L, listOf(CalendarView.MultiDay).associateWith { true })
|
||||
assertThat(prefs.perCalendarHiddenViews.first()).containsExactly(
|
||||
7L, setOf(CalendarView.Month, CalendarView.Agenda),
|
||||
9L, setOf(CalendarView.MultiDay),
|
||||
)
|
||||
prefs.setCalendarHiddenViews(7L, emptySet())
|
||||
prefs.clearCalendarHiddenViews(7L)
|
||||
assertThat(prefs.perCalendarHiddenViews.first()).containsExactly(9L, setOf(CalendarView.MultiDay))
|
||||
// One write can hide some views and show others, leaving the rest alone.
|
||||
prefs.applyCalendarHiddenChanges(9L, mapOf(CalendarView.MultiDay to false, CalendarView.Day to true))
|
||||
assertThat(prefs.perCalendarHiddenViews.first()).containsExactly(9L, setOf(CalendarView.Day))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -52,7 +52,7 @@ class ViewHiddenCalendarsTest {
|
||||
}
|
||||
val settings = testSettings(tempDir)
|
||||
val repo = testRepository(fake, tempDir, UnconfinedTestDispatcher(testScheduler), settings = settings)
|
||||
settings.setCalendarHiddenViews(2L, setOf(CalendarView.Month))
|
||||
settings.applyCalendarHiddenChanges(2L, listOf(CalendarView.Month).associateWith { true })
|
||||
val hidden = settings.perCalendarHiddenViews
|
||||
|
||||
assertThat(repo.instancesWithout(range, hidden.calendarsHiddenIn(CalendarView.Month, backgroundScope)).first().map { it.eventId })
|
||||
|
||||
Reference in new issue
Block a user