Repository navigation
Fix missing server-side lyrics in Now Playing - #1406
Conversation
| started = entry == null || entry.state is DataState.Error | ||
| val access = (current.values.maxOfOrNull { it.access } ?: 0) + 1 | ||
| // Returning to a cached track keeps it ahead of older requests that are still in flight. | ||
| current + (key to Entry(if (started) DataState.Loading() else entry!!.state, access)) |
There was a problem hiding this comment.
We don't do forced non-null cast in this repo.
I will post full comments a bit later.
formatBCE
left a comment
There was a problem hiding this comment.
Thanks for taking this!
A few points before merge:
Must fix
entry!!.stateinTrackLyricsRepository.load. The project bans!!in live code, and here it is avoidable:entryis never null on that path. Useentry?.state ?: DataState.Loading(), or carry the entry out of thestartedcheck.
Should fix
-
The repository duplicates
TranscriptRepository, with different wiring.TranscriptRepositoryis a Koin singleton in the app scope, because the item page and the player ask for the same episode. This PR buildsTrackLyricsRepositoryinsideHomeScreenViewModelonviewModelScope, which causes two problems:- It goes around DI. The project rule is that
HomeScreenViewModeldependencies come fromSharedModule.kt. ItemDetailsViewModelstill callsfetchTrackLyricsdirectly, so the track page and the player do not share a cache.TranscriptRepositoryexists to avoid exactly this.
Suggestion: register it in Koin on the app scope and send the item page through it as well. Better still, make one
LyricsRepositorywithload(track)andload(episode). The two classes differ only in the fetch call and the key. - It goes around DI. The project rule is that
-
The
accesscounter is more than this needs.maxOfOrNull + 1on every load is a hand-built LRU.TranscriptRepository.appended()gets the same order by removing the key and adding it again, because a KotlinMapkeeps insertion order. Reusing that pattern removes theEntrywrapper. -
The error handling differs from the transcript path. This PR uses
getOrThrow()withtry/catchfor cancellation, whileTranscriptRepositoryusesResult.fold. Point 2 removes this difference if the classes merge, so align it either way.
Nits
- The pager now collects
trackLyricsfor every composed page, not only the current one. That costs little, because it is amapState, so this is fine. .claude/architecture.mddescribes transcripts in the "Episode page" section but says nothing about Now Playing lyrics. Please add a line there, because the guidelines ask for it when a pattern changes.- The new case in
MediaItemRepositoryLyricsTesttestsfetchTrackLyrics, which this PR does not change. It does no harm, but it is out of scope.
With point 1 fixed and point 2 done (at least the Koin wiring), this is good to merge.
|
Thanks for the detailed review! I've pushed the requested changes:
All required checks pass: The PR is ready for another review. |
formatBCE
left a comment
There was a problem hiding this comment.
Thank you, this is much better.
Three small things:
- The .claude/architecture.md paragraph carries too much code detail. Please use ASD-STE100 style to conform the overall format.
- The compare-and-set loop replaces an update { } that already worked.
- The test files use different name styles.
|
Thanks! I've addressed all three points. The changes are pushed and ready for another look. |
formatBCE
left a comment
There was a problem hiding this comment.
Great. Thanks for fixing!
Closes #1404
Is there anything about the code changes here that should be highlighted?
Previously, Now Playing only checked the track's embedded
lyricsfield. Lyrics provided by Music Assistant metadata providers (such as LRCLIB or Genius) were therefore unavailable, even when they were displayed correctly in the web interface.This PR adds support for fetching server-side lyrics through the existing
metadata/get_track_lyricsAPI.Key changes:
The implementation reuses the existing Music Assistant API and does not require any server-side changes.
Testing:
Are there any additional changes not related to the issue above?
No.
Before submitting this PR, make sure you have:
./gradlew detektAll testAndroidHostTest :androidApp:testDebug