From 05538f9155c26a5be2c983d9476488ee57d125a3 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 5 Aug 2023 10:41:26 +0200 Subject: [PATCH] feat: controls to order queue by date, uploader or views --- .../libretube/ui/sheets/PlayingQueueSheet.kt | 26 ++++++++++++++++++ .../main/res/layout/queue_bottom_sheet.xml | 27 ++++++++++++------- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 46 insertions(+), 9 deletions(-) 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 75e145266..4f398c5cc 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 @@ -8,10 +8,13 @@ import android.view.ViewGroup import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.R import com.github.libretube.databinding.QueueBottomSheetBinding import com.github.libretube.ui.adapters.PlayingQueueAdapter import com.github.libretube.ui.dialogs.AddToPlaylistDialog import com.github.libretube.util.PlayingQueue +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import java.lang.IllegalArgumentException class PlayingQueueSheet : ExpandedBottomSheet() { private lateinit var binding: QueueBottomSheetBinding @@ -76,6 +79,9 @@ class PlayingQueueSheet : ExpandedBottomSheet() { .filterIndexed { index, _ -> index == currentIndex }) adapter.notifyDataSetChanged() } + binding.sort.setOnClickListener { + showSortDialog() + } binding.bottomControls.setOnClickListener { dialog?.dismiss() @@ -113,4 +119,24 @@ class PlayingQueueSheet : ExpandedBottomSheet() { val itemTouchHelper = ItemTouchHelper(callback) itemTouchHelper.attachToRecyclerView(binding.optionsRecycler) } + + @SuppressLint("NotifyDataSetChanged") + private fun showSortDialog() { + val sortOptions = listOf(R.string.creation_date, R.string.most_views, R.string.uploader_name) + .map { requireContext().getString(it) } + .toTypedArray() + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.sort_by) + .setItems(sortOptions) { _, index -> + val newQueue = when (index) { + 0 -> PlayingQueue.getStreams().sortedBy { it.uploaded } + 1 -> PlayingQueue.getStreams().sortedBy { it.views }.reversed() + 2 -> PlayingQueue.getStreams().sortedBy { it.uploaderName } + else -> throw IllegalArgumentException() + } + PlayingQueue.setStreams(newQueue) + binding.optionsRecycler.adapter?.notifyDataSetChanged() + } + .show() + } } diff --git a/app/src/main/res/layout/queue_bottom_sheet.xml b/app/src/main/res/layout/queue_bottom_sheet.xml index 830779e10..0d55de50f 100644 --- a/app/src/main/res/layout/queue_bottom_sheet.xml +++ b/app/src/main/res/layout/queue_bottom_sheet.xml @@ -37,6 +37,15 @@ android:background="@drawable/rounded_ripple" android:padding="10dp"> + + - - + + Visibility Public Unlisted + Sort by + Uploader name Import subscriptions from