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 a10cae728..ec0e2551a 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 @@ -50,33 +50,10 @@ class PlayingQueueSheet : ExpandedBottomSheet() { val currentPlayingIndex = PlayingQueue.currentIndex() if (currentPlayingIndex != -1) binding.optionsRecycler.scrollToPosition(currentPlayingIndex) - binding.shuffle.setOnClickListener { - val streams = PlayingQueue.getStreams().toMutableList() - val currentIndex = PlayingQueue.currentIndex() - - // save all streams that need to be shuffled to a copy of the list - val toShuffle = streams.filterIndexed { index, _ -> - index > currentIndex - } - - // re-add all streams in the new, shuffled order after removing them - streams.removeAll(toShuffle) - streams.addAll(toShuffle.shuffled()) - - PlayingQueue.setStreams(streams) - - adapter.notifyDataSetChanged() - } - binding.addToPlaylist.setOnClickListener { AddToPlaylistDialog().show(childFragmentManager, null) } - binding.reverse.setOnClickListener { - PlayingQueue.setStreams(PlayingQueue.getStreams().reversed()) - adapter.notifyDataSetChanged() - } - binding.repeat.setOnClickListener { // select the next available repeat mode PlayingQueue.repeatMode = when (PlayingQueue.repeatMode) { @@ -152,7 +129,9 @@ class PlayingQueueSheet : ExpandedBottomSheet() { val sortOptions = listOf( R.string.creation_date, R.string.most_views, - R.string.uploader_name + R.string.uploader_name, + R.string.shuffle, + R.string.tooltip_reverse ) .map { requireContext().getString(it) } .toTypedArray() @@ -163,6 +142,21 @@ class PlayingQueueSheet : ExpandedBottomSheet() { 0 -> PlayingQueue.getStreams().sortedBy { it.uploaded } 1 -> PlayingQueue.getStreams().sortedBy { it.views }.reversed() 2 -> PlayingQueue.getStreams().sortedBy { it.uploaderName } + 3 -> { + val streams = PlayingQueue.getStreams() + val currentIndex = PlayingQueue.currentIndex() + + // save all streams that need to be shuffled to a copy of the list + val toShuffle = streams.filterIndexed { queueIndex, _ -> + queueIndex > currentIndex + } + + // create a new list by replacing the old queue-end with the new, shuffled one + streams + .filter { it !in toShuffle } + .plus(toShuffle.shuffled()) + } + 4 -> PlayingQueue.getStreams().reversed() else -> throw IllegalArgumentException() } PlayingQueue.setStreams(newQueue) diff --git a/app/src/main/res/drawable/ic_reverse.xml b/app/src/main/res/drawable/ic_reverse.xml deleted file mode 100644 index 1daf24465..000000000 --- a/app/src/main/res/drawable/ic_reverse.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/layout/queue_bottom_sheet.xml b/app/src/main/res/layout/queue_bottom_sheet.xml index 953f06909..e84d6d62c 100644 --- a/app/src/main/res/layout/queue_bottom_sheet.xml +++ b/app/src/main/res/layout/queue_bottom_sheet.xml @@ -43,18 +43,6 @@ style="@style/QueueSheetOption" android:src="@drawable/ic_repeat" /> - - - -