fix: focus first unwatched episode in details view (#117) - #124
Merged
Conversation
Previously `initialEpisodeIndex` defaulted to 0 when the caller did not pass an explicit episode target (e.g., navigating to a show from the home grid rather than from a Continue Watching tile). That always focused episode 1 of the current season, forcing users to scroll past every episode they had already watched before reaching the next unwatched one — particularly painful on long-running anime with hundreds of episodes. `nextUnwatchedEpisode` was already computed on the line below and used to build the "Continue SxEy" play button label, but was never fed back into the initial focus index. Now: - If the caller passed an explicit episode target, focus it (unchanged). - Otherwise focus the first unwatched episode in the loaded season. - If every episode in the current season is already watched, fall back to episode 1 so the user can switch seasons from the normal starting point. This reuses the watched-status decoration that already runs a few lines earlier (from Trakt for Trakt-linked users, falling back to local season progress), so there is no extra work or network call. The `> 0` guard in DetailsScreen.LaunchedEffect still handles the index-0 case correctly because the screen-level `episodeIndex` default is also 0. Closes #117
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.
Summary
Closes #117.
In the episode list on the details screen, the first unwatched episode is now focused by default instead of always focusing episode 1. Particularly valuable for long-running shows/anime where users had to scroll past everything they had already watched.
Root cause
DetailsViewModel.loadDetails()computesnextUnwatchedEpisodeon line 496 and uses it for the play button label ("Continue S1E3"), butinitialEpisodeIndexat line 493-495 always defaulted to0when the caller did not pass an explicit episode target (which is the normal case for navigation from the home grid, search, catalogs, etc. — only Continue Watching tiles pass a target episode).Fix
Replaced the
if/else 0with a three-waywhen:The watched-status decoration already runs a few lines earlier (pulls from Trakt for linked users via
traktRepository.getWatchedEpisodesForShow(mediaId), falls back to local season progress otherwise), so this reuses existing data with zero extra network calls or work.Edge cases handled
nextUnwatchedEpisodeisnull, falls back to index 0 (episode 1). User can use the season selector to jump forward.nextUnwatchedEpisodeis episode 1,indexOf(...)returns 0, same as the old default.LaunchedEffectinDetailsScreen.kt:268keys on(initialEpisodeIndex, episodes)— both change when a new season loads, so the new focus index is picked up correctly.DetailsScreen.kt:269only re-syncs wheninitialEpisodeIndex > 0. When my fix returns 0, the screen-levelepisodeIndexdefault is also 0, so no re-sync is needed. No behavior change for shows where episode 1 is unwatched.Risk
Minimal. Single-file, 13-line change. Reuses existing watched-episode data. No new network calls, no new allocations on a hot path.