fix(android): playlist screens and the replay loop meet detekt's limits (#8023)
release / go (push) Successful in 1m49s
release / web (push) Successful in 1m11s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m6s
release / android (push) Successful in 4m19s
release / Build signed APK (push) Successful in 4m44s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 15s
release / Verify release artifacts (tag releases only) (push) Skipped

The replay loop's per-row choice moves to replayRow, so the loop has no
continue. The playlist detail's top bar and the playlists list's body
move into their own composables. ReorderableRow.kt is named for its row,
not for ReorderHandles, its parameter type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 10:42:27 -05:00
co-authored by Claude Opus 5.5
parent 7e112ac523
commit 9b36effbaf
4 changed files with 75 additions and 48 deletions
@@ -145,13 +145,21 @@ class MutationReplayer @Inject constructor(
// never reaches the server before the create of its list. // never reaches the server before the create of its list.
val waiting = HashSet<String>() val waiting = HashSet<String>()
for (row in rows) { for (row in rows) {
if (row.id in superseded) { replayRow(row, superseded = row.id in superseded, waiting = waiting)
dao.delete(row.id) }
continue }
}
val playlistId = playlistIdOf(row, json) /**
if (playlistId != null && playlistId in waiting) continue * Sends one row, or drops it when a later row has superseded it, or
when (outcomeFor(row)) { * leaves it queued when an earlier change to the same playlist is still
* waiting. A row that has to retry makes its playlist wait in [waiting].
*/
private suspend fun replayRow(row: CachedMutationEntity, superseded: Boolean, waiting: MutableSet<String>) {
val playlistId = playlistIdOf(row, json)
when {
superseded -> dao.delete(row.id)
playlistId != null && playlistId in waiting -> Unit
else -> when (outcomeFor(row)) {
Outcome.SENT, Outcome.DROP -> dao.delete(row.id) Outcome.SENT, Outcome.DROP -> dao.delete(row.id)
Outcome.RETRY -> { Outcome.RETRY -> {
dao.recordAttempt(row.id, Clock.System.now()) dao.recordAttempt(row.id, Clock.System.now())
@@ -437,25 +437,7 @@ fun PlaylistDetailScreen(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
snackbarHost = { SnackbarHost(snackbarHostState) }, snackbarHost = { SnackbarHost(snackbarHostState) },
topBar = { topBar = {
TopAppBar( PlaylistDetailTopBar(state, viewModel, onBack = { navController.popBackStack() })
title = { Text(currentTitle(state)) },
navigationIcon = {
IconButton(onClick = { navController.popBackStack() }) {
Icon(Lucide.ArrowLeft, contentDescription = "Back")
}
},
actions = {
val playlist = (state as? PlaylistDetailUiState.Success)?.detail?.playlist
if (playlist != null && viewModel.canEdit(playlist)) {
PlaylistOwnerMenu(
playlist = playlist,
onRename = viewModel::rename,
onSetPublic = viewModel::setPublic,
onDelete = viewModel::delete,
)
}
},
)
}, },
) { inner -> ) { inner ->
PullToRefreshScaffold( PullToRefreshScaffold(
@@ -472,6 +454,35 @@ fun PlaylistDetailScreen(
} }
} }
/** The title and back arrow, and the owner's menu when the list is theirs to change. */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun PlaylistDetailTopBar(
state: PlaylistDetailUiState,
viewModel: PlaylistDetailViewModel,
onBack: () -> Unit,
) {
TopAppBar(
title = { Text(currentTitle(state)) },
navigationIcon = {
IconButton(onClick = onBack) {
Icon(Lucide.ArrowLeft, contentDescription = "Back")
}
},
actions = {
val playlist = (state as? PlaylistDetailUiState.Success)?.detail?.playlist
if (playlist != null && viewModel.canEdit(playlist)) {
PlaylistOwnerMenu(
playlist = playlist,
onRename = viewModel::rename,
onSetPublic = viewModel::setPublic,
onDelete = viewModel::delete,
)
}
},
)
}
@Composable @Composable
private fun PlaylistDetailContent( private fun PlaylistDetailContent(
state: PlaylistDetailUiState, state: PlaylistDetailUiState,
@@ -204,36 +204,42 @@ fun PlaylistsListScreen(
}, },
snackbarHost = { SnackbarHost(snackbar) }, snackbarHost = { SnackbarHost(snackbar) },
) { inner -> ) { inner ->
val state by viewModel.uiState.collectAsStateWithLifecycle()
val offline by viewModel.offline.collectAsStateWithLifecycle()
PullToRefreshScaffold( PullToRefreshScaffold(
onRefresh = { viewModel.refresh().join() }, onRefresh = { viewModel.refresh().join() },
modifier = Modifier.fillMaxSize().padding(inner), modifier = Modifier.fillMaxSize().padding(inner),
) { ) {
when (val s = state) { PlaylistsListBody(viewModel, onOpen = { id -> navController.navigate(PlaylistDetail(id)) })
UiState.Loading -> LoadingCentered()
UiState.Empty -> EmptyState(
title = "No playlists yet",
body = "System playlists (For You / Discover / Songs like…) " +
"appear once your library has enough plays. Make your own " +
"with + above, or from any track's Add to playlist.",
)
is UiState.Error -> ErrorRetry(
title = "Couldn't load playlists",
message = s.message,
onRetry = { viewModel.refresh() },
)
is UiState.Success -> PlaylistsGrid(
playlists = s.data,
offline = offline,
onPlaylistClick = { id -> navController.navigate(PlaylistDetail(id)) },
onPlay = viewModel::playPlaylist,
)
}
} }
} }
} }
/** Loading, empty, error, or the grid of playlists. */
@Composable
private fun PlaylistsListBody(viewModel: PlaylistsListViewModel, onOpen: (String) -> Unit) {
val state by viewModel.uiState.collectAsStateWithLifecycle()
val offline by viewModel.offline.collectAsStateWithLifecycle()
when (val s = state) {
UiState.Loading -> LoadingCentered()
UiState.Empty -> EmptyState(
title = "No playlists yet",
body = "System playlists (For You / Discover / Songs like…) " +
"appear once your library has enough plays. Make your own " +
"with + above, or from any track's Add to playlist.",
)
is UiState.Error -> ErrorRetry(
title = "Couldn't load playlists",
message = s.message,
onRetry = { viewModel.refresh() },
)
is UiState.Success -> PlaylistsGrid(
playlists = s.data,
offline = offline,
onPlaylistClick = onOpen,
onPlay = viewModel::playPlaylist,
)
}
}
@Composable @Composable
private fun PlaylistsGrid( private fun PlaylistsGrid(
playlists: List<PlaylistRef>, playlists: List<PlaylistRef>,
@@ -1,3 +1,5 @@
@file:Suppress("MatchingDeclarationName") // The file is named for its row; ReorderHandles is the row's parameter type.
package com.fabledsword.minstrel.shared.widgets package com.fabledsword.minstrel.shared.widgets
import androidx.compose.foundation.background import androidx.compose.foundation.background