From 6f95b6fa3dcb055a12b9077552891f56d70d1080 Mon Sep 17 00:00:00 2001 From: Cobb Date: Sat, 20 Jun 2026 07:57:51 -0700 Subject: [PATCH] Persist hide-watched toggle across restart (vc=74 item 4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../main/kotlin/com/sulkta/straw/StrawHome.kt | 12 ++++++------ .../com/sulkta/straw/data/SettingsStore.kt | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/strawApp/src/main/kotlin/com/sulkta/straw/StrawHome.kt b/strawApp/src/main/kotlin/com/sulkta/straw/StrawHome.kt index d62c68852..94616d9f7 100644 --- a/strawApp/src/main/kotlin/com/sulkta/straw/StrawHome.kt +++ b/strawApp/src/main/kotlin/com/sulkta/straw/StrawHome.kt @@ -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(), ) diff --git a/strawApp/src/main/kotlin/com/sulkta/straw/data/SettingsStore.kt b/strawApp/src/main/kotlin/com/sulkta/straw/data/SettingsStore.kt index 7ded93aba..e98e23607 100644 --- a/strawApp/src/main/kotlin/com/sulkta/straw/data/SettingsStore.kt +++ b/strawApp/src/main/kotlin/com/sulkta/straw/data/SettingsStore.kt @@ -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 = _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 = _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