mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
refactor: move shuffle queue button to sort dialog
This commit is contained in:
parent
c49eef5faf
commit
fc64e6b0ad
@ -50,24 +50,6 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
|||||||
val currentPlayingIndex = PlayingQueue.currentIndex()
|
val currentPlayingIndex = PlayingQueue.currentIndex()
|
||||||
if (currentPlayingIndex != -1) binding.optionsRecycler.scrollToPosition(currentPlayingIndex)
|
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 {
|
binding.addToPlaylist.setOnClickListener {
|
||||||
AddToPlaylistDialog().show(childFragmentManager, null)
|
AddToPlaylistDialog().show(childFragmentManager, null)
|
||||||
}
|
}
|
||||||
@ -152,7 +134,8 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
|||||||
val sortOptions = listOf(
|
val sortOptions = listOf(
|
||||||
R.string.creation_date,
|
R.string.creation_date,
|
||||||
R.string.most_views,
|
R.string.most_views,
|
||||||
R.string.uploader_name
|
R.string.uploader_name,
|
||||||
|
R.string.shuffle
|
||||||
)
|
)
|
||||||
.map { requireContext().getString(it) }
|
.map { requireContext().getString(it) }
|
||||||
.toTypedArray()
|
.toTypedArray()
|
||||||
@ -163,6 +146,20 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
|||||||
0 -> PlayingQueue.getStreams().sortedBy { it.uploaded }
|
0 -> PlayingQueue.getStreams().sortedBy { it.uploaded }
|
||||||
1 -> PlayingQueue.getStreams().sortedBy { it.views }.reversed()
|
1 -> PlayingQueue.getStreams().sortedBy { it.views }.reversed()
|
||||||
2 -> PlayingQueue.getStreams().sortedBy { it.uploaderName }
|
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())
|
||||||
|
}
|
||||||
else -> throw IllegalArgumentException()
|
else -> throw IllegalArgumentException()
|
||||||
}
|
}
|
||||||
PlayingQueue.setStreams(newQueue)
|
PlayingQueue.setStreams(newQueue)
|
||||||
|
@ -43,12 +43,6 @@
|
|||||||
style="@style/QueueSheetOption"
|
style="@style/QueueSheetOption"
|
||||||
android:src="@drawable/ic_repeat" />
|
android:src="@drawable/ic_repeat" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/shuffle"
|
|
||||||
android:tooltipText="@string/shuffle"
|
|
||||||
style="@style/QueueSheetOption"
|
|
||||||
android:src="@drawable/ic_shuffle" />
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/reverse"
|
android:id="@+id/reverse"
|
||||||
android:tooltipText="@string/tooltip_reverse"
|
android:tooltipText="@string/tooltip_reverse"
|
||||||
|
Loading…
Reference in New Issue
Block a user