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
|
package com.github.libretube.ui.sheets
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -24,6 +25,7 @@ class PlayingQueueSheet : BottomSheetDialogFragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
@ -33,17 +35,27 @@ class PlayingQueueSheet : BottomSheetDialogFragment() {
|
|||||||
|
|
||||||
binding.shuffle.setOnClickListener {
|
binding.shuffle.setOnClickListener {
|
||||||
val streams = PlayingQueue.getStreams()
|
val streams = PlayingQueue.getStreams()
|
||||||
val size = PlayingQueue.size()
|
val currentIndex = PlayingQueue.currentIndex()
|
||||||
streams.subList(PlayingQueue.currentIndex(), size).shuffle()
|
val current = streams[currentIndex]
|
||||||
adapter.notifyItemRangeChanged(0, size)
|
|
||||||
|
streams.shuffle()
|
||||||
|
streams.remove(current)
|
||||||
|
streams.add(currentIndex, current)
|
||||||
|
PlayingQueue.setStreams(streams)
|
||||||
|
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.clear.setOnClickListener {
|
binding.clear.setOnClickListener {
|
||||||
val streams = PlayingQueue.getStreams()
|
val streams = PlayingQueue.getStreams()
|
||||||
val currentIndex = PlayingQueue.currentIndex()
|
val index = PlayingQueue.currentIndex()
|
||||||
val size = PlayingQueue.size()
|
|
||||||
streams.subList(currentIndex, size).clear()
|
while (index >= PlayingQueue.size()) {
|
||||||
adapter.notifyItemRangeRemoved(currentIndex + 1, size)
|
streams.removeAt(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayingQueue.setStreams(streams)
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.bottomControls.setOnClickListener {
|
binding.bottomControls.setOnClickListener {
|
||||||
|
@ -74,6 +74,11 @@ object PlayingQueue {
|
|||||||
|
|
||||||
fun getStreams() = queue
|
fun getStreams() = queue
|
||||||
|
|
||||||
|
fun setStreams(streams: List<StreamItem>) {
|
||||||
|
queue.clear()
|
||||||
|
queue.addAll(streams)
|
||||||
|
}
|
||||||
|
|
||||||
fun remove(index: Int) = queue.removeAt(index)
|
fun remove(index: Int) = queue.removeAt(index)
|
||||||
|
|
||||||
fun move(from: Int, to: Int) = queue.move(from, to)
|
fun move(from: Int, to: Int) = queue.move(from, to)
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
android:id="@+id/bottom_controls"
|
android:id="@+id/bottom_controls"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="5dp"
|
||||||
android:background="@drawable/rounded_ripple"
|
android:background="@drawable/rounded_ripple"
|
||||||
android:padding="10dp">
|
android:padding="10dp">
|
||||||
|
|
||||||
@ -41,11 +42,13 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:padding="5dp"
|
||||||
android:src="@drawable/ic_shuffle" />
|
android:src="@drawable/ic_shuffle" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:layout_marginHorizontal="10dp"
|
android:layout_marginHorizontal="10dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:rotation="180"
|
android:rotation="180"
|
||||||
@ -56,6 +59,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:padding="5dp"
|
||||||
android:src="@drawable/ic_close" />
|
android:src="@drawable/ic_close" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user