fix(android): AddToPlaylist routes empty list through UiState.Empty
The original AddToPlaylistUiState only had Loading/Success/Error, with the empty-list message branched inside Success. After migrating to shared UiState<T> (which adds Empty), the sheet's when over the state was non-exhaustive. Route empty through UiState.Empty at the VM, drop the inner branch in the sheet, and add the explicit Empty arm in the when block to satisfy the compiler.
This commit is contained in:
+8
-11
@@ -60,22 +60,19 @@ fun AddToPlaylistSheet(
|
||||
modifier = Modifier.fillMaxWidth().padding(24.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) { CircularProgressIndicator(color = MaterialTheme.colorScheme.primary) }
|
||||
UiState.Empty -> Text(
|
||||
text = "You haven't created any playlists yet.",
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 20.dp, vertical = 12.dp),
|
||||
)
|
||||
is UiState.Error -> Text(
|
||||
text = s.message,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
modifier = Modifier.padding(horizontal = 20.dp, vertical = 12.dp),
|
||||
)
|
||||
is UiState.Success -> if (s.data.isEmpty()) {
|
||||
Text(
|
||||
text = "You haven't created any playlists yet.",
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 20.dp, vertical = 12.dp),
|
||||
)
|
||||
} else {
|
||||
LazyColumn(modifier = Modifier.fillMaxWidth()) {
|
||||
items(items = s.data, key = { it.id }) { p ->
|
||||
PlaylistPickRow(playlist = p, onClick = { onPick(p.id) })
|
||||
}
|
||||
is UiState.Success -> LazyColumn(modifier = Modifier.fillMaxWidth()) {
|
||||
items(items = s.data, key = { it.id }) { p ->
|
||||
PlaylistPickRow(playlist = p, onClick = { onPick(p.id) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -30,7 +30,9 @@ class AddToPlaylistViewModel @Inject constructor(
|
||||
|
||||
val uiState: StateFlow<UiState<List<PlaylistRef>>> = repository
|
||||
.observeUserPlaylists()
|
||||
.map { list -> UiState.Success(list) as UiState<List<PlaylistRef>> }
|
||||
.map { list ->
|
||||
if (list.isEmpty()) UiState.Empty else UiState.Success(list)
|
||||
}
|
||||
.onStart {
|
||||
// Best-effort refresh so the sheet reflects newly-created
|
||||
// playlists from another device. Cached list shows first;
|
||||
|
||||
Reference in New Issue
Block a user