mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #1882 from Bnyro/master
Queue: Reverse and repeat controls
This commit is contained in:
commit
e2ca94c434
@ -501,7 +501,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
try {
|
try {
|
||||||
// clear the playing queue
|
// clear the playing queue
|
||||||
PlayingQueue.clear()
|
PlayingQueue.clear()
|
||||||
PlayingQueue.removeOnQueueTapListener()
|
PlayingQueue.resetToDefaults()
|
||||||
|
|
||||||
saveWatchPosition()
|
saveWatchPosition()
|
||||||
nowPlayingNotification.destroySelfAndPlayer()
|
nowPlayingNotification.destroySelfAndPlayer()
|
||||||
|
@ -48,8 +48,7 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
|||||||
binding.clear.setOnClickListener {
|
binding.clear.setOnClickListener {
|
||||||
val currentIndex = PlayingQueue.currentIndex()
|
val currentIndex = PlayingQueue.currentIndex()
|
||||||
|
|
||||||
val streams = PlayingQueue.getStreams().filterIndexed {
|
val streams = PlayingQueue.getStreams().filterIndexed { position, _ ->
|
||||||
position, _ ->
|
|
||||||
position <= currentIndex
|
position <= currentIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +56,18 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
|||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.reverse.setOnClickListener {
|
||||||
|
PlayingQueue.setStreams(PlayingQueue.getStreams().reversed())
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.repeat.setOnClickListener {
|
||||||
|
PlayingQueue.repeatQueue = !PlayingQueue.repeatQueue
|
||||||
|
it.alpha = if (PlayingQueue.repeatQueue) 1f else 0.5f
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.repeat.alpha = if (PlayingQueue.repeatQueue) 1f else 0.5f
|
||||||
|
|
||||||
binding.bottomControls.setOnClickListener {
|
binding.bottomControls.setOnClickListener {
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,9 @@ import com.github.libretube.ui.interfaces.PlayerOptions
|
|||||||
import com.github.libretube.ui.sheets.BaseBottomSheet
|
import com.github.libretube.ui.sheets.BaseBottomSheet
|
||||||
import com.github.libretube.ui.sheets.PlaybackSpeedSheet
|
import com.github.libretube.ui.sheets.PlaybackSpeedSheet
|
||||||
import com.github.libretube.util.PlayerHelper
|
import com.github.libretube.util.PlayerHelper
|
||||||
|
import com.github.libretube.util.PlayingQueue
|
||||||
import com.google.android.exoplayer2.PlaybackParameters
|
import com.google.android.exoplayer2.PlaybackParameters
|
||||||
|
import com.google.android.exoplayer2.Player
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelector
|
import com.google.android.exoplayer2.trackselection.TrackSelector
|
||||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
||||||
import com.google.android.exoplayer2.ui.StyledPlayerView
|
import com.google.android.exoplayer2.ui.StyledPlayerView
|
||||||
@ -373,18 +375,23 @@ internal class CustomExoPlayerView(
|
|||||||
override fun onRepeatModeClicked() {
|
override fun onRepeatModeClicked() {
|
||||||
val repeatModeNames = listOf(
|
val repeatModeNames = listOf(
|
||||||
context.getString(R.string.repeat_mode_none),
|
context.getString(R.string.repeat_mode_none),
|
||||||
context.getString(R.string.repeat_mode_current)
|
context.getString(R.string.repeat_mode_current),
|
||||||
)
|
context.getString(R.string.all)
|
||||||
|
|
||||||
val repeatModes = listOf(
|
|
||||||
RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE,
|
|
||||||
RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL
|
|
||||||
|
|
||||||
)
|
)
|
||||||
// repeat mode options dialog
|
// repeat mode options dialog
|
||||||
BaseBottomSheet()
|
BaseBottomSheet()
|
||||||
.setSimpleItems(repeatModeNames) { index ->
|
.setSimpleItems(repeatModeNames) { index ->
|
||||||
player?.repeatMode = repeatModes[index]
|
PlayingQueue.repeatQueue = when (index) {
|
||||||
|
0 -> {
|
||||||
|
player?.repeatMode = Player.REPEAT_MODE_OFF
|
||||||
|
false
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
|
player?.repeatMode = Player.REPEAT_MODE_ONE
|
||||||
|
false
|
||||||
|
}
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.show(supportFragmentManager)
|
.show(supportFragmentManager)
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ object PlayingQueue {
|
|||||||
private val queue = mutableListOf<StreamItem>()
|
private val queue = mutableListOf<StreamItem>()
|
||||||
private var currentStream: StreamItem? = null
|
private var currentStream: StreamItem? = null
|
||||||
private var onQueueTapListener: (StreamItem) -> Unit = {}
|
private var onQueueTapListener: (StreamItem) -> Unit = {}
|
||||||
|
var repeatQueue: Boolean = false
|
||||||
|
|
||||||
fun add(vararg streamItem: StreamItem) {
|
fun add(vararg streamItem: StreamItem) {
|
||||||
streamItem.forEach {
|
streamItem.forEach {
|
||||||
@ -33,11 +34,13 @@ object PlayingQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getNext(): String? {
|
fun getNext(): String? {
|
||||||
return try {
|
try {
|
||||||
queue[currentIndex() + 1].url?.toID()
|
return queue[currentIndex() + 1].url?.toID()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
null
|
Log.e("queue ended", e.toString())
|
||||||
}
|
}
|
||||||
|
if (repeatQueue) return queue.firstOrNull()?.url?.toID()
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPrev(): String? {
|
fun getPrev(): String? {
|
||||||
@ -133,7 +136,8 @@ object PlayingQueue {
|
|||||||
onQueueTapListener = listener
|
onQueueTapListener = listener
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeOnQueueTapListener() {
|
fun resetToDefaults() {
|
||||||
|
repeatQueue = false
|
||||||
onQueueTapListener = {}
|
onQueueTapListener = {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
app/src/main/res/drawable/ic_reverse.xml
Normal file
10
app/src/main/res/drawable/ic_reverse.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="48"
|
||||||
|
android:viewportHeight="48">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="m16.25,41.4 l-2.1,-2.1 3.2,-3.3q-5.5,0 -9.425,-3.75Q4,28.5 4,23q0,-5.35 3.725,-9.175Q11.45,10 16.8,10h7.6v3h-7.6q-4.1,0 -6.95,2.925Q7,18.85 7,23q0,4.25 3.125,7.125T17.6,33l-3.3,-3.3 2.1,-2.1 6.8,6.85ZM28.6,36v-3L44,33v3ZM28.6,24.5v-3L44,21.5v3ZM27.4,13v-3L44,10v3Z" />
|
||||||
|
</vector>
|
@ -41,10 +41,20 @@
|
|||||||
android:id="@+id/shuffle"
|
android:id="@+id/shuffle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="5dp"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:src="@drawable/ic_shuffle" />
|
android:src="@drawable/ic_shuffle" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/reverse"
|
||||||
|
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_reverse" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -53,10 +63,20 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:src="@drawable/ic_arrow_down" />
|
android:src="@drawable/ic_arrow_down" />
|
||||||
|
|
||||||
|
<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/clear"
|
android:id="@+id/clear"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="5dp"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:src="@drawable/ic_close" />
|
android:src="@drawable/ic_close" />
|
||||||
|
Loading…
Reference in New Issue
Block a user