Repository navigation
fix(browse): stop the library sort resetting to its default - #237
Conversation
TV: backing out of item detail returned to a surviving library ViewModel, but re-entering the screen re-issues the committed cascade section, and onTabSelected re-applied the tab's default filter whenever the viewer had customised it — the guard only skipped when the filter was ALSO unchanged. Re-selecting the already-active tab is now a no-op; only a genuine tab change applies the new tab's defaults. Phone: the browse sort lived outside the persisted CatalogFilterState, so "Preserve sort & filters" restored the facet chips while the sort snapped back to Recently Added on relaunch. The sort now rides the persisted filter state (as BrowseViewModel already does) and is derived back out on restore. applyFilterState keeps the committed sort so the Reset control, which changes the sort and clears facets off the same composition frame, cannot reinstate the old one. Verified on both emulators: TV keeps Year/Newest across Back, phone keeps Title across a force-stop relaunch, and Reset still clears both. Co-Authored-By: Claude Opus 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: 1 review is currently available. Based on recent review activity, included reviews refill at 3 per hour. 📝 WalkthroughWalkthroughThe Android phone now persists and restores browse sort with filters. The Android TV no longer reapplies default browse filters when the active tab is selected again. ChangesAndroid phone browse sort persistence
Android TV browse tab preservation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change preserves customized library sorting across navigation and relaunch while keeping reset behavior intact; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Both comments asserted the behaviour the guard change removes — re-committing the same pill "re-applies the section rather than being a silent no-op". That is now exactly what must not happen, and these are the comments the next person reads when debugging this area. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7dc2f0414
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // re-applying `forTab` here would reset the viewer's customised sort | ||
| // and facets back to the tab's defaults (Title A–Z). Only a genuine | ||
| // tab CHANGE applies the new tab's defaults. | ||
| if (state.selectedTab == tab) return |
There was a problem hiding this comment.
Reapply explicitly recommitted TV library sections
When a viewer customizes the active Browse/Genres/A-Z section and then explicitly commits that same pill again from the Skyline cascade, the shell increments sectionRequestNonce specifically to reapply the section defaults, but this unconditional early return now discards the commit and leaves the custom sort and facets active. TvLibraryDetailScreen still invokes onTabSelected for every nonce change, so return-trip preservation needs to be distinguished from a genuine recommit rather than treating every same-tab selection as a no-op.
Useful? React with 👍 / 👎.
Fixes #236.
The reported symptom — "SORT goes back to default so have to start from scratch" — turned out to be two independent defects, one per client. Filters survive in both cases; only the sort is lost.
Android TV — sort lost on Back from item detail
TvLibraryDetailScreenre-issues the committed cascade section every time it re-enters composition:The ViewModel survives the Back (verified with a temporary log — same instance either side), but
onTabSelectedguarded withif (state.selectedTab == tab && !filterChanged) return. On re-entry the tab is unchanged andfilterChangedis true precisely because the viewer customised the sort, so the guard fell through andforTab(Browse)reset sort and facets to Title A–Z.Re-selecting the already-active tab is now a no-op. A genuine tab change still applies the new tab's defaults, and
forTab/onAudiobookGroupClearedare untouched.Android phone — sort lost on relaunch
LibrariesViewModelkept the sort inLibrariesUiState.browseSort, outside theCatalogFilterStatethatBrowsePrefsStorepersists — so "Preserve sort & filters" restored the chips while the sort snapped back to Recently Added.The sort now rides the persisted filter state, the way
BrowseViewModelalready does it, and is derived back out on restore viaLibraryBrowseSort.fromFilterState.applyFilterStatekeeps the sort already committed here and takes only the facet/match parts from its argument: the Reset control changes the sort and clears the facets off the same composition frame, so trusting the incoming state's sort would reinstate the one just cleared.Verified
On the local phone and TV emulators against the dev server, with builds from this branch:
Sort · Year Newest, grid still 2026-first. Before the fix it returned to Title A–Z.{"selections":{"WatchStatus":["unwatched"]},"sort":"title","order":"asc"}.{}../gradlew :androidApp:assembleDebug :androidTvApp:assembleDebugand:androidApp:testDebugUnitTest :androidTvApp:testDebugUnitTestpass.Tests
One focused regression test per app, in the existing files. Each was confirmed to fail with its fix reverted, so neither is vacuous.
LibrariesViewModelTestnow runs under Robolectric becauseBrowsePrefsStorewrites through realSharedPreferences(precedent:ReaderViewModelReaderTargetSourceTest,WatchTogetherEntryViewModelTest); all pre-existing tests in the file still pass.Behavioural deltas worth a reviewer's eye
onAudiobookGroupCleared, which has its own dedicated UI affordance (onClearAudiobookGroup), so nothing is trapped.selectLibrarypreviously carried the previous library's sort across a library switch. Sort now travels with the per-library persisted state, so switching to a library with nothing saved lands on Recently Added.TvLibraryDetailScreen.kt(thesectionRequestNoncedoc and theLaunchedEffectcomment) still claim re-committing the same pill "re-applies the section rather than being a silent no-op". That is now false when the tab is already selected — which is the fix. Left alone to keep the diff to the defect; happy to update them here if preferred.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes