Persist hide-watched toggle across restart (vc=74 item 4)

hide-watched was session-only remember state in StrawHome — reset to OFF on every cold start. Back it with SettingsStore (SharedPreferences), mirroring hideShorts: new hideWatched StateFlow + setHideWatched(). StrawHome reads/writes Settings.
This commit is contained in:
Cobb 2026-06-20 07:57:51 -07:00
parent af3c39a662
commit 6f95b6fa3d
2 changed files with 23 additions and 6 deletions

View file

@ -294,12 +294,12 @@ private fun SubsPane(
}
LaunchedEffect(subs) { feedVm.refreshIfStale() }
// Filter + pagination state. hideWatched is sticky for the session
// (no SharedPreferences yet — easy to add if persistence is wanted).
// Filter + pagination state. hideWatched is persisted in SettingsStore
// (vc=74) so the choice survives app restart — was session-only
// `remember` before, which reset to OFF on every cold start.
// visibleCount starts at PAGE_SIZE and grows by PAGE_SIZE every time
// the scroll passes ~5 items from the bottom of what's currently
// visible.
var hideWatched by remember { mutableStateOf(false) }
// the scroll passes ~5 items from the bottom of what's currently visible.
val hideWatched by com.sulkta.straw.data.Settings.get().hideWatched.collectAsState()
var visibleCount by remember { mutableIntStateOf(PAGE_SIZE) }
// O(1) lookup for the watched-filter; rebuild only when watches
@ -355,7 +355,7 @@ private fun SubsPane(
)
FilterChip(
selected = hideWatched,
onClick = { hideWatched = !hideWatched },
onClick = { com.sulkta.straw.data.Settings.get().setHideWatched(!hideWatched) },
label = { Text("Hide watched") },
colors = FilterChipDefaults.filterChipColors(),
)

View file

@ -132,6 +132,7 @@ private const val KEY_LAST_UPDATE_CHECK_MS = "last_update_check_ms_v1"
private const val KEY_LATEST_KNOWN_VC = "latest_known_vc_v1"
private const val KEY_LATEST_KNOWN_VNAME = "latest_known_vname_v1"
private const val KEY_HIDE_SHORTS = "hide_shorts_v1"
private const val KEY_HIDE_WATCHED = "hide_watched_v1"
private const val KEY_CACHE_HISTORY_WATCHES = "cache_history_watches_v1"
private const val KEY_CACHE_HISTORY_SEARCHES = "cache_history_searches_v1"
private const val KEY_CACHE_RESUME_POSITIONS = "cache_resume_positions_v1"
@ -252,6 +253,16 @@ class SettingsStore(context: Context) {
)
val hideShorts: StateFlow<Boolean> = _hideShorts.asStateFlow()
/**
* Hide already-watched videos from feeds. Persisted (vc=74) was
* session-only `remember` state in StrawHome before, so it reset to
* OFF on every app restart.
*/
private val _hideWatched = MutableStateFlow(
sp.getBoolean(KEY_HIDE_WATCHED, false),
)
val hideWatched: StateFlow<Boolean> = _hideWatched.asStateFlow()
/**
* Per-store cache caps. Each store reads its cap from the matching
* StateFlow on every prune cycle so flipping the toggle in Settings
@ -402,6 +413,12 @@ class SettingsStore(context: Context) {
sp.edit().putBoolean(KEY_HIDE_SHORTS, hide).apply()
}
fun setHideWatched(hide: Boolean) {
if (_hideWatched.value == hide) return
_hideWatched.value = hide
sp.edit().putBoolean(KEY_HIDE_WATCHED, hide).apply()
}
fun setHistoryWatchesCap(cap: CacheCap) {
if (_historyWatchesCap.value == cap) return
_historyWatchesCap.value = cap