Skip to content

Native Android client for Spotify, built with Jetpack Compose

Repeat one loops the song for good again and repeat once stays as a fourth mode (the button goes off, the queue, the song, the song once, off; the loop with a bare 1 for good and with 1x for once, in Classic, Immersive and the queue sheets), on Spotify songs, extension, downloaded and local songs alike; the Web Player gets its repeat-track for both and the page reporting it keeps once as once; the saved mode keeps all four [skip ci]

kota-zo52bf85b436a9
diff --git a/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt b/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt
index a3fbf175..7ff4ca84 100644
--- a/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt
@@ -239,7 +239,7 @@ object LocalPlayer {
// Another song picked: repeat once was for the song left.
val shown = SongPlayer.nowPlaying.value.uri.substringAfterLast(':')
val picked = list.getOrNull(index.coerceIn(0, list.lastIndex))?.let(::spotifyId).orEmpty()
- if (SongPlayer.repeatMode.value == LocalRepeat.ONE && (picked.isBlank() || picked != shown)) {
+ if (SongPlayer.repeatMode.value == LocalRepeat.ONCE && (picked.isBlank() || picked != shown)) {
log("repeat once: cancelled (another song picked), back to off")
SongPlayer.setRepeatMode(LocalRepeat.OFF)
}
@@ -663,13 +663,13 @@ object LocalPlayer {
private fun item(t: LocalTrack) = MediaItem.Builder().setUri(t.uri).setMediaId(t.id.toString())
.setMediaMetadata(MediaMetadata.Builder().setTitle(t.title).setArtist(t.artist).setAlbumTitle(t.album)
.setArtworkUri(android.net.Uri.parse(app.myspoti.host.android.Covers.large(t.artUri.toString()))).setDurationMs(t.durationMs.takeIf { it > 0 }).build()).build()
- /** SongPlayer.repeatMode as this player has it (0 off, 1 the queue, 2 the song; see LocalRepeat). */
+ /** SongPlayer.repeatMode as this player has it (0 off, 1 the queue, 2 the song for good, 3 the song once; see LocalRepeat). */
private var repeat = LocalRepeat.OFF
fun setRepeatMode(mode: Int) {
repeat = mode
// Repeat once tapped again, or another mode: its replay to come is cancelled.
- if (mode != LocalRepeat.ONE) replaying = null
+ if (mode != LocalRepeat.ONCE) replaying = null
exo?.let { applyRepeat(it); if (active.value) continueIfLast(it) }
}
@@ -685,7 +685,7 @@ object LocalPlayer {
/** Manual moves (next, previous, a pick) cancel repeat once: it was for the song left. */
private fun cancelOnce(why: String) {
- if (repeat != LocalRepeat.ONE) return
+ if (repeat != LocalRepeat.ONCE) return
log("repeat once: cancelled ($why), back to off")
SongPlayer.setRepeatMode(LocalRepeat.OFF)
}
@@ -716,7 +716,7 @@ object LocalPlayer {
}
/**
- * ExoPlayer repeats a queue of several songs itself; a song that follows itself (repeat one, a
+ * ExoPlayer repeats a queue of several songs itself; a song that follows itself (repeat one or once, a
* queue of one song repeated) pauses at its end and is played again by [playAgain].
*/
private fun applyRepeat(p: ExoPlayer) {
@@ -752,7 +752,7 @@ object LocalPlayer {
/** The song at [index] plays again from 0:00, and the Connect mirror's copy plays it anew (a new play, as Spotify's repeat counts one). */
private fun replay(p: ExoPlayer, index: Int, endedAt: Long) {
endFade()
- if (repeat == LocalRepeat.ONE) replaying = tracks.getOrNull(index)
+ if (repeat == LocalRepeat.ONCE) replaying = tracks.getOrNull(index)
p.seekTo(index, 0L)
p.play()
log("repeat: ${current()?.title} plays again from ${p.currentPosition} ms (it ended at $endedAt ms)")
@@ -882,7 +882,7 @@ object LocalPlayer {
val end = LocalRepeat.atEnd(repeat, p.mediaItemCount, replayedNow())
if (end == LocalRepeat.End.ONCE_DONE) onceDone()
when {
- end == LocalRepeat.End.REPLAY -> { if (repeat == LocalRepeat.ONE) replaying = current(); CastPlayback.replay() }
+ end == LocalRepeat.End.REPLAY -> { if (repeat == LocalRepeat.ONCE) replaying = current(); CastPlayback.replay() }
p.hasNextMediaItem() -> {
val before = current()
p.seekToNextMediaItem()
diff --git a/base/app/src/main/java/com/music/spotui/di/LocalRepeat.kt b/base/app/src/main/java/com/music/spotui/di/LocalRepeat.kt
index 9b5055c6..4149e0fa 100644
--- a/base/app/src/main/java/com/music/spotui/di/LocalRepeat.kt
+++ b/base/app/src/main/java/com/music/spotui/di/LocalRepeat.kt
@@ -2,26 +2,34 @@ package com.music.spotui.di
/**
* How [LocalPlayer] repeats, kept pure so it is tested off-device. [mode] is SongPlayer.repeatMode:
- * 0 off, 1 the queue, 2 the song.
+ * 0 off, 1 the queue, 2 the song for good, 3 the song once.
*
* A song that follows itself (repeat one, or a queue of one song repeated) is not left to
* ExoPlayer's own repeat: that plays the song again as a new period of the same item, and with an
* extension's stream it was seen starting again near the last seek instead of at 0:00 (and earlier
* on each loop). The player pauses at the song's end instead and Myspoti puts it back at 0:00.
*
- * Repeat one is "repeat once": the song plays again one time, then the queue goes on and the mode
- * goes back to off ([atEnd]). A queue of one song repeated (repeat all) loops it for good.
+ * Repeat one loops the song for good, as Spotify's repeat-track does. Repeat once plays the song
+ * again one time, then the queue goes on and the mode goes back to off ([atEnd]). A queue of one
+ * song repeated (repeat all) loops it for good.
*/
object LocalRepeat {
const val OFF = 0
const val ALL = 1
const val ONE = 2
+ const val ONCE = 3
/**
* The song pauses at its end for Myspoti to play it again from 0:00 (see the object's note), or,
* after repeat once's replay, to go on to the next song ([atEnd]).
*/
- fun loopsSong(mode: Int, items: Int): Boolean = mode == ONE || mode == ALL && items == 1
+ fun loopsSong(mode: Int, items: Int): Boolean = mode == ONE || mode == ONCE || mode == ALL && items == 1
+
+ /**
+ * The repeat the Web Player is given for [mode]: its repeat-track for both ways of repeating the
+ * song (0 off, 1 the context, 2 the track, as Spotify's Repeat), repeat once being Myspoti's own.
+ */
+ fun pageMode(mode: Int): Int = if (mode >= ONCE) ONE else mode.coerceIn(OFF, ONE)
/** The repeat ExoPlayer is given: its own only for a queue of several songs repeated. */
fun playerMode(mode: Int, items: Int): Int =
@@ -46,8 +54,8 @@ object LocalRepeat {
/** [replayed]: the song ending is the one repeat once already played again. */
fun atEnd(mode: Int, items: Int, replayed: Boolean): End = when {
- mode == ONE -> if (replayed) End.ONCE_DONE else End.REPLAY
- mode == ALL && items == 1 -> End.REPLAY
+ mode == ONCE -> if (replayed) End.ONCE_DONE else End.REPLAY
+ mode == ONE || mode == ALL && items == 1 -> End.REPLAY
else -> End.NEXT
}
diff --git a/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt b/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
index 286ecc91..6171e0aa 100644
--- a/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
@@ -578,7 +578,7 @@ object SongPlayer {
// Repeat once on a Spotify song: the page's repeat-track loops for good. The page seen
// starting the song again is its one replay: repeat goes off there, and that replay ends
// into the next song. Another song under repeat-track (a skip, a pick) cancels it.
- if (item != null && s.repeat == Repeat.TRACK && _repeatMode.value == LocalRepeat.ONE) {
+ if (item != null && s.repeat == Repeat.TRACK && _repeatMode.value == LocalRepeat.ONCE) {
if (LocalRepeat.pageRestarted(!trackChanged, predicted, lengthBefore, reported)) {
app.myspoti.host.android.Logbook.log("repeat once: ${item.name} replayed, back to off")
setRepeatMode(LocalRepeat.OFF)
@@ -627,7 +627,8 @@ object SongPlayer {
val repeatHeld = SystemClock.elapsedRealtime() < repeatWantedUntil
if (repeatHeld && s.repeat.ordinal == repeatWanted) repeatWantedUntil = 0L
if (!LocalPlayer.active.value && (!repeatHeld || s.repeat.ordinal == repeatWanted)) {
- _repeatMode.value = s.repeat.ordinal
+ // Repeat once is the page's repeat-track too: the page reporting it does not turn once into for good.
+ if (!(s.repeat == Repeat.TRACK && _repeatMode.value == LocalRepeat.ONCE)) _repeatMode.value = s.repeat.ordinal
state.repeat.value = s.repeat != Repeat.OFF
}
if (item == null) {
@@ -1672,7 +1673,7 @@ object SongPlayer {
@Volatile private var shuffleWantedUntil = 0L
private const val SHUFFLE_HOLD_MS = 2_500L
- /** 0 = off, 1 = context, 2 = track. */
+ /** 0 = off, 1 = context, 2 = track for good, 3 = track once (see [LocalRepeat]). */
private val _repeatMode = mutableStateOf(0)
val repeatMode: State<Int> get() = _repeatMode
@@ -1682,11 +1683,11 @@ object SongPlayer {
if (LocalPlayer.active.value) { _repeatMode.value = mode; boundState?.repeat?.value = mode != 0; LocalPlayer.setRepeatMode(mode); return }
Haptics.toggle(mode != 0)
_repeatMode.value = mode
- repeatWanted = mode
+ repeatWanted = LocalRepeat.pageMode(mode)
repeatWantedUntil = SystemClock.elapsedRealtime() + SHUFFLE_HOLD_MS
boundState?.repeat?.value = mode != 0
- lastTrackPrefs().edit().putInt("repeat", mode.coerceIn(0, 2)).apply()
- command { api.player.setRepeat(Repeat.entries[mode.coerceIn(0, 2)]) }
+ lastTrackPrefs().edit().putInt("repeat", mode.coerceIn(0, 3)).apply()
+ command { api.player.setRepeat(Repeat.entries[LocalRepeat.pageMode(mode)]) }
}
/**
@@ -1697,17 +1698,18 @@ object SongPlayer {
private fun restoreRepeat(state: CurrentSongState) {
val p = lastTrackPrefs()
if (!p.contains("repeat")) return
- val mode = p.getInt("repeat", 0).coerceIn(0, 2)
+ val mode = p.getInt("repeat", 0).coerceIn(0, 3)
_repeatMode.value = mode
state.repeat.value = mode != 0
- MyspotiRuntime.spotify.player.restoreRepeat(Repeat.entries[mode])
+ MyspotiRuntime.spotify.player.restoreRepeat(Repeat.entries[LocalRepeat.pageMode(mode)])
}
- fun cycleRepeat() = setRepeatMode((_repeatMode.value + 1) % 3)
+ /** Off, the queue, the song for good, the song once, off. */
+ fun cycleRepeat() = setRepeatMode((_repeatMode.value + 1) % 4)
/** A manual move on a Spotify song cancels repeat once: it was for the song left. */
private fun cancelRepeatOnce(why: String) {
- if (_repeatMode.value != LocalRepeat.ONE) return
+ if (_repeatMode.value != LocalRepeat.ONCE) return
app.myspoti.host.android.Logbook.log("repeat once: cancelled ($why), back to off")
setRepeatMode(LocalRepeat.OFF)
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/PlayerSheets.kt b/base/app/src/main/java/com/music/spotui/ui/components/PlayerSheets.kt
index 2f3b29f4..f108da93 100644
--- a/base/app/src/main/java/com/music/spotui/ui/components/PlayerSheets.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/components/PlayerSheets.kt
@@ -569,7 +569,7 @@ fun QueueSheet(contextName: String, onDismiss: () -> Unit) {
SongPlayer.setShuffle(!shuffle); state.shuffle.value = !shuffle
}
val mode = SongPlayer.repeatMode.value
- QueueAction(if (mode == 2) Icons.Default.RepeatOne else Icons.Default.Repeat, stringResource(R.string.np_content_desc_repeat), mode != 0, Modifier.weight(1f)) {
+ QueueAction(when (mode) { 2 -> Icons.Default.RepeatOne; 3 -> RepeatIcons.once; else -> Icons.Default.Repeat }, stringResource(R.string.np_content_desc_repeat), mode != 0, Modifier.weight(1f)) {
SongPlayer.cycleRepeat()
}
QueueAction(Icons.Outlined.Timer, stringResource(R.string.np_content_desc_sleep_timer), SongPlayer.sleepEndsAt.value != null, Modifier.weight(1f)) {
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/RepeatIcons.kt b/base/app/src/main/java/com/music/spotui/ui/components/RepeatIcons.kt
new file mode 100644
index 00000000..1d7fa4a3
--- /dev/null
+++ b/base/app/src/main/java/com/music/spotui/ui/components/RepeatIcons.kt
@@ -0,0 +1,43 @@
+package com.music.spotui.ui.components
+
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.graphics.StrokeCap
+import androidx.compose.ui.graphics.StrokeJoin
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.graphics.vector.path
+import androidx.compose.ui.unit.dp
+
+/**
+ * Repeat once: the loop with "1×" inside, next to the loop with a bare "1" that repeats the song
+ * for good (Material's RepeatOne). Drawn with the Classic player's strokes (2 wide, round), which
+ * match Material's repeat closely enough to stand beside it in the Immersive player and the queue.
+ */
+object RepeatIcons {
+ val once: ImageVector = ImageVector.Builder("repeatOnce", 24.dp, 24.dp, 24f, 24f).apply {
+ path(
+ stroke = SolidColor(Color.Black),
+ strokeLineWidth = 2f,
+ strokeLineCap = StrokeCap.Round,
+ strokeLineJoin = StrokeJoin.Round,
+ ) {
+ // Rounded frame open at the lower left, where the arrow head sits.
+ moveTo(3f, 12f); verticalLineTo(9f); arcTo(4f, 4f, 0f, false, true, 7f, 5f)
+ horizontalLineTo(17f); arcTo(4f, 4f, 0f, false, true, 21f, 9f)
+ verticalLineTo(12f); arcTo(4f, 4f, 0f, false, true, 17f, 16f)
+ horizontalLineTo(8f)
+ moveTo(11f, 12.5f); lineTo(7.5f, 16f); lineTo(11f, 19.5f)
+ }
+ path(
+ stroke = SolidColor(Color.Black),
+ strokeLineWidth = 1.6f,
+ strokeLineCap = StrokeCap.Round,
+ strokeLineJoin = StrokeJoin.Round,
+ ) {
+ // The "1", then the "×".
+ moveTo(7.6f, 8.6f); lineTo(9.4f, 7.7f); verticalLineTo(12.6f)
+ moveTo(12.6f, 8.6f); lineTo(16.2f, 12.2f)
+ moveTo(16.2f, 8.6f); lineTo(12.6f, 12.2f)
+ }
+ }.build()
+}
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveQueuePanel.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveQueuePanel.kt
index 57d0bbc4..b71b779a 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveQueuePanel.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveQueuePanel.kt
@@ -96,6 +96,7 @@ import com.bumptech.glide.integration.compose.GlideImage
import com.music.spotui.data.entity.SongsModel
import com.music.spotui.di.Graph
import com.music.spotui.di.SongPlayer
+import com.music.spotui.ui.components.RepeatIcons
import com.music.spotui.ui.immersive.Immersive
import com.music.spotui.ui.screens.ExplicitBadge
@@ -531,7 +532,7 @@ private fun QueueHeader(
QueueToggle(Icons.Rounded.Shuffle, stringResource(R.string.immersive_queue_shuffle), shuffle, onShuffle)
Spacer(Modifier.width(8.dp))
QueueToggle(
- if (repeatMode == 2) Icons.Rounded.RepeatOne else Icons.Rounded.Repeat,
+ when (repeatMode) { 2 -> Icons.Rounded.RepeatOne; 3 -> RepeatIcons.once; else -> Icons.Rounded.Repeat },
stringResource(R.string.immersive_queue_repeat),
repeatMode != 0,
onRepeat,
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerBridge.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerBridge.kt
index 4f635adb..8c766661 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerBridge.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerBridge.kt
@@ -39,6 +39,7 @@ object ImmersiveRepeat {
const val OFF = 0
const val ALL = 1
const val ONE = 2
+ const val ONCE = 3
}
/**
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt
index 050f585c..f4222dc8 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt
@@ -80,6 +80,7 @@ import com.music.spotui.di.Haptics
import com.music.spotui.ui.immersive.Immersive
import com.music.spotui.ui.look.MeshPalette
import com.music.spotui.ui.look.ThinSlider
+import com.music.spotui.ui.components.RepeatIcons
import com.music.spotui.ui.components.rememberFrameClock
import kotlin.math.roundToInt
@@ -531,9 +532,14 @@ internal fun PlayerActionRow(
)
PillDivider()
PillSegment(
- icon = if (repeatMode == ImmersiveRepeat.ONE) Icons.Rounded.RepeatOne else Icons.Rounded.Repeat,
+ icon = when (repeatMode) {
+ ImmersiveRepeat.ONE -> Icons.Rounded.RepeatOne
+ ImmersiveRepeat.ONCE -> RepeatIcons.once
+ else -> Icons.Rounded.Repeat
+ },
contentDescription = when (repeatMode) {
ImmersiveRepeat.ONE -> stringResource(R.string.immersive_player_repeat_one)
+ ImmersiveRepeat.ONCE -> stringResource(R.string.immersive_player_repeat_once)
ImmersiveRepeat.ALL -> stringResource(R.string.immersive_player_repeat_all)
else -> stringResource(R.string.immersive_player_repeat_off)
},
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt
index 1ab3f337..feb41dee 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt
@@ -1418,8 +1418,9 @@ fun PlayerFull(
Color.White
},
// The official loop with one arrow (drawn here: the old drawable was the two-arrow one).
- imageVector = if (SongPlayer.repeatMode.value == 2) PlayerIcons.repeatOne else PlayerIcons.repeat,
- contentDescription = when (SongPlayer.repeatMode.value) { 1 -> stringResource(R.string.repeat_on); 2 -> stringResource(R.string.repeat_one); else -> stringResource(R.string.repeat_off) })
+ // Repeat once has the same loop with "1×" in it.
+ imageVector = when (SongPlayer.repeatMode.value) { 2 -> PlayerIcons.repeatOne; 3 -> com.music.spotui.ui.components.RepeatIcons.once; else -> PlayerIcons.repeat },
+ contentDescription = when (SongPlayer.repeatMode.value) { 1 -> stringResource(R.string.repeat_on); 2 -> stringResource(R.string.repeat_one); 3 -> stringResource(R.string.repeat_once); else -> stringResource(R.string.repeat_off) })
}
}
diff --git a/base/app/src/main/res/values-fr/immersive_player_strings.xml b/base/app/src/main/res/values-fr/immersive_player_strings.xml
index 6a26ed21..5d7893d8 100644
--- a/base/app/src/main/res/values-fr/immersive_player_strings.xml
+++ b/base/app/src/main/res/values-fr/immersive_player_strings.xml
@@ -17,7 +17,8 @@
<string name="immersive_player_shuffle_off">Aléatoire : désactivé</string>
<string name="immersive_player_repeat_off">Répétition : désactivée</string>
<string name="immersive_player_repeat_all">Répétition : tout</string>
- <string name="immersive_player_repeat_one">Répéter une fois</string>
+ <string name="immersive_player_repeat_one">Répétition : un titre</string>
+ <string name="immersive_player_repeat_once">Répéter une fois</string>
<string name="immersive_player_volume_down">Volume moins</string>
<string name="immersive_player_volume_up">Volume plus</string>
<string name="immersive_player_ad">Publicité</string>
diff --git a/base/app/src/main/res/values-fr/myspoti_strings.xml b/base/app/src/main/res/values-fr/myspoti_strings.xml
index b6b7e802..b3af8170 100644
--- a/base/app/src/main/res/values-fr/myspoti_strings.xml
+++ b/base/app/src/main/res/values-fr/myspoti_strings.xml
@@ -10,7 +10,8 @@
<string name="welcome_privacy">Vous vous connectez sur la page officielle de Spotify. Myspoti ne voit jamais votre mot de passe.</string>
<string name="remove_from_liked">Retirer des Titres likés</string>
<string name="repeat_on">Répéter : activé</string>
- <string name="repeat_one">Répéter une fois</string>
+ <string name="repeat_one">Répéter le titre</string>
+ <string name="repeat_once">Répéter une fois</string>
<string name="repeat_off">Répéter : désactivé</string>
<string name="headphones">Écouteurs</string>
<string name="listen_on">Écouter sur</string>
diff --git a/base/app/src/main/res/values/immersive_player_strings.xml b/base/app/src/main/res/values/immersive_player_strings.xml
index d6764a25..219403b6 100644
--- a/base/app/src/main/res/values/immersive_player_strings.xml
+++ b/base/app/src/main/res/values/immersive_player_strings.xml
@@ -17,7 +17,8 @@
<string name="immersive_player_shuffle_off">Shuffle: off</string>
<string name="immersive_player_repeat_off">Repeat: off</string>
<string name="immersive_player_repeat_all">Repeat: all</string>
- <string name="immersive_player_repeat_one">Repeat once</string>
+ <string name="immersive_player_repeat_one">Repeat: one</string>
+ <string name="immersive_player_repeat_once">Repeat once</string>
<string name="immersive_player_volume_down">Volume down</string>
<string name="immersive_player_volume_up">Volume up</string>
<string name="immersive_player_ad">Advertisement</string>
diff --git a/base/app/src/main/res/values/myspoti_strings.xml b/base/app/src/main/res/values/myspoti_strings.xml
index 4abb0782..6633b696 100644
--- a/base/app/src/main/res/values/myspoti_strings.xml
+++ b/base/app/src/main/res/values/myspoti_strings.xml
@@ -10,7 +10,8 @@
<string name="welcome_privacy">You sign in on Spotify\'s own page. Myspoti never sees your password.</string>
<string name="remove_from_liked">Remove from Liked Songs</string>
<string name="repeat_on">Repeat: on</string>
- <string name="repeat_one">Repeat once</string>
+ <string name="repeat_one">Repeat one</string>
+ <string name="repeat_once">Repeat once</string>
<string name="repeat_off">Repeat: off</string>
<string name="headphones">Headphones</string>
<string name="listen_on">Listen on</string>
diff --git a/base/app/src/test/java/com/music/spotui/di/LocalRepeatTest.kt b/base/app/src/test/java/com/music/spotui/di/LocalRepeatTest.kt
index ca1bb131..2a720ed2 100644
--- a/base/app/src/test/java/com/music/spotui/di/LocalRepeatTest.kt
+++ b/base/app/src/test/java/com/music/spotui/di/LocalRepeatTest.kt
@@ -15,6 +15,23 @@ class LocalRepeatTest {
assertEquals(Player.REPEAT_MODE_OFF, LocalRepeat.playerMode(LocalRepeat.ONE, 1))
}
+ @Test fun repeatOnceLoopsTheSongItselfToo() {
+ assertTrue(LocalRepeat.loopsSong(LocalRepeat.ONCE, 50))
+ assertTrue(LocalRepeat.loopsSong(LocalRepeat.ONCE, 1))
+ assertEquals(Player.REPEAT_MODE_OFF, LocalRepeat.playerMode(LocalRepeat.ONCE, 50))
+ assertEquals(Player.REPEAT_MODE_OFF, LocalRepeat.playerMode(LocalRepeat.ONCE, 1))
+ }
+
+ @Test fun theWebPlayerRepeatsTheTrackForBothWaysOfRepeatingTheSong() {
+ assertEquals(0, LocalRepeat.pageMode(LocalRepeat.OFF))
+ assertEquals(1, LocalRepeat.pageMode(LocalRepeat.ALL))
+ assertEquals(2, LocalRepeat.pageMode(LocalRepeat.ONE))
+ assertEquals(2, LocalRepeat.pageMode(LocalRepeat.ONCE))
+ // The mode is Spotify's Repeat ordinal for the first three.
+ assertEquals(app.myspoti.api.Repeat.TRACK.ordinal, LocalRepeat.pageMode(LocalRepeat.ONCE))
+ assertEquals(0, LocalRepeat.pageMode(-1))
+ }
+
@Test fun repeatAllOfSeveralSongsIsThePlayersOwn() {
assertFalse(LocalRepeat.loopsSong(LocalRepeat.ALL, 2))
assertEquals(Player.REPEAT_MODE_ALL, LocalRepeat.playerMode(LocalRepeat.ALL, 50))
@@ -41,13 +58,26 @@ class LocalRepeatTest {
// ── Repeat once ──
@Test fun repeatOncePlaysTheSongAgainOneTimeThenGoesOn() {
- assertEquals(LocalRepeat.End.REPLAY, LocalRepeat.atEnd(LocalRepeat.ONE, 50, replayed = false))
- assertEquals(LocalRepeat.End.ONCE_DONE, LocalRepeat.atEnd(LocalRepeat.ONE, 50, replayed = true))
+ assertEquals(LocalRepeat.End.REPLAY, LocalRepeat.atEnd(LocalRepeat.ONCE, 50, replayed = false))
+ assertEquals(LocalRepeat.End.ONCE_DONE, LocalRepeat.atEnd(LocalRepeat.ONCE, 50, replayed = true))
// The only song of the queue too: once, then the queue's end (its song radio).
- assertEquals(LocalRepeat.End.REPLAY, LocalRepeat.atEnd(LocalRepeat.ONE, 1, replayed = false))
- assertEquals(LocalRepeat.End.ONCE_DONE, LocalRepeat.atEnd(LocalRepeat.ONE, 1, replayed = true))
+ assertEquals(LocalRepeat.End.REPLAY, LocalRepeat.atEnd(LocalRepeat.ONCE, 1, replayed = false))
+ assertEquals(LocalRepeat.End.ONCE_DONE, LocalRepeat.atEnd(LocalRepeat.ONCE, 1, replayed = true))
// Repeat once still pauses at the end in both turns: Myspoti decides, never the player.
- assertTrue(LocalRepeat.loopsSong(LocalRepeat.ONE, 50))
+ assertTrue(LocalRepeat.loopsSong(LocalRepeat.ONCE, 50))
+ }
+
+ @Test fun repeatOneReplaysForGood() {
+ for (items in listOf(1, 50)) {
+ assertEquals(LocalRepeat.End.REPLAY, LocalRepeat.atEnd(LocalRepeat.ONE, items, replayed = false))
+ // Whatever was replayed before: it never ends into the next song.
+ assertEquals(LocalRepeat.End.REPLAY, LocalRepeat.atEnd(LocalRepeat.ONE, items, replayed = true))
+ }
+ }
+
+ @Test fun theModesAreTheCycleOfTheButton() {
+ // Off, the queue, the song for good, the song once: Android's REPEAT_MODE_ONE is the third.
+ assertEquals(listOf(0, 1, 2, 3), listOf(LocalRepeat.OFF, LocalRepeat.ALL, LocalRepeat.ONE, LocalRepeat.ONCE))
}
@Test fun repeatAllOfOneSongLoopsForGood() {