fix shuffle and clear

This commit is contained in:
Bnyro 2022-10-28 23:04:44 +02:00
parent c5fb672d44
commit 38d286bb94
3 changed files with 28 additions and 7 deletions

View File

@ -1,5 +1,6 @@
package com.github.libretube.ui.sheets
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -24,6 +25,7 @@ class PlayingQueueSheet : BottomSheetDialogFragment() {
return binding.root
}
@SuppressLint("NotifyDataSetChanged")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -33,17 +35,27 @@ class PlayingQueueSheet : BottomSheetDialogFragment() {
binding.shuffle.setOnClickListener {
val streams = PlayingQueue.getStreams()
val size = PlayingQueue.size()
streams.subList(PlayingQueue.currentIndex(), size).shuffle()
adapter.notifyItemRangeChanged(0, size)
val currentIndex = PlayingQueue.currentIndex()
val current = streams[currentIndex]
streams.shuffle()
streams.remove(current)
streams.add(currentIndex, current)
PlayingQueue.setStreams(streams)
adapter.notifyDataSetChanged()
}
binding.clear.setOnClickListener {
val streams = PlayingQueue.getStreams()
val currentIndex = PlayingQueue.currentIndex()
val size = PlayingQueue.size()
streams.subList(currentIndex, size).clear()
adapter.notifyItemRangeRemoved(currentIndex + 1, size)
val index = PlayingQueue.currentIndex()
while (index >= PlayingQueue.size()) {
streams.removeAt(index)
}
PlayingQueue.setStreams(streams)
adapter.notifyDataSetChanged()
}
binding.bottomControls.setOnClickListener {

View File

@ -74,6 +74,11 @@ object PlayingQueue {
fun getStreams() = queue
fun setStreams(streams: List<StreamItem>) {
queue.clear()
queue.addAll(streams)
}
fun remove(index: Int) = queue.removeAt(index)
fun move(from: Int, to: Int) = queue.move(from, to)

View File

@ -33,6 +33,7 @@
android:id="@+id/bottom_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/rounded_ripple"
android:padding="10dp">
@ -41,11 +42,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="5dp"
android:src="@drawable/ic_shuffle" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="10dp"
android:layout_weight="1"
android:rotation="180"
@ -56,6 +59,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="5dp"
android:src="@drawable/ic_close" />
</LinearLayout>