Merge pull request #5067 from Bnyro/master

refactor: cleanup queue sort options at the bottom
This commit is contained in:
Bnyro 2023-10-30 12:15:53 +01:00 committed by GitHub
commit 3e1e082ea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 46 deletions

View File

@ -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)

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="m16.25,41.4 l-2.1,-2.1 3.2,-3.3q-5.5,0 -9.425,-3.75Q4,28.5 4,23q0,-5.35 3.725,-9.175Q11.45,10 16.8,10h7.6v3h-7.6q-4.1,0 -6.95,2.925Q7,18.85 7,23q0,4.25 3.125,7.125T17.6,33l-3.3,-3.3 2.1,-2.1 6.8,6.85ZM28.6,36v-3L44,33v3ZM28.6,24.5v-3L44,21.5v3ZM27.4,13v-3L44,10v3Z" />
</vector>

View File

@ -43,18 +43,6 @@
style="@style/QueueSheetOption"
android:src="@drawable/ic_repeat" />
<ImageView
android:id="@+id/shuffle"
android:tooltipText="@string/shuffle"
style="@style/QueueSheetOption"
android:src="@drawable/ic_shuffle" />
<ImageView
android:id="@+id/reverse"
android:tooltipText="@string/tooltip_reverse"
style="@style/QueueSheetOption"
android:src="@drawable/ic_reverse" />
<ImageView
android:id="@+id/add_to_playlist"
android:tooltipText="@string/addToPlaylist"