From a85a95507cd58fdbbcd7a1612b6a651cdcf9be3a Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 26 May 2026 01:01:31 -0400 Subject: [PATCH] fix(android): AlbumDetail shuffle button actually shuffles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Shuffle button on AlbumDetail was wired to the same code path as Play — both called `play(startTrackId = null)` which started the queue in track order. PlaylistDetail already does inline `.shuffled()` for shuffle; mirror that on AlbumDetail via a new `shuffle()` VM method that pre-shuffles the track list before handing it to the player. A future refinement could use Media3's `setShuffleModeEnabled` for play-then-shuffle without disturbing the original queue ordering, but pre-shuffling matches the existing PlaylistDetail behavior and keeps both screens consistent. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../minstrel/library/ui/AlbumDetailScreen.kt | 2 +- .../minstrel/library/ui/AlbumDetailViewModel.kt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/fabledsword/minstrel/library/ui/AlbumDetailScreen.kt b/android/app/src/main/java/com/fabledsword/minstrel/library/ui/AlbumDetailScreen.kt index 4a37a772..54ce5f00 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/library/ui/AlbumDetailScreen.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/library/ui/AlbumDetailScreen.kt @@ -87,7 +87,7 @@ fun AlbumDetailScreen( albumLiked = albumLiked, likedTrackIds = likedTrackIds, onPlayAll = { viewModel.play(startTrackId = null) }, - onShuffleAll = { viewModel.play(startTrackId = null) }, + onShuffleAll = viewModel::shuffle, onTrackClick = { id -> viewModel.play(startTrackId = id) }, onToggleAlbumLike = viewModel::toggleLikeAlbum, onToggleTrackLike = viewModel::toggleLikeTrack, diff --git a/android/app/src/main/java/com/fabledsword/minstrel/library/ui/AlbumDetailViewModel.kt b/android/app/src/main/java/com/fabledsword/minstrel/library/ui/AlbumDetailViewModel.kt index e8970724..324c06fa 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/library/ui/AlbumDetailViewModel.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/library/ui/AlbumDetailViewModel.kt @@ -90,6 +90,23 @@ class AlbumDetailViewModel @Inject constructor( ) } + /** + * Play the album in shuffled order. Pre-shuffles the list and hands + * the result to the player — matches the PlaylistDetail shuffle + * pattern. A future refinement could use Media3's + * `setShuffleModeEnabled` for play-then-shuffle without disturbing + * the original queue ordering. + */ + fun shuffle() { + val detail = (internal.value as? AlbumDetailUiState.Success)?.detail ?: return + if (detail.tracks.isEmpty()) return + player.setQueue( + tracks = detail.tracks.shuffled(), + initialIndex = 0, + source = "album:${detail.album.id}", + ) + } + fun toggleLikeAlbum() { val desired = !albumLiked.value viewModelScope.launch {