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.
|
// 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())
|
||||||
|
|||||||
+30
-19
@@ -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,
|
||||||
|
|||||||
+28
-22
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user