mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
show the artist hero thumbnail under the full image too
This commit is contained in:
@@ -71,10 +71,12 @@ fun ArtistDetailRoute(
|
||||
val artist by viewModel.artist.collectAsStateWithLifecycle(initialValue = null)
|
||||
val albums by viewModel.albums.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||
val art by viewModel.art.collectAsStateWithLifecycle()
|
||||
val artThumbnail by viewModel.artThumbnail.collectAsStateWithLifecycle()
|
||||
ArtistDetailScreen(
|
||||
artist = artist,
|
||||
albums = albums,
|
||||
art = art,
|
||||
artThumbnail = artThumbnail,
|
||||
coverArt = viewModel::coverArt,
|
||||
onBack = onBack,
|
||||
onAlbumClick = onAlbumClick,
|
||||
@@ -87,6 +89,7 @@ fun ArtistDetailScreen(
|
||||
artist: Artist?,
|
||||
albums: List<Album>,
|
||||
art: CoverArtRef?,
|
||||
artThumbnail: CoverArtRef? = null,
|
||||
coverArt: (String?, Boolean) -> CoverArtRef?,
|
||||
onBack: () -> Unit,
|
||||
onAlbumClick: (Album) -> Unit,
|
||||
@@ -140,6 +143,7 @@ fun ArtistDetailScreen(
|
||||
CoverArt(
|
||||
ref = art,
|
||||
name = artist?.name.orEmpty(),
|
||||
thumbnailRef = artThumbnail,
|
||||
modifier = Modifier.fillMaxWidth().height(ART_HEIGHT),
|
||||
)
|
||||
Text(
|
||||
|
||||
@@ -33,22 +33,34 @@ class ArtistDetailViewModel(
|
||||
private val _art = MutableStateFlow<CoverArtRef?>(null)
|
||||
val art: StateFlow<CoverArtRef?> = _art
|
||||
|
||||
private val _artThumbnail = MutableStateFlow<CoverArtRef?>(null)
|
||||
val artThumbnail: StateFlow<CoverArtRef?> = _artThumbnail
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
artist
|
||||
.filterNotNull()
|
||||
.distinctUntilChangedBy { it.id }
|
||||
.collectLatest { loaded -> _art.value = resolveArt(loaded) }
|
||||
.collectLatest { loaded ->
|
||||
val (full, thumbnail) = resolveArt(loaded)
|
||||
_art.value = full
|
||||
_artThumbnail.value = thumbnail
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun resolveArt(artist: Artist): CoverArtRef? {
|
||||
private suspend fun resolveArt(artist: Artist): Pair<CoverArtRef?, CoverArtRef?> {
|
||||
repeat(3) { attempt ->
|
||||
val ref = sourceRepository.artistArt(artist.id) ?: sourceRepository.coverArt(artist.coverArt)
|
||||
if (ref != null) return ref
|
||||
val full = sourceRepository.artistArt(artist.id) ?: sourceRepository.coverArt(artist.coverArt)
|
||||
if (full != null) {
|
||||
val thumbnail =
|
||||
sourceRepository.artistArt(artist.id, thumbnail = true)
|
||||
?: sourceRepository.coverArt(artist.coverArt, thumbnail = true)
|
||||
return full to thumbnail
|
||||
}
|
||||
if (attempt < 2) delay(300)
|
||||
}
|
||||
return null
|
||||
return null to null
|
||||
}
|
||||
|
||||
fun coverArt(
|
||||
|
||||
Reference in New Issue
Block a user