music: the up-next panel no longer resurrects the queue on the final track
- Commit
fdc0030c07bab398ce33c1d43a9f1f5d0794604a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 05:33 UTC (5 days ago)
- Parents
c798cec
queueOriginSongs computed the upcoming slice as
dropWhile{current}.drop(1), then applied
ifEmpty { origin }. With [1,2,3] and song 3 playing that is
[] -> [1,2,3]: on the final track of every album, artist,
playlist and all-songs queue the 'up next' panel listed the
already-played songs as upcoming, and tapping one called
playSong on the full origin — silently replacing the queue.
The fallback was meant only for 'current song unknown' (the
function's own contract says so), and the same ifEmpty
conflated that case with 'current song is last, upcoming is
legitimately empty'.
The slicing now resolves the current index: found -> the
slice after it (empty at queue end); not found or null ->
the whole origin, preserving the intended unknown-current
fallback. queueOriginSongs/QueueOrigin became internal for
unit testing. Four regression tests pin queue-end empty for
each origin kind, the mid-queue slice and the preserved
fallback. Playback persistence (absent by design), cast
handoff, lyrics timing and aggregation were audited and
cleared. Verified: targeted new tests and the adjacent queue
suite pass; the full suite hit the known stuck-worker hang
(125 tests ran, 0 failures before the kill); lint errors are
pre-existing on untouched files.Diff
music/src/main/java/com/vayunmathur/music/ui/NowPlayingQueue.kt
diff --git a/music/src/main/java/com/vayunmathur/music/ui/NowPlayingQueue.kt b/music/src/main/java/com/vayunmathur/music/ui/NowPlayingQueue.ktindex b3cb57a973..d2b2aa868b 100644--- a/music/src/main/java/com/vayunmathur/music/ui/NowPlayingQueue.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/NowPlayingQueue.kt@@ -65,7 +65,7 @@ fun NowPlayingQueue( } /** The songs the queue panel shows, and the title above them. */-private data class QueueOrigin(+internal data class QueueOrigin( val songs: List<Music>, val title: String, )@@ -74,8 +74,14 @@ private data class QueueOrigin( * Upcoming songs after [currentSongId] from the player's origin, or everything * when the current song is unknown (stale state): an empty panel would read as * "no queue" when the queue is merely unresolved.+ *+ * A current song that *is* in the origin but is its last song is not the+ * unknown case: nothing follows it, so the panel is empty. Falling back to+ * the whole origin there showed already-played songs as "up next" at the end+ * of every queue and let a tap on one restart playback from a slice that had+ * silently become the full list again. */-private fun queueOriginSongs(+internal fun queueOriginSongs( allMusic: List<Music>, playlistMemberIds: List<Long>, sourceId: String?,@@ -89,11 +95,10 @@ private fun queueOriginSongs( is PlaybackSource.Artist -> allMusic.filter { it.artistId == source.artistId } else -> allMusic.sortedBy { it.title } }- val upcoming = currentSongId?.let { id ->- origin.dropWhile { it.id != id }.drop(1)- }.orEmpty()+ val currentIndex = currentSongId?.let { id -> origin.indexOfFirst { it.id == id } } ?: -1+ val upcoming = if (currentIndex >= 0) origin.drop(currentIndex + 1) else origin return QueueOrigin(- songs = upcoming.ifEmpty { origin },+ songs = upcoming, title = "", ) }
music/src/test/java/com/vayunmathur/music/ui/NowPlayingQueueOriginTest.kt
diff --git a/music/src/test/java/com/vayunmathur/music/ui/NowPlayingQueueOriginTest.kt b/music/src/test/java/com/vayunmathur/music/ui/NowPlayingQueueOriginTest.ktnew file mode 100644index 0000000000..d244e954a4--- /dev/null+++ b/music/src/test/java/com/vayunmathur/music/ui/NowPlayingQueueOriginTest.kt@@ -0,0 +1,68 @@+package com.vayunmathur.music.ui++import com.vayunmathur.music.data.Music+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Regression tests for [queueOriginSongs], the queue panel's "up next" slice.+ *+ * The bug pinned here: with origin [1, 2, 3] and song 3 (the last one)+ * playing, the upcoming slice is empty, and the old `ifEmpty { origin }`+ * fallback replaced that empty slice with the whole origin — so at the end+ * of every queue the panel showed every already-played song as upcoming.+ * The fallback exists only for the *unknown* current song (null or not in+ * the origin), where showing the origin beats an empty panel.+ */+class NowPlayingQueueOriginTest {++ private fun song(id: Long, title: String, albumId: Long = 21L, artistId: Long = 11L) = Music(+ id = id,+ title = title,+ artist = "Artist",+ artistId = artistId,+ album = "Album",+ albumId = albumId,+ uri = "content://media/external/audio/media/$id",+ duration = 180_000L,+ trackNumber = id.toInt(),+ year = 2020,+ discNumber = 1,+ )++ private val songs = listOf(+ song(1L, "Alpha"),+ song(2L, "Beta"),+ song(3L, "Gamma"),+ )++ @Test+ fun lastSongInQueueHasNoUpcomingSongs() {+ val origin = queueOriginSongs(songs, emptyList(), sourceId = null, currentSongId = 3L)+ assertTrue(origin.songs.isEmpty(), "queue end must show nothing upcoming, was ${origin.songs.map { it.id }}")+ }++ @Test+ fun lastSongOfAlbumAndPlaylistOriginsHaveNoUpcomingSongs() {+ val album = queueOriginSongs(songs, emptyList(), sourceId = "album_21", currentSongId = 3L)+ assertTrue(album.songs.isEmpty())+ val playlist = queueOriginSongs(songs, listOf(1L, 2L, 3L), sourceId = "playlist_7", currentSongId = 3L)+ assertTrue(playlist.songs.isEmpty())+ }++ @Test+ fun upcomingAfterMiddleSongExcludesPlayedAndCurrent() {+ val origin = queueOriginSongs(songs, emptyList(), sourceId = null, currentSongId = 1L)+ // All-songs origin is title-sorted (Alpha, Beta, Gamma).+ assertEquals(listOf(2L, 3L), origin.songs.map { it.id })+ }++ @Test+ fun unknownOrAbsentCurrentSongStillShowsWholeOrigin() {+ val absent = queueOriginSongs(songs, emptyList(), sourceId = null, currentSongId = null)+ assertEquals(listOf(1L, 2L, 3L), absent.songs.map { it.id })+ val stale = queueOriginSongs(songs, emptyList(), sourceId = null, currentSongId = 99L)+ assertEquals(listOf(1L, 2L, 3L), stale.songs.map { it.id })+ }+}