add repeat queue btn

This commit is contained in:
Bnyro 2022-11-17 16:45:07 +01:00
parent 12adebd4bf
commit bbdeeea03b
4 changed files with 31 additions and 13 deletions

View File

@ -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()

View File

@ -61,6 +61,13 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
adapter.notifyDataSetChanged() 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()
} }

View File

@ -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)
} }

View File

@ -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 = {}
} }
} }