fix: preserve heroItem during loadHomeData reloads to prevent Continue Watching hero override - #177
Merged
Conversation
…e Watching hero override
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a home-screen UX bug where catalog-triggered reloads could overwrite the currently focused hero with the first “Continue Watching” item by preserving the existing heroItem across loadHomeData() refreshes and tightening the hero null-fallback behavior in HomeScreen.
Changes:
- Preserve an existing
uiState.heroItemduringloadHomeData()by matching it (id + mediaType) against freshly loaded categories, falling back to the prior instance if not found. - Gate
HomeScreen’s “first row / first item” hero fallback so it only applies during the initial-load window (whenuiState.categoriesis still empty). - Adds extensive
HeroDebuglogging for diagnostics (currently present in the PR).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| app/src/main/kotlin/com/arflix/tv/ui/screens/home/HomeViewModel.kt | Preserves current hero across reloads by remapping it into refreshed categories; adds HeroDebug logging. |
| app/src/main/kotlin/com/arflix/tv/ui/screens/home/HomeScreen.kt | Prevents mid-session hero corruption by limiting the null-fallback; adds HeroDebug logging in hero/focus watcher. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+717
to
+726
| if (categoriesSnapshot.isEmpty() || focusState.isSidebarFocused) { | ||
| android.util.Log.d("HeroDebug", "LaunchedEffect: EXIT at line 708 (empty=${categoriesSnapshot.isEmpty()}, sidebar=${focusState.isSidebarFocused})") | ||
| return@collectLatest | ||
| } | ||
| if (focusSnapshot.focusedItemKey.isBlank()) { | ||
| android.util.Log.d("HeroDebug", "LaunchedEffect: EXIT at line 709 (blank focusedKey)") | ||
| return@collectLatest | ||
| } | ||
| if (focusSnapshot.focusedItemKey == focusSnapshot.heroItemKey) { | ||
| android.util.Log.d("HeroDebug", "LaunchedEffect: EXIT at line 710 (hero already correct: ${focusSnapshot.heroItemKey})") |
Contributor
Author
There was a problem hiding this comment.
@copilot apply changes based on this feedback
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
@copilot apply changes based on the comments in this thread |
Contributor
Author
|
@ProdigyV21 - should work as expected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug where the home screen hero item would be incorrectly overridden by a Continue Watching item during catalog-triggered data reloads.
Root cause: When
loadHomeDatarefreshes categories (e.g. after Trakt sync or pull-to-refresh),chooseInitialHero(categories)unconditionally selects the first item from the first non-empty row — which is the "Continue Watching" row when it exists. This overwrites whatever item the user was currently focused on. The hero-updateLaunchedEffectinHomeScreen.ktattempts to correct this via focus-based hero updates, but during a reload the categories are rebuilt with fresh data instances, causing the key-based guard to bail out early (item at the focused position now has a different instance key). Result: the hero gets permanently stuck on the first CW item until the user navigates to a new row.Fix (2 parts):
Preserve hero during reload —
HomeViewModel.loadHomeData(): If aheroItemalready exists in the UI state, preserve it across the reload by attempting to find its match (byid+mediaType) in the fresh categories. Falls back to keeping the old hero instance if not found, with theLaunchedEffectcorrecting it on next focus change.Guard the hero fallback —
HomeScreen.displayHeroItem: The?: displayCategories.firstOrNull()?.items?.firstOrNull()fallback was silently showing the first row's first item when the hero wasnull, even after categories were populated. Gated to only apply during the initial-load window whenuiState.categoriesis empty, preventing silent hero corruption mid-session.Changes
HomeViewModel.ktheroItemduringloadHomeDatareloads by matchingid/mediaTypein fresh categoriesHomeScreen.ktCleanup
Temporary
HeroDebugdiagnostic logs were removed before merge.Testing
chooseInitialHeroLaunchedEffectcontinues to correct hero on focus change post-reload:app:compileSideloadDebugKotlinpassed:app:compilePlayDebugKotlinpassed