fix(android): share timeline ViewModel app-scope so the viewer opens (ISSUE-121) #1132
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/viewer-vm-scope"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem (ISSUE-121)
Tapping a photo in the Android timeline grid did NOT open the viewer: the screen flickered briefly and stayed on the gallery.
NavHostscopes every destination's ViewModels to its ownNavBackStackEntry(NavBackStackEntry.LocalOwnersProviderprovides theLocalViewModelStoreOwner), so theTimelineViewModelresolved insidecomposable(Routes.PHOTOS)and the one insidecomposable(Routes.MEDIA_DETAIL)were two different instances. The viewer receiveditems.isEmpty()andMediaViewerScreen's empty-list guard (LaunchedEffect { onBack() }) popped straight back — the flicker.Fix
TimelineViewModelto app scope inMemoriesApp.kt, the same idiom already used forSearchViewModel(#1119),AlbumDetailViewModel(#1121) andMapViewModel(#1126): one sharedviewModel(factory)at the top of the composable +LaunchedEffect(session) { reset() }so one member's timeline never lingers under another member's login.TimelineViewModel.reset()/ensureLoaded()mirroringMapViewModel: reset bumps the generation (stale in-flight responses are dropped) and clears the state; the screen callsensureLoaded()on composition so a re-entered tab or a fresh login re-fetches, an empty library counts as loaded (endReached), and a failure waits for the visible retry affordance instead of auto-looping.MediaViewerScreenno longer auto-pops on an empty list — it shows a friendly empty state (viewer_empty, de/en/da) with the top-bar back button and keeps the Undo snackbar mounted, so trashing the last item never produces a flicker even if the list empties again.searchMedia/{id}), album (albumMedia/{id}), map (mapMedia/{id}) and person (personMedia/{id) all already read their hoisted ViewModels' item lists.JVM test coverage
The scoping itself is composition-level (no compose-ui-test dependency in this project — none added). What is testable at JVM level is pinned in
TimelineViewModelTest:reset forgets the previous session and ensureLoaded refetchesensureLoaded does not refetch a loaded timelinean empty library counts as loaded so ensureLoaded does not loopensureLoaded leaves a failed load to the screen's retry affordanceVerification
./gradlew :app:testDebugUnitTest :app:assembleDebug— BUILD SUCCESSFUL (TimelineViewModelTest 25/25)lintDebugerror count unchanged at the 18-issue ISSUE-119 baseline — no new lint errorsVersion
Bumped to 0.3.1 (versionCode 14) per the changelog-comment convention. ISSUE-121 archived in
KNOWN_ISSUES.md.