fix(android): share timeline ViewModel app-scope so the viewer opens (ISSUE-121) #1132

Merged
chris merged 2 commits from fix/viewer-vm-scope into main 2026-10-12 10:13:59 +02:00
Owner

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. NavHost scopes every destination's ViewModels to its own NavBackStackEntry (NavBackStackEntry.LocalOwnersProvider provides the LocalViewModelStoreOwner), so the TimelineViewModel resolved inside composable(Routes.PHOTOS) and the one inside composable(Routes.MEDIA_DETAIL) were two different instances. The viewer received items.isEmpty() and MediaViewerScreen's empty-list guard (LaunchedEffect { onBack() }) popped straight back — the flicker.

Fix

  • Hoist TimelineViewModel to app scope in MemoriesApp.kt, the same idiom already used for SearchViewModel (#1119), AlbumDetailViewModel (#1121) and MapViewModel (#1126): one shared viewModel(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() mirroring MapViewModel: reset bumps the generation (stale in-flight responses are dropped) and clears the state; the screen calls ensureLoaded() 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.
  • Belt-and-braces empty state: MediaViewerScreen no 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.
  • The album picker keeps its deliberately fresh destination-scoped instance (its day list is per-pick by design; the local now shadows the hoisted one on purpose).
  • The other viewer entry points were unaffected: search (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 refetches
  • ensureLoaded does not refetch a loaded timeline
  • an empty library counts as loaded so ensureLoaded does not loop
  • ensureLoaded leaves a failed load to the screen's retry affordance

Verification

  • ./gradlew :app:testDebugUnitTest :app:assembleDebug — BUILD SUCCESSFUL (TimelineViewModelTest 25/25)
  • lintDebug error count unchanged at the 18-issue ISSUE-119 baseline — no new lint errors

Version

Bumped to 0.3.1 (versionCode 14) per the changelog-comment convention. ISSUE-121 archived in KNOWN_ISSUES.md.

## 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. `NavHost` scopes every destination's ViewModels to its own `NavBackStackEntry` (`NavBackStackEntry.LocalOwnersProvider` provides the `LocalViewModelStoreOwner`), so the `TimelineViewModel` resolved inside `composable(Routes.PHOTOS)` and the one inside `composable(Routes.MEDIA_DETAIL)` were two different instances. The viewer received `items.isEmpty()` and `MediaViewerScreen`'s empty-list guard (`LaunchedEffect { onBack() }`) popped straight back — the flicker. ## Fix - **Hoist `TimelineViewModel` to app scope** in `MemoriesApp.kt`, the same idiom already used for `SearchViewModel` (#1119), `AlbumDetailViewModel` (#1121) and `MapViewModel` (#1126): one shared `viewModel(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()`** mirroring `MapViewModel`: reset bumps the generation (stale in-flight responses are dropped) and clears the state; the screen calls `ensureLoaded()` 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. - **Belt-and-braces empty state**: `MediaViewerScreen` no 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. - The **album picker keeps its deliberately fresh destination-scoped instance** (its day list is per-pick by design; the local now shadows the hoisted one on purpose). - The **other viewer entry points were unaffected**: search (`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 refetches` - `ensureLoaded does not refetch a loaded timeline` - `an empty library counts as loaded so ensureLoaded does not loop` - `ensureLoaded leaves a failed load to the screen's retry affordance` ## Verification - `./gradlew :app:testDebugUnitTest :app:assembleDebug` — **BUILD SUCCESSFUL** (TimelineViewModelTest 25/25) - `lintDebug` error count unchanged at the 18-issue ISSUE-119 baseline — no new lint errors ## Version Bumped to 0.3.1 (versionCode 14) per the changelog-comment convention. ISSUE-121 archived in `KNOWN_ISSUES.md`.
navigation-compose scopes every destination's ViewModels to its own
NavBackStackEntry, so the destination-scoped TimelineViewModel in
composable(Routes.PHOTOS) and the one in composable(Routes.MEDIA_DETAIL)
were two different instances — the viewer received an empty item list
and MediaViewerScreen's empty-list guard popped straight back to the
grid: tapping a photo flickered and never opened the viewer.

- Hoist TimelineViewModel to app scope in MemoriesApp, the same idiom
  SearchViewModel/AlbumDetailViewModel/MapViewModel already use:
  one shared instance plus reset-on-session-change so one member's
  timeline never lingers under another member's login.
- Add TimelineViewModel.reset() (generation bump + clear) and
  ensureLoaded() (re-entry guard the screen calls on composition; an
  empty library counts as loaded, a failure waits for the visible
  retry affordance), mirroring MapViewModel.
- TimelineScreen calls ensureLoaded() on entry, like MapScreen.
- The album picker keeps its deliberately fresh destination-scoped
  instance; the other viewer entry points (search/album/map/person)
  were already reading hoisted ViewModels and are unaffected.
- Belt-and-braces: MediaViewerScreen no longer auto-pops on an empty
  list (that guard was the flicker); it shows a friendly empty state
  with the top-bar back button and keeps the Undo snackbar mounted.
  The awaitingUndo scaffolding that only existed to delay that pop is
  gone.
- JVM tests pin reset/ensureLoaded: refetch after reset, no refetch of
  a loaded or empty library, no hidden retry loop after a failure.
chore(android): bump to 0.3.1 (versionCode 14) and archive ISSUE-121
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 6s
Build and Deploy / Android unit tests and debug APK (push) Successful in 3m34s
83f6045591
0.3.1 is the viewer-scope fix release; the changelog comment follows
the established one-line-per-version convention. ISSUE-121 moves to the
Archived section as resolved per repo rules.
chris merged commit 3874e231b7 into main 2026-10-12 10:13:59 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1132
No description provided.