fix(android): album Neueste now uses Navidrome type=newest (add-date), not year sort
Loads albumsByNewest (type=newest) and albumsByName (alphabetical) in parallel. Neueste → Navidrome add-date order; A-Z → alphabetical; Älteste → client-side by year asc. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ffd071c58
commit
6a1bf33f31
2 files changed
+15
-10
No files matched your search
@@ -116,17 +116,14 @@ fun LibraryScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
val sortedAlbums = remember(state.albums, state.albumSort) {
|
||||
val sortedAlbums = remember(state.albumsByNewest, state.albumsByName, state.albumSort) {
|
||||
when (state.albumSort) {
|
||||
AlbumSort.NEWEST -> state.albums.sortedWith(
|
||||
compareByDescending<com.novasonic.app.api.model.Album> { it.year ?: 0 }
|
||||
.thenBy { it.name.lowercase() }
|
||||
)
|
||||
AlbumSort.OLDEST -> state.albums.sortedWith(
|
||||
AlbumSort.NEWEST -> state.albumsByNewest // already ordered by Navidrome add-date
|
||||
AlbumSort.AZ -> state.albumsByName // already ordered alphabetically
|
||||
AlbumSort.OLDEST -> state.albumsByName.sortedWith(
|
||||
compareBy<com.novasonic.app.api.model.Album> { it.year ?: Int.MAX_VALUE }
|
||||
.thenBy { it.name.lowercase() }
|
||||
)
|
||||
AlbumSort.AZ -> state.albums.sortedBy { it.name.lowercase() }
|
||||
}
|
||||
}
|
||||
val albumGridState = rememberLazyGridState()
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.novasonic.app.api.model.Album
|
||||
import com.novasonic.app.api.model.ArtistIndex
|
||||
import com.novasonic.app.api.model.Playlist
|
||||
import com.novasonic.app.app
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -16,7 +17,9 @@ enum class AlbumSort { NEWEST, OLDEST, AZ }
|
||||
|
||||
data class LibraryUiState(
|
||||
val tab: LibraryTab = LibraryTab.PLAYLISTS,
|
||||
val albums: List<Album> = emptyList(),
|
||||
// Two pre-fetched lists — avoids re-fetch when switching sort
|
||||
val albumsByNewest: List<Album> = emptyList(), // type=newest (Navidrome add-date)
|
||||
val albumsByName: List<Album> = emptyList(), // type=alphabeticalByName (for AZ + Oldest)
|
||||
val albumSort: AlbumSort = AlbumSort.NEWEST,
|
||||
val artistIndexes: List<ArtistIndex> = emptyList(),
|
||||
val playlists: List<Playlist> = emptyList(),
|
||||
@@ -49,8 +52,13 @@ class LibraryViewModel(app: Application) : AndroidViewModel(app) {
|
||||
private fun loadAlbums() = viewModelScope.launch {
|
||||
_state.value = _state.value.copy(isLoading = true, error = null)
|
||||
try {
|
||||
val albums = repo.getAlphaAlbums(200)
|
||||
_state.value = _state.value.copy(albums = albums, isLoading = false)
|
||||
val newestDef = async { repo.getRecentAlbums(500) } // type=newest → add-date order
|
||||
val azDef = async { repo.getAlphaAlbums(500) } // type=alphabeticalByName
|
||||
_state.value = _state.value.copy(
|
||||
albumsByNewest = newestDef.await(),
|
||||
albumsByName = azDef.await(),
|
||||
isLoading = false,
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
_state.value = _state.value.copy(error = e.message, isLoading = false)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user