fix(#143): review round 3 — rows toggle against the stored set too
This commit is contained in:
1 parent
4186640a63
commit
9511444c6b
4 files changed
+16
-20
No files matched your search
@@ -32,10 +32,6 @@ class CalendarPrefs @Inject constructor(
|
||||
|
||||
suspend fun setHiddenCalendarIds(ids: Set<Long>) = prefs.set(HIDDEN_IDS, ids)
|
||||
|
||||
/** Hide or show [ids] in the drawer filter in one atomic write. */
|
||||
suspend fun setCalendarsHidden(ids: Collection<Long>, hidden: Boolean) =
|
||||
updateHiddenCalendarIds { if (hidden) it + ids else it - ids.toSet() }
|
||||
|
||||
/** Rewrite the drawer's hidden set atomically from its current value. */
|
||||
suspend fun updateHiddenCalendarIds(transform: (Set<Long>) -> Set<Long>) {
|
||||
prefs.update(HIDDEN_IDS, transform)
|
||||
|
||||
@@ -56,7 +56,7 @@ fun CalendarFilterList(
|
||||
is FilterUiState.Success -> FilterList(
|
||||
groups = s.groups,
|
||||
hidden = s.hidden,
|
||||
onSetVisible = viewModel::setVisible,
|
||||
onToggleCalendar = viewModel::toggleCalendar,
|
||||
onToggleGroup = viewModel::toggleGroup,
|
||||
modifier = modifier,
|
||||
)
|
||||
@@ -72,7 +72,7 @@ fun CalendarFilterList(
|
||||
private fun FilterList(
|
||||
groups: List<CalendarAccountGroup>,
|
||||
hidden: Set<Long>,
|
||||
onSetVisible: (Long, Boolean) -> Unit,
|
||||
onToggleCalendar: (Long) -> Unit,
|
||||
onToggleGroup: (List<Long>) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
@@ -94,10 +94,10 @@ private fun FilterList(
|
||||
trailing = {
|
||||
Checkbox(
|
||||
checked = visible,
|
||||
onCheckedChange = { onSetVisible(cal.id, it) },
|
||||
onCheckedChange = { onToggleCalendar(cal.id) },
|
||||
)
|
||||
},
|
||||
onClick = { onSetVisible(cal.id, !visible) },
|
||||
onClick = { onToggleCalendar(cal.id) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,15 +47,17 @@ class FilterViewModel @Inject constructor(
|
||||
initialValue = FilterUiState.Loading,
|
||||
)
|
||||
|
||||
/** Show or hide a single calendar; persists the new hidden set. */
|
||||
fun setVisible(calendarId: Long, visible: Boolean) {
|
||||
viewModelScope.launch { prefs.setCalendarsHidden(listOf(calendarId), hidden = !visible) }
|
||||
/**
|
||||
* Flip one calendar, or a whole group from its header (#143). Both decide
|
||||
* against the stored set rather than the last drawn state, so quick repeated
|
||||
* taps still alternate.
|
||||
*/
|
||||
fun toggleCalendar(calendarId: Long) {
|
||||
viewModelScope.launch {
|
||||
prefs.updateHiddenCalendarIds { if (calendarId in it) it - calendarId else it + calendarId }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The group header's tap (#143), decided against the stored set rather than
|
||||
* the last drawn state so quick repeated taps still alternate.
|
||||
*/
|
||||
fun toggleGroup(calendarIds: List<Long>) {
|
||||
viewModelScope.launch { prefs.updateHiddenCalendarIds { toggledGroup(it, calendarIds) } }
|
||||
}
|
||||
|
||||
@@ -35,14 +35,12 @@ class CalendarPrefsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `setCalendarsHidden adds and removes only the given ids`(@TempDir tempDir: Path) = runTest {
|
||||
fun `updateHiddenCalendarIds transforms the stored set`(@TempDir tempDir: Path) = runTest {
|
||||
val prefs = testPrefs(tempDir)
|
||||
prefs.setHiddenCalendarIds(setOf(9L))
|
||||
prefs.setCalendarsHidden(listOf(1L, 2L), hidden = true)
|
||||
prefs.updateHiddenCalendarIds { it + listOf(1L, 2L) }
|
||||
assertThat(prefs.hiddenCalendarIds.first()).isEqualTo(setOf(1L, 2L, 9L))
|
||||
prefs.setCalendarsHidden(listOf(2L, 3L), hidden = false)
|
||||
assertThat(prefs.hiddenCalendarIds.first()).isEqualTo(setOf(1L, 9L))
|
||||
prefs.setCalendarsHidden(listOf(1L, 9L), hidden = false)
|
||||
prefs.updateHiddenCalendarIds { emptySet() }
|
||||
assertThat(prefs.hiddenCalendarIds.first()).isEmpty()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user