mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
fix shuffle and clear
This commit is contained in:
parent
c5fb672d44
commit
38d286bb94
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user