mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Improve the queue shuffle behavior
This commit is contained in:
parent
c3182edc73
commit
c5a543bdf0
@ -33,13 +33,18 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
||||
binding.optionsRecycler.adapter = adapter
|
||||
|
||||
binding.shuffle.setOnClickListener {
|
||||
var streams = PlayingQueue.getStreams()
|
||||
val streams = PlayingQueue.getStreams().toMutableList()
|
||||
val currentIndex = PlayingQueue.currentIndex()
|
||||
val current = streams[currentIndex]
|
||||
|
||||
streams = streams.shuffled().toMutableList()
|
||||
streams.remove(current)
|
||||
streams.add(currentIndex, current)
|
||||
// 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()
|
||||
|
@ -79,7 +79,8 @@ object PlayingQueue {
|
||||
|
||||
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>) {
|
||||
queue.clear()
|
||||
|
Loading…
x
Reference in New Issue
Block a user