fix(android): back from album returns to the "all albums" view, not the artist page

The artist screen's "show all albums" overlay state was plain remember(), so
navigating into an album and pressing back reset it — dumping you on the
collapsed artist page instead of the list you came from. Persist which section
is open via rememberSaveable (a String? title) so it survives the round-trip,
and re-derive the overlay entries from the (surviving) categorized albums.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Opus 4.8 committed 2026-07-01 21:35:01 +02:00
1 parent 445a7bf583
commit 8741c2fb88
1 file changed
+35 -41
@@ -26,6 +26,7 @@ import androidx.compose.material.icons.filled.Shuffle
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@@ -68,11 +69,12 @@ fun ArtistDetailScreen(
BackHandler(enabled = state.partialAlbum != null) { vm.dismissPartialAlbum() } BackHandler(enabled = state.partialAlbum != null) { vm.dismissPartialAlbum() }
BackHandler(enabled = state.subAlbumItem != null && state.partialAlbum == null) { vm.dismissSubAlbum() } BackHandler(enabled = state.subAlbumItem != null && state.partialAlbum == null) { vm.dismissSubAlbum() }
var showAllAlbums by remember { mutableStateOf(false) } // Which "all albums" section is expanded (by title), or null. rememberSaveable so it survives
var allAlbumsTitle by remember { mutableStateOf("") } // navigating into an album and back — otherwise back would land on the collapsed artist page.
var allAlbumEntries by remember { mutableStateOf<List<AllAlbumEntry>>(emptyList()) } var openAllAlbums by rememberSaveable { mutableStateOf<String?>(null) }
val showAllAlbums = openAllAlbums != null
BackHandler(enabled = showAllAlbums && state.partialAlbum == null && state.subAlbumItem == null) { BackHandler(enabled = showAllAlbums && state.partialAlbum == null && state.subAlbumItem == null) {
showAllAlbums = false openAllAlbums = null
} }
LaunchedEffect(state.pendingShufflePlay) { LaunchedEffect(state.pendingShufflePlay) {
@@ -163,11 +165,35 @@ fun ArtistDetailScreen(
// Album categories (computed once iTunes data arrives) // Album categories (computed once iTunes data arrives)
val cats = if (state.iAlbums.isNotEmpty()) categorizeAlbums(artist.album, state.iAlbums) else null val cats = if (state.iAlbums.isNotEmpty()) categorizeAlbums(artist.album, state.iAlbums) else null
// Rebuild the overlay entries from the (surviving) categorized albums for whichever section is
// open. Derived — not stored — so it's correct after returning from an album.
val allAlbumEntries: List<AllAlbumEntry> = when (openAllAlbums) {
"In Library" -> cats?.downloaded?.map { (nd, _) ->
AllAlbumEntry(name = nd.name, year = nd.year?.toString(), artUrl = coverUrl(nd.coverArt), onClick = { onAlbumClick(nd) })
}.orEmpty()
"Unvollständig" -> cats?.partial?.map { (nd, ia, counts) ->
AllAlbumEntry(
name = nd.name, year = nd.year?.toString(),
artUrl = ia.artworkUrl100?.replace("100x100bb", "300x300bb") ?: coverUrl(nd.coverArt),
badge = "${counts.first}/${counts.second}",
onClick = { vm.loadPartialAlbum(nd, ia) }, onDownload = { vm.showDownloadSheet(ia) },
)
}.orEmpty()
"Nicht heruntergeladen" -> cats?.notDownloaded?.map { ia ->
AllAlbumEntry(
name = ia.collectionName ?: "—", year = ia.releaseDate?.take(4),
artUrl = ia.artworkUrl100?.replace("100x100bb", "300x300bb"), dimmed = true,
onClick = { vm.loadSubAlbum(ia) }, onDownload = { vm.showDownloadSheet(ia) },
)
}.orEmpty()
else -> emptyList()
}
if (showAllAlbums) { if (showAllAlbums) {
AllAlbumsOverlay( AllAlbumsOverlay(
title = allAlbumsTitle, title = openAllAlbums ?: "",
entries = allAlbumEntries, entries = allAlbumEntries,
onBack = { showAllAlbums = false }, onBack = { openAllAlbums = null },
) )
return return
} }
@@ -349,13 +375,7 @@ fun ArtistDetailScreen(
if (cats.downloaded.isNotEmpty()) { if (cats.downloaded.isNotEmpty()) {
item { item {
ArtistSectionHeader("In Library", cats.downloaded.size, ArtistSectionHeader("In Library", cats.downloaded.size,
onShowAll = if (cats.downloaded.size > 4) ({ onShowAll = if (cats.downloaded.size > 4) ({ openAllAlbums = "In Library" }) else null
allAlbumsTitle = "In Library"
allAlbumEntries = cats.downloaded.map { (nd, _) ->
AllAlbumEntry(name = nd.name, year = nd.year?.toString(), artUrl = coverUrl(nd.coverArt), onClick = { onAlbumClick(nd) })
}
showAllAlbums = true
}) else null
) )
} }
item { item {
@@ -379,20 +399,7 @@ fun ArtistDetailScreen(
if (cats.partial.isNotEmpty()) { if (cats.partial.isNotEmpty()) {
item { item {
ArtistSectionHeader("Unvollständig", cats.partial.size, ArtistSectionHeader("Unvollständig", cats.partial.size,
onShowAll = if (cats.partial.size > 4) ({ onShowAll = if (cats.partial.size > 4) ({ openAllAlbums = "Unvollständig" }) else null
allAlbumsTitle = "Unvollständig"
allAlbumEntries = cats.partial.map { (nd, ia, counts) ->
AllAlbumEntry(
name = nd.name,
year = nd.year?.toString(),
artUrl = ia.artworkUrl100?.replace("100x100bb", "300x300bb") ?: coverUrl(nd.coverArt),
badge = "${counts.first}/${counts.second}",
onClick = { vm.loadPartialAlbum(nd, ia) },
onDownload = { vm.showDownloadSheet(ia) },
)
}
showAllAlbums = true
}) else null
) )
} }
item { item {
@@ -419,20 +426,7 @@ fun ArtistDetailScreen(
if (cats.notDownloaded.isNotEmpty()) { if (cats.notDownloaded.isNotEmpty()) {
item { item {
ArtistSectionHeader("Nicht heruntergeladen", cats.notDownloaded.size, ArtistSectionHeader("Nicht heruntergeladen", cats.notDownloaded.size,
onShowAll = if (cats.notDownloaded.size > 4) ({ onShowAll = if (cats.notDownloaded.size > 4) ({ openAllAlbums = "Nicht heruntergeladen" }) else null
allAlbumsTitle = "Nicht heruntergeladen"
allAlbumEntries = cats.notDownloaded.map { ia ->
AllAlbumEntry(
name = ia.collectionName ?: "—",
year = ia.releaseDate?.take(4),
artUrl = ia.artworkUrl100?.replace("100x100bb", "300x300bb"),
dimmed = true,
onClick = { vm.loadSubAlbum(ia) },
onDownload = { vm.showDownloadSheet(ia) },
)
}
showAllAlbums = true
}) else null
) )
} }
item { item {