mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Merge pull request #2582 from Bnyro/master
Improve the queue shuffle behavior
This commit is contained in:
commit
645e3e2bf0
@ -33,13 +33,18 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
|||||||
binding.optionsRecycler.adapter = adapter
|
binding.optionsRecycler.adapter = adapter
|
||||||
|
|
||||||
binding.shuffle.setOnClickListener {
|
binding.shuffle.setOnClickListener {
|
||||||
var streams = PlayingQueue.getStreams()
|
val streams = PlayingQueue.getStreams().toMutableList()
|
||||||
val currentIndex = PlayingQueue.currentIndex()
|
val currentIndex = PlayingQueue.currentIndex()
|
||||||
val current = streams[currentIndex]
|
|
||||||
|
|
||||||
streams = streams.shuffled().toMutableList()
|
// save all streams that need to be shuffled to a copy of the list
|
||||||
streams.remove(current)
|
val toShuffle = streams.filterIndexed { index, _ ->
|
||||||
streams.add(currentIndex, current)
|
index > currentIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-add all streams in the new, shuffled order after removing them
|
||||||
|
streams.removeAll(toShuffle)
|
||||||
|
streams.addAll(toShuffle.shuffled())
|
||||||
|
|
||||||
PlayingQueue.setStreams(streams)
|
PlayingQueue.setStreams(streams)
|
||||||
|
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
|
@ -79,7 +79,8 @@ object PlayingQueue {
|
|||||||
|
|
||||||
fun contains(streamItem: StreamItem) = queue.any { it.url?.toID() == streamItem.url?.toID() }
|
fun contains(streamItem: StreamItem) = queue.any { it.url?.toID() == streamItem.url?.toID() }
|
||||||
|
|
||||||
fun getStreams() = queue
|
// only returns a copy of the queue, no write access
|
||||||
|
fun getStreams() = queue.toList()
|
||||||
|
|
||||||
fun setStreams(streams: List<StreamItem>) {
|
fun setStreams(streams: List<StreamItem>) {
|
||||||
queue.clear()
|
queue.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user