mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 15:29:15 +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 artist by viewModel.artist.collectAsStateWithLifecycle(initialValue = null)
|
||||||
val albums by viewModel.albums.collectAsStateWithLifecycle(initialValue = emptyList())
|
val albums by viewModel.albums.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||||
val art by viewModel.art.collectAsStateWithLifecycle()
|
val art by viewModel.art.collectAsStateWithLifecycle()
|
||||||
|
val artThumbnail by viewModel.artThumbnail.collectAsStateWithLifecycle()
|
||||||
ArtistDetailScreen(
|
ArtistDetailScreen(
|
||||||
artist = artist,
|
artist = artist,
|
||||||
albums = albums,
|
albums = albums,
|
||||||
art = art,
|
art = art,
|
||||||
|
artThumbnail = artThumbnail,
|
||||||
coverArt = viewModel::coverArt,
|
coverArt = viewModel::coverArt,
|
||||||
onBack = onBack,
|
onBack = onBack,
|
||||||
onAlbumClick = onAlbumClick,
|
onAlbumClick = onAlbumClick,
|
||||||
@@ -87,6 +89,7 @@ fun ArtistDetailScreen(
|
|||||||
artist: Artist?,
|
artist: Artist?,
|
||||||
albums: List<Album>,
|
albums: List<Album>,
|
||||||
art: CoverArtRef?,
|
art: CoverArtRef?,
|
||||||
|
artThumbnail: CoverArtRef? = null,
|
||||||
coverArt: (String?, Boolean) -> CoverArtRef?,
|
coverArt: (String?, Boolean) -> CoverArtRef?,
|
||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
onAlbumClick: (Album) -> Unit,
|
onAlbumClick: (Album) -> Unit,
|
||||||
@@ -140,6 +143,7 @@ fun ArtistDetailScreen(
|
|||||||
CoverArt(
|
CoverArt(
|
||||||
ref = art,
|
ref = art,
|
||||||
name = artist?.name.orEmpty(),
|
name = artist?.name.orEmpty(),
|
||||||
|
thumbnailRef = artThumbnail,
|
||||||
modifier = Modifier.fillMaxWidth().height(ART_HEIGHT),
|
modifier = Modifier.fillMaxWidth().height(ART_HEIGHT),
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@@ -33,22 +33,34 @@ class ArtistDetailViewModel(
|
|||||||
private val _art = MutableStateFlow<CoverArtRef?>(null)
|
private val _art = MutableStateFlow<CoverArtRef?>(null)
|
||||||
val art: StateFlow<CoverArtRef?> = _art
|
val art: StateFlow<CoverArtRef?> = _art
|
||||||
|
|
||||||
|
private val _artThumbnail = MutableStateFlow<CoverArtRef?>(null)
|
||||||
|
val artThumbnail: StateFlow<CoverArtRef?> = _artThumbnail
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
artist
|
artist
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.distinctUntilChangedBy { it.id }
|
.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 ->
|
repeat(3) { attempt ->
|
||||||
val ref = sourceRepository.artistArt(artist.id) ?: sourceRepository.coverArt(artist.coverArt)
|
val full = sourceRepository.artistArt(artist.id) ?: sourceRepository.coverArt(artist.coverArt)
|
||||||
if (ref != null) return ref
|
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)
|
if (attempt < 2) delay(300)
|
||||||
}
|
}
|
||||||
return null
|
return null to null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun coverArt(
|
fun coverArt(
|
||||||
|
|||||||
Reference in New Issue
Block a user