feat: controls to order queue by date, uploader or views

This commit is contained in:
Bnyro 2023-08-05 10:41:26 +02:00
parent c83a8ee1b7
commit 05538f9155
3 changed files with 46 additions and 9 deletions

View File

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

View File

@ -37,6 +37,15 @@
android:background="@drawable/rounded_ripple"
android:padding="10dp">
<ImageView
android:id="@+id/repeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="5dp"
android:src="@drawable/ic_repeat" />
<ImageView
android:id="@+id/shuffle"
android:layout_width="wrap_content"
@ -55,15 +64,6 @@
android:padding="5dp"
android:src="@drawable/ic_reverse" />
<ImageView
android:id="@+id/repeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="5dp"
android:src="@drawable/ic_repeat" />
<ImageView
android:id="@+id/add_to_playlist"
android:layout_width="wrap_content"
@ -73,6 +73,15 @@
android:padding="5dp"
android:src="@drawable/ic_playlist_add" />
<ImageView
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="5dp"
android:src="@drawable/ic_sort" />
<ImageView
android:id="@+id/clear_queue"
android:layout_width="wrap_content"

View File

@ -436,6 +436,8 @@
<string name="visibility">Visibility</string>
<string name="visibility_public">Public</string>
<string name="visibility_unlisted">Unlisted</string>
<string name="sort_by">Sort by</string>
<string name="uploader_name">Uploader name</string>
<!-- Backup & Restore Settings -->
<string name="import_subscriptions_from">Import subscriptions from</string>