mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #1678 from Bnyro/master
add shuffle and clear to playing queue
This commit is contained in:
commit
ba24652603
@ -0,0 +1,9 @@
|
||||
package com.github.libretube.extensions
|
||||
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
fun Float.round(decimalPlaces: Int): Float {
|
||||
return (this * 10.0.pow(decimalPlaces.toDouble())).roundToInt() / 10.0.pow(decimalPlaces.toDouble())
|
||||
.toFloat()
|
||||
}
|
@ -6,6 +6,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.github.libretube.databinding.PlaybackBottomSheetBinding
|
||||
import com.github.libretube.extensions.round
|
||||
import com.google.android.exoplayer2.PlaybackParameters
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
@ -31,11 +32,11 @@ class PlaybackSpeedSheet(
|
||||
binding.pitch.value = player.playbackParameters.pitch
|
||||
|
||||
binding.speed.addOnChangeListener { _, value, _ ->
|
||||
onChange(value, binding.pitch.value)
|
||||
onChange(value, binding.pitch.value.round(2))
|
||||
}
|
||||
|
||||
binding.pitch.addOnChangeListener { _, value, _ ->
|
||||
onChange(binding.speed.value, value)
|
||||
onChange(binding.speed.value.round(2), value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
@ -7,23 +8,24 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.BottomSheetBinding
|
||||
import com.github.libretube.databinding.QueueBottomSheetBinding
|
||||
import com.github.libretube.ui.adapters.PlayingQueueAdapter
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
|
||||
class PlayingQueueSheet : BottomSheetDialogFragment() {
|
||||
private lateinit var binding: BottomSheetBinding
|
||||
private lateinit var binding: QueueBottomSheetBinding
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = BottomSheetBinding.inflate(layoutInflater)
|
||||
binding = QueueBottomSheetBinding.inflate(layoutInflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
@ -31,6 +33,35 @@ class PlayingQueueSheet : BottomSheetDialogFragment() {
|
||||
val adapter = PlayingQueueAdapter()
|
||||
binding.optionsRecycler.adapter = adapter
|
||||
|
||||
binding.shuffle.setOnClickListener {
|
||||
val streams = PlayingQueue.getStreams()
|
||||
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 index = PlayingQueue.currentIndex()
|
||||
|
||||
while (index >= PlayingQueue.size()) {
|
||||
streams.removeAt(index)
|
||||
}
|
||||
|
||||
PlayingQueue.setStreams(streams)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
binding.bottomControls.setOnClickListener {
|
||||
dialog?.dismiss()
|
||||
}
|
||||
|
||||
val callback = object : ItemTouchHelper.SimpleCallback(
|
||||
ItemTouchHelper.UP or ItemTouchHelper.DOWN,
|
||||
ItemTouchHelper.LEFT
|
||||
|
@ -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)
|
||||
|
10
app/src/main/res/drawable/ic_shuffle.xml
Normal file
10
app/src/main/res/drawable/ic_shuffle.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10.59,9.17L5.41,4 4,5.41l5.17,5.17 1.42,-1.41zM14.5,4l2.04,2.04L4,18.59 5.41,20 17.96,7.46 20,9.5L20,4h-5.5zM14.83,13.41l-1.41,1.41 3.13,3.13L14.5,20L20,20v-5.5l-2.04,2.04 -3.13,-3.13z" />
|
||||
</vector>
|
71
app/src/main/res/layout/queue_bottom_sheet.xml
Normal file
71
app/src/main/res/layout/queue_bottom_sheet.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/standard_bottom_sheet"
|
||||
style="@style/Widget.Material3.BottomSheet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="20dp"
|
||||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Drag handle for accessibility -->
|
||||
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
|
||||
android:id="@+id/drag_handle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/options_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<LinearLayout
|
||||
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">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/shuffle"
|
||||
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"
|
||||
android:src="@drawable/ic_arrow_down" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/clear"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/ic_close" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user