From 943464b86e9a612523a4669ba548c28290b74d0d Mon Sep 17 00:00:00 2001 From: AE <98699388+A-EDev@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:57:49 +0200 Subject: [PATCH 1/9] feat(player): repeat off, all or one from the queue sheet --- .../github/aedev/flow/player/VideoRepeat.kt | 20 +++++++++ .../aedev/flow/player/VideoSessionButtons.kt | 42 ++++--------------- .../sheet/FlowPlaylistQueueBottomSheet.kt | 22 +++++++--- .../player/dialogs/PlayerSheetHosts.kt | 9 +++- app/src/main/res/values/strings.xml | 3 ++ .../aedev/flow/player/VideoRepeatTest.kt | 29 +++++++++++++ .../flow/player/VideoSessionControlsTest.kt | 9 ++-- 7 files changed, 88 insertions(+), 46 deletions(-) create mode 100644 app/src/main/java/io/github/aedev/flow/player/VideoRepeat.kt create mode 100644 app/src/test/java/io/github/aedev/flow/player/VideoRepeatTest.kt diff --git a/app/src/main/java/io/github/aedev/flow/player/VideoRepeat.kt b/app/src/main/java/io/github/aedev/flow/player/VideoRepeat.kt new file mode 100644 index 0000000000..12ab97744b --- /dev/null +++ b/app/src/main/java/io/github/aedev/flow/player/VideoRepeat.kt @@ -0,0 +1,20 @@ +package io.github.aedev.flow.player + +/** Off, then the whole queue, then the current item, then off again. */ +fun RepeatMode.next(): RepeatMode = + when (this) { + RepeatMode.OFF -> RepeatMode.ALL + RepeatMode.ALL -> RepeatMode.ONE + RepeatMode.ONE -> RepeatMode.OFF + } + +/** The video player's queue loop and video loop read as one mode; looping the video wins. */ +fun videoRepeatMode( + queueLoop: Boolean, + videoLoop: Boolean, +): RepeatMode = + when { + videoLoop -> RepeatMode.ONE + queueLoop -> RepeatMode.ALL + else -> RepeatMode.OFF + } diff --git a/app/src/main/java/io/github/aedev/flow/player/VideoSessionButtons.kt b/app/src/main/java/io/github/aedev/flow/player/VideoSessionButtons.kt index 9e03e58bb3..1546641b8e 100644 --- a/app/src/main/java/io/github/aedev/flow/player/VideoSessionButtons.kt +++ b/app/src/main/java/io/github/aedev/flow/player/VideoSessionButtons.kt @@ -14,8 +14,6 @@ import io.github.aedev.flow.R /** What the video notification's repeat and shuffle buttons show and do. */ internal object VideoSessionControls { - enum class Repeat { OFF, QUEUE, ONE } - data class State( val videoLooping: Boolean, val queueLooping: Boolean, @@ -24,13 +22,8 @@ internal object VideoSessionControls { ) { val hasQueue: Boolean get() = queueSize > 1 - val repeat: Repeat - get() = - when { - videoLooping -> Repeat.ONE - queueLooping && hasQueue -> Repeat.QUEUE - else -> Repeat.OFF - } + val repeat: RepeatMode + get() = videoRepeatMode(queueLoop = queueLooping && hasQueue, videoLoop = videoLooping) } data class LoopTarget( @@ -39,27 +32,10 @@ internal object VideoSessionControls { ) /** Off, then the whole queue, then this video; a single video goes straight to looping itself. */ - fun nextLoop(state: State): LoopTarget = - when (state.repeat) { - Repeat.OFF -> { - if (state.hasQueue) { - LoopTarget( - videoLoop = false, - queueLoop = true, - ) - } else { - LoopTarget(videoLoop = true, queueLoop = false) - } - } - - Repeat.QUEUE -> { - LoopTarget(videoLoop = true, queueLoop = false) - } - - Repeat.ONE -> { - LoopTarget(videoLoop = false, queueLoop = false) - } - } + fun nextLoop(state: State): LoopTarget { + val next = state.repeat.next().let { if (it == RepeatMode.ALL && !state.hasQueue) RepeatMode.ONE else it } + return LoopTarget(videoLoop = next == RepeatMode.ONE, queueLoop = next == RepeatMode.ALL) + } } /** @@ -112,9 +88,9 @@ internal class VideoSessionButtons( fun buttons(state: VideoSessionControls.State): List { val (repeatIcon, repeatIconRes) = when (state.repeat) { - VideoSessionControls.Repeat.ONE -> CommandButton.ICON_REPEAT_ONE to R.drawable.ic_repeat_one_on - VideoSessionControls.Repeat.QUEUE -> CommandButton.ICON_REPEAT_ALL to R.drawable.ic_repeat_on - VideoSessionControls.Repeat.OFF -> CommandButton.ICON_REPEAT_OFF to R.drawable.ic_repeat + RepeatMode.ONE -> CommandButton.ICON_REPEAT_ONE to R.drawable.ic_repeat_one_on + RepeatMode.ALL -> CommandButton.ICON_REPEAT_ALL to R.drawable.ic_repeat_on + RepeatMode.OFF -> CommandButton.ICON_REPEAT_OFF to R.drawable.ic_repeat } val repeat = CommandButton diff --git a/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/sheet/FlowPlaylistQueueBottomSheet.kt b/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/sheet/FlowPlaylistQueueBottomSheet.kt index 845a1061a9..66d9d4196e 100644 --- a/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/sheet/FlowPlaylistQueueBottomSheet.kt +++ b/app/src/main/java/io/github/aedev/flow/ui/components/videoplayer/sheet/FlowPlaylistQueueBottomSheet.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.Repeat +import androidx.compose.material.icons.rounded.RepeatOne import androidx.compose.material.icons.rounded.Shuffle import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi import androidx.compose.material3.FilledTonalIconToggleButton @@ -31,6 +32,8 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import io.github.aedev.flow.R import io.github.aedev.flow.data.model.Video +import io.github.aedev.flow.player.RepeatMode +import io.github.aedev.flow.player.next import io.github.aedev.flow.ui.components.shared.FlowBottomSheet import io.github.aedev.flow.ui.components.shared.FlowSheetHeader import io.github.aedev.flow.ui.components.shared.defaultSheetExpandedHeight @@ -51,9 +54,9 @@ fun FlowPlaylistQueueBottomSheet( queueVideos: List