The first public release of Fabled Minstrel #158
+15
-7
@@ -145,13 +145,21 @@ class MutationReplayer @Inject constructor(
|
||||
// never reaches the server before the create of its list.
|
||||
val waiting = HashSet<String>()
|
||||
for (row in rows) {
|
||||
if (row.id in superseded) {
|
||||
dao.delete(row.id)
|
||||
continue
|
||||
}
|
||||
val playlistId = playlistIdOf(row, json)
|
||||
if (playlistId != null && playlistId in waiting) continue
|
||||
when (outcomeFor(row)) {
|
||||
replayRow(row, superseded = row.id in superseded, waiting = waiting)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends one row, or drops it when a later row has superseded it, or
|
||||
* 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.RETRY -> {
|
||||
dao.recordAttempt(row.id, Clock.System.now())
|
||||
|
||||
+30
-19
@@ -437,25 +437,7 @@ fun PlaylistDetailScreen(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
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,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
PlaylistDetailTopBar(state, viewModel, onBack = { navController.popBackStack() })
|
||||
},
|
||||
) { inner ->
|
||||
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
|
||||
private fun PlaylistDetailContent(
|
||||
state: PlaylistDetailUiState,
|
||||
|
||||
+28
-22
@@ -204,36 +204,42 @@ fun PlaylistsListScreen(
|
||||
},
|
||||
snackbarHost = { SnackbarHost(snackbar) },
|
||||
) { inner ->
|
||||
val state by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
val offline by viewModel.offline.collectAsStateWithLifecycle()
|
||||
PullToRefreshScaffold(
|
||||
onRefresh = { viewModel.refresh().join() },
|
||||
modifier = Modifier.fillMaxSize().padding(inner),
|
||||
) {
|
||||
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 = { id -> navController.navigate(PlaylistDetail(id)) },
|
||||
onPlay = viewModel::playPlaylist,
|
||||
)
|
||||
}
|
||||
PlaylistsListBody(viewModel, onOpen = { id -> navController.navigate(PlaylistDetail(id)) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 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
|
||||
private fun PlaylistsGrid(
|
||||
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
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
|
||||
Reference in New Issue
Block a user