mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
feat: controls to order queue by date, uploader or views
This commit is contained in:
parent
c83a8ee1b7
commit
05538f9155
@ -8,10 +8,13 @@ import android.view.ViewGroup
|
|||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.QueueBottomSheetBinding
|
import com.github.libretube.databinding.QueueBottomSheetBinding
|
||||||
import com.github.libretube.ui.adapters.PlayingQueueAdapter
|
import com.github.libretube.ui.adapters.PlayingQueueAdapter
|
||||||
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
||||||
import com.github.libretube.util.PlayingQueue
|
import com.github.libretube.util.PlayingQueue
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import java.lang.IllegalArgumentException
|
||||||
|
|
||||||
class PlayingQueueSheet : ExpandedBottomSheet() {
|
class PlayingQueueSheet : ExpandedBottomSheet() {
|
||||||
private lateinit var binding: QueueBottomSheetBinding
|
private lateinit var binding: QueueBottomSheetBinding
|
||||||
@ -76,6 +79,9 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
|||||||
.filterIndexed { index, _ -> index == currentIndex })
|
.filterIndexed { index, _ -> index == currentIndex })
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
binding.sort.setOnClickListener {
|
||||||
|
showSortDialog()
|
||||||
|
}
|
||||||
|
|
||||||
binding.bottomControls.setOnClickListener {
|
binding.bottomControls.setOnClickListener {
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
@ -113,4 +119,24 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
|||||||
val itemTouchHelper = ItemTouchHelper(callback)
|
val itemTouchHelper = ItemTouchHelper(callback)
|
||||||
itemTouchHelper.attachToRecyclerView(binding.optionsRecycler)
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,15 @@
|
|||||||
android:background="@drawable/rounded_ripple"
|
android:background="@drawable/rounded_ripple"
|
||||||
android:padding="10dp">
|
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
|
<ImageView
|
||||||
android:id="@+id/shuffle"
|
android:id="@+id/shuffle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -55,15 +64,6 @@
|
|||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:src="@drawable/ic_reverse" />
|
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
|
<ImageView
|
||||||
android:id="@+id/add_to_playlist"
|
android:id="@+id/add_to_playlist"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -73,6 +73,15 @@
|
|||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:src="@drawable/ic_playlist_add" />
|
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
|
<ImageView
|
||||||
android:id="@+id/clear_queue"
|
android:id="@+id/clear_queue"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -436,6 +436,8 @@
|
|||||||
<string name="visibility">Visibility</string>
|
<string name="visibility">Visibility</string>
|
||||||
<string name="visibility_public">Public</string>
|
<string name="visibility_public">Public</string>
|
||||||
<string name="visibility_unlisted">Unlisted</string>
|
<string name="visibility_unlisted">Unlisted</string>
|
||||||
|
<string name="sort_by">Sort by</string>
|
||||||
|
<string name="uploader_name">Uploader name</string>
|
||||||
|
|
||||||
<!-- Backup & Restore Settings -->
|
<!-- Backup & Restore Settings -->
|
||||||
<string name="import_subscriptions_from">Import subscriptions from</string>
|
<string name="import_subscriptions_from">Import subscriptions from</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user