mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Replace the autoplay option with a switch
This commit is contained in:
parent
3898f5e9a1
commit
15afbc2a82
@ -107,15 +107,15 @@ import com.google.android.exoplayer2.ui.StyledPlayerView
|
|||||||
import com.google.android.exoplayer2.upstream.DefaultDataSource
|
import com.google.android.exoplayer2.upstream.DefaultDataSource
|
||||||
import com.google.android.exoplayer2.util.MimeTypes
|
import com.google.android.exoplayer2.util.MimeTypes
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import java.io.IOException
|
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.Executors
|
|
||||||
import kotlin.math.abs
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.chromium.net.CronetEngine
|
import org.chromium.net.CronetEngine
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
|
import java.io.IOException
|
||||||
|
import java.util.*
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||||
|
|
||||||
@ -314,6 +314,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
.commit()
|
.commit()
|
||||||
BackgroundHelper.stopBackgroundPlay(requireContext())
|
BackgroundHelper.stopBackgroundPlay(requireContext())
|
||||||
}
|
}
|
||||||
|
playerBinding.autoPlay.visibility = View.VISIBLE
|
||||||
|
|
||||||
binding.playImageView.setOnClickListener {
|
binding.playImageView.setOnClickListener {
|
||||||
if (!exoPlayer.isPlaying) {
|
if (!exoPlayer.isPlaying) {
|
||||||
@ -1162,8 +1163,8 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
for (vid in videoStreams) {
|
for (vid in videoStreams) {
|
||||||
if (resolutions.any {
|
if (resolutions.any {
|
||||||
it.resolution == vid.quality.qualityToInt()
|
it.resolution == vid.quality.qualityToInt()
|
||||||
} || vid.url == null
|
} || vid.url == null
|
||||||
) {
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.github.libretube.ui.interfaces
|
package com.github.libretube.ui.interfaces
|
||||||
|
|
||||||
interface PlayerOptions {
|
interface PlayerOptions {
|
||||||
fun onAutoplayClicked()
|
|
||||||
|
|
||||||
fun onPlaybackSpeedClicked()
|
fun onPlaybackSpeedClicked()
|
||||||
|
|
||||||
|
@ -127,6 +127,12 @@ internal class CustomExoPlayerView(
|
|||||||
isPlayerLocked = !isPlayerLocked
|
isPlayerLocked = !isPlayerLocked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.autoPlay.isChecked = autoplayEnabled
|
||||||
|
|
||||||
|
binding.autoPlay.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
autoplayEnabled = isChecked
|
||||||
|
}
|
||||||
|
|
||||||
resizeMode = when (resizeModePref) {
|
resizeMode = when (resizeModePref) {
|
||||||
"fill" -> AspectRatioFrameLayout.RESIZE_MODE_FILL
|
"fill" -> AspectRatioFrameLayout.RESIZE_MODE_FILL
|
||||||
"zoom" -> AspectRatioFrameLayout.RESIZE_MODE_ZOOM
|
"zoom" -> AspectRatioFrameLayout.RESIZE_MODE_ZOOM
|
||||||
@ -213,19 +219,6 @@ internal class CustomExoPlayerView(
|
|||||||
private fun initializeAdvancedOptions(context: Context) {
|
private fun initializeAdvancedOptions(context: Context) {
|
||||||
binding.toggleOptions.setOnClickListener {
|
binding.toggleOptions.setOnClickListener {
|
||||||
val items = mutableListOf(
|
val items = mutableListOf(
|
||||||
BottomSheetItem(
|
|
||||||
context.getString(R.string.player_autoplay),
|
|
||||||
R.drawable.ic_play,
|
|
||||||
{
|
|
||||||
if (autoplayEnabled) {
|
|
||||||
context.getString(R.string.enabled)
|
|
||||||
} else {
|
|
||||||
context.getString(R.string.disabled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
onAutoplayClicked()
|
|
||||||
},
|
|
||||||
BottomSheetItem(
|
BottomSheetItem(
|
||||||
context.getString(R.string.repeat_mode),
|
context.getString(R.string.repeat_mode),
|
||||||
R.drawable.ic_repeat,
|
R.drawable.ic_repeat,
|
||||||
@ -446,23 +439,6 @@ internal class CustomExoPlayerView(
|
|||||||
gestureViewBinding.volumeTextView.text = "${bar.progress.normalize(0, bar.max, 0, 100)}"
|
gestureViewBinding.volumeTextView.text = "${bar.progress.normalize(0, bar.max, 0, 100)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAutoplayClicked() {
|
|
||||||
// autoplay options dialog
|
|
||||||
BaseBottomSheet()
|
|
||||||
.setSimpleItems(
|
|
||||||
listOf(
|
|
||||||
context.getString(R.string.enabled),
|
|
||||||
context.getString(R.string.disabled)
|
|
||||||
)
|
|
||||||
) { index ->
|
|
||||||
when (index) {
|
|
||||||
0 -> autoplayEnabled = true
|
|
||||||
1 -> autoplayEnabled = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.show(supportFragmentManager)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPlaybackSpeedClicked() {
|
override fun onPlaybackSpeedClicked() {
|
||||||
player?.let { PlaybackSpeedSheet(it).show(supportFragmentManager) }
|
player?.let { PlaybackSpeedSheet(it).show(supportFragmentManager) }
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,15 @@
|
|||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layoutDirection="ltr">
|
android:layoutDirection="ltr">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
android:id="@+id/autoPlay"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_marginEnd="2dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:trackTint="#88ffffff"
|
||||||
|
app:thumbTint="@android:color/white"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/sb_toggle"
|
android:id="@+id/sb_toggle"
|
||||||
style="@style/PlayerControlTop"
|
style="@style/PlayerControlTop"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user