Modern Apps git

← Modern-Apps.git

music: stop forcing repeat-all and unify the repeat cycle

Commit
52b162e40b5de918a6d881a273e774dd15cdac31
Author
Vayun Mathur <[email protected]>
When
2026-11-07 20:13 UTC (29 days ago)
Parents
05b6fca
Symptom: choosing repeat off or repeat-one on the now-playing screen
was silently undone the next time any song, album or playlist was
tapped, because starting a queue forced REPEAT_MODE_ALL. The same
repeat button also cycled in different orders on different surfaces:
the app went off -> one -> all while the notification went
off -> all -> one, so a press meant different things by surface.

Root cause: PlaybackManager.playSongsInternal set repeatMode on every
new queue, and toggleRepeat and PlaybackService's ACTION_REPEAT each
carried their own copy of the cycle. RepeatShuffleTest re-implemented
the app cycle locally, so it kept passing while the surfaces disagreed.

Fix: remove the forced REPEAT_MODE_ALL (shuffle is still set, because
play vs shuffle-play is the explicit action the user pressed), add one
production nextRepeatMode (off -> all -> one -> off, unknown -> off),
use it from both surfaces, and pin RepeatShuffleTest against the
production function instead of a local copy.

Verification: covered by the updated RepeatShuffleTest; full module
verification run after all fixes in this series.

Diff

music/src/main/java/com/vayunmathur/music/platform/PlaybackManager.kt
diff --git a/music/src/main/java/com/vayunmathur/music/platform/PlaybackManager.kt b/music/src/main/java/com/vayunmathur/music/platform/PlaybackManager.ktindex 5a7e453414..2381459552 100644--- a/music/src/main/java/com/vayunmathur/music/platform/PlaybackManager.kt+++ b/music/src/main/java/com/vayunmathur/music/platform/PlaybackManager.kt@@ -56,6 +56,18 @@ sealed interface PlaybackSource {     } } +/**+ * The one repeat cycle, shared by the app transport and the notification+ * buttons in `PlaybackService`: off -> all -> one -> off. Unknown modes fall+ * back to off. The two surfaces previously cycled in different orders, so the+ * same press meant different things depending on where it was pressed.+ */+fun nextRepeatMode(mode: Int): Int = when (mode) {+    Player.REPEAT_MODE_OFF -> Player.REPEAT_MODE_ALL+    Player.REPEAT_MODE_ALL -> Player.REPEAT_MODE_ONE+    else -> Player.REPEAT_MODE_OFF+}+ class PlaybackManager private constructor(context: Context) {      private var controller: MediaController? = null@@ -188,7 +200,9 @@ class PlaybackManager private constructor(context: Context) {         if (songs.isEmpty() || startWithIndex !in songs.indices) return         val player = controller ?: return -        player.repeatMode = Player.REPEAT_MODE_ALL+        // Repeat is the user's setting, not a property of the new queue:+        // forcing it here silently undid an explicit off/one chosen on the+        // now-playing screen every time another song or album was tapped.         player.shuffleModeEnabled = shuffle          val mediaItems = songs.map { song ->@@ -225,13 +239,7 @@ class PlaybackManager private constructor(context: Context) {     }      fun toggleRepeat() {-        controller?.let {-            it.repeatMode = when (it.repeatMode) {-                Player.REPEAT_MODE_OFF -> Player.REPEAT_MODE_ONE-                Player.REPEAT_MODE_ONE -> Player.REPEAT_MODE_ALL-                else -> Player.REPEAT_MODE_OFF-            }-        }+        controller?.let { it.repeatMode = nextRepeatMode(it.repeatMode) }     }      companion object {
music/src/main/java/com/vayunmathur/music/service/PlaybackService.kt
diff --git a/music/src/main/java/com/vayunmathur/music/service/PlaybackService.kt b/music/src/main/java/com/vayunmathur/music/service/PlaybackService.ktindex bbc7fa9a88..a701edd375 100644--- a/music/src/main/java/com/vayunmathur/music/service/PlaybackService.kt+++ b/music/src/main/java/com/vayunmathur/music/service/PlaybackService.kt@@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture import com.vayunmathur.music.MainActivity+import com.vayunmathur.music.platform.nextRepeatMode  /**  * Playback + media-browse service.@@ -155,12 +156,7 @@ class PlaybackService : MediaLibraryService() {                     updateNotificationButtons() // Redraw notification with new icon                 }                 ACTION_REPEAT -> {-                    val nextMode = when (session.player.repeatMode) {-                        Player.REPEAT_MODE_OFF -> Player.REPEAT_MODE_ALL-                        Player.REPEAT_MODE_ALL -> Player.REPEAT_MODE_ONE-                        else -> Player.REPEAT_MODE_OFF-                    }-                    session.player.repeatMode = nextMode+                    session.player.repeatMode = nextRepeatMode(session.player.repeatMode)                     updateNotificationButtons() // Redraw notification with new icon                 }             }
music/src/test/java/com/vayunmathur/music/platform/RepeatShuffleTest.kt
diff --git a/music/src/test/java/com/vayunmathur/music/platform/RepeatShuffleTest.kt b/music/src/test/java/com/vayunmathur/music/platform/RepeatShuffleTest.ktindex 80a2bd574e..25ce8ff7ab 100644--- a/music/src/test/java/com/vayunmathur/music/platform/RepeatShuffleTest.kt+++ b/music/src/test/java/com/vayunmathur/music/platform/RepeatShuffleTest.kt@@ -8,25 +8,21 @@ import kotlin.test.assertTrue /**  * Pins the repeat and shuffle transitions behind the transport buttons.  *- * The buttons drive a service controller, so what is pinned here is the- * transition each press applies: repeat cycles off, one, all and wraps,- * while shuffle flips independently of it.+ * Repeat is pinned against the production [nextRepeatMode] (this test+ * previously re-implemented the cycle locally, so it kept passing while the+ * app and notification surfaces cycled in different orders): repeat cycles+ * off, all, one and wraps, while shuffle flips independently of it.+ * Player constants: OFF=0, ONE=1, ALL=2.  */ class RepeatShuffleTest { -    private fun nextRepeatMode(mode: Int): Int = when (mode) {-        0 -> 1-        1 -> 2-        else -> 0-    }-     private fun toggleShuffle(enabled: Boolean): Boolean = !enabled      @Test-    fun repeatCyclesOffOneAllThenWraps() {-        assertEquals(1, nextRepeatMode(0))-        assertEquals(2, nextRepeatMode(1))-        assertEquals(0, nextRepeatMode(2))+    fun repeatCyclesOffAllOneThenWraps() {+        assertEquals(2, nextRepeatMode(0))+        assertEquals(1, nextRepeatMode(2))+        assertEquals(0, nextRepeatMode(1))     }      @Test@@ -56,7 +52,7 @@ class RepeatShuffleTest {         var mode = 0         repeat(4) { mode = nextRepeatMode(mode) }         assertTrue(shuffle)-        assertEquals(1, mode)+        assertEquals(2, mode)     }      @Test