From 12adebd4bf1cb8250f4b90f63e34dffca14ea858 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 17 Nov 2022 16:25:34 +0100 Subject: [PATCH 1/2] add a reverse queue button --- .../libretube/ui/sheets/PlayingQueueSheet.kt | 8 ++++++-- app/src/main/res/drawable/ic_reverse.xml | 10 ++++++++++ .../main/res/layout/queue_bottom_sheet.xml | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_reverse.xml diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt index 886ddf591..9982f5216 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt @@ -48,8 +48,7 @@ class PlayingQueueSheet : ExpandedBottomSheet() { binding.clear.setOnClickListener { val currentIndex = PlayingQueue.currentIndex() - val streams = PlayingQueue.getStreams().filterIndexed { - position, _ -> + val streams = PlayingQueue.getStreams().filterIndexed { position, _ -> position <= currentIndex } @@ -57,6 +56,11 @@ class PlayingQueueSheet : ExpandedBottomSheet() { adapter.notifyDataSetChanged() } + binding.reverse.setOnClickListener { + PlayingQueue.setStreams(PlayingQueue.getStreams().reversed()) + adapter.notifyDataSetChanged() + } + binding.bottomControls.setOnClickListener { dialog?.dismiss() } diff --git a/app/src/main/res/drawable/ic_reverse.xml b/app/src/main/res/drawable/ic_reverse.xml new file mode 100644 index 000000000..1daf24465 --- /dev/null +++ b/app/src/main/res/drawable/ic_reverse.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/queue_bottom_sheet.xml b/app/src/main/res/layout/queue_bottom_sheet.xml index e5671da4c..9d7c17904 100644 --- a/app/src/main/res/layout/queue_bottom_sheet.xml +++ b/app/src/main/res/layout/queue_bottom_sheet.xml @@ -41,10 +41,20 @@ android:id="@+id/shuffle" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginHorizontal="5dp" android:background="?attr/selectableItemBackgroundBorderless" android:padding="5dp" android:src="@drawable/ic_shuffle" /> + + + + From bbdeeea03b77ead731b4bae0c7d2c04bee29ba3e Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 17 Nov 2022 16:45:07 +0100 Subject: [PATCH 2/2] add repeat queue btn --- .../libretube/ui/fragments/PlayerFragment.kt | 2 +- .../libretube/ui/sheets/PlayingQueueSheet.kt | 7 ++++++ .../libretube/ui/views/CustomExoPlayerView.kt | 23 ++++++++++++------- .../com/github/libretube/util/PlayingQueue.kt | 12 ++++++---- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index f9b14fbce..fe2f78e92 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -501,7 +501,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { try { // clear the playing queue PlayingQueue.clear() - PlayingQueue.removeOnQueueTapListener() + PlayingQueue.resetToDefaults() saveWatchPosition() nowPlayingNotification.destroySelfAndPlayer() diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt index 9982f5216..8a5e024fd 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt @@ -61,6 +61,13 @@ class PlayingQueueSheet : ExpandedBottomSheet() { adapter.notifyDataSetChanged() } + binding.repeat.setOnClickListener { + PlayingQueue.repeatQueue = !PlayingQueue.repeatQueue + it.alpha = if (PlayingQueue.repeatQueue) 1f else 0.5f + } + + binding.repeat.alpha = if (PlayingQueue.repeatQueue) 1f else 0.5f + binding.bottomControls.setOnClickListener { dialog?.dismiss() } diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 31f05388d..7bc063714 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -22,7 +22,9 @@ import com.github.libretube.ui.interfaces.PlayerOptions import com.github.libretube.ui.sheets.BaseBottomSheet import com.github.libretube.ui.sheets.PlaybackSpeedSheet import com.github.libretube.util.PlayerHelper +import com.github.libretube.util.PlayingQueue import com.google.android.exoplayer2.PlaybackParameters +import com.google.android.exoplayer2.Player import com.google.android.exoplayer2.trackselection.TrackSelector import com.google.android.exoplayer2.ui.AspectRatioFrameLayout import com.google.android.exoplayer2.ui.StyledPlayerView @@ -373,18 +375,23 @@ internal class CustomExoPlayerView( override fun onRepeatModeClicked() { val repeatModeNames = listOf( context.getString(R.string.repeat_mode_none), - context.getString(R.string.repeat_mode_current) - ) - - val repeatModes = listOf( - RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE, - RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL - + context.getString(R.string.repeat_mode_current), + context.getString(R.string.all) ) // repeat mode options dialog BaseBottomSheet() .setSimpleItems(repeatModeNames) { index -> - player?.repeatMode = repeatModes[index] + PlayingQueue.repeatQueue = when (index) { + 0 -> { + player?.repeatMode = Player.REPEAT_MODE_OFF + false + } + 1 -> { + player?.repeatMode = Player.REPEAT_MODE_ONE + false + } + else -> true + } } .show(supportFragmentManager) } diff --git a/app/src/main/java/com/github/libretube/util/PlayingQueue.kt b/app/src/main/java/com/github/libretube/util/PlayingQueue.kt index 28c502e60..27dfe7b7b 100644 --- a/app/src/main/java/com/github/libretube/util/PlayingQueue.kt +++ b/app/src/main/java/com/github/libretube/util/PlayingQueue.kt @@ -13,6 +13,7 @@ object PlayingQueue { private val queue = mutableListOf() private var currentStream: StreamItem? = null private var onQueueTapListener: (StreamItem) -> Unit = {} + var repeatQueue: Boolean = false fun add(vararg streamItem: StreamItem) { streamItem.forEach { @@ -33,11 +34,13 @@ object PlayingQueue { } fun getNext(): String? { - return try { - queue[currentIndex() + 1].url?.toID() + try { + return queue[currentIndex() + 1].url?.toID() } catch (e: Exception) { - null + Log.e("queue ended", e.toString()) } + if (repeatQueue) return queue.firstOrNull()?.url?.toID() + return null } fun getPrev(): String? { @@ -133,7 +136,8 @@ object PlayingQueue { onQueueTapListener = listener } - fun removeOnQueueTapListener() { + fun resetToDefaults() { + repeatQueue = false onQueueTapListener = {} } }