Merge pull request #2118 from Bnyro/master

Option to disable double tap to seek
This commit is contained in:
Bnyro 2022-11-27 18:42:01 +01:00 committed by GitHub
commit a6f1027fff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 11 deletions

View File

@ -86,6 +86,7 @@ object PreferenceKeys {
const val PLAYER_SWIPE_CONTROLS = "player_swipe_controls" const val PLAYER_SWIPE_CONTROLS = "player_swipe_controls"
const val PLAYER_SCREEN_BRIGHTNESS = "player_screen_brightness" const val PLAYER_SCREEN_BRIGHTNESS = "player_screen_brightness"
const val CAPTIONS_SIZE = "captions_size" const val CAPTIONS_SIZE = "captions_size"
const val DOUBLE_TAP_TO_SEEK = "double_tap_seek"
/** /**
* Background mode * Background mode

View File

@ -92,7 +92,8 @@ internal class CustomExoPlayerView(
// Set touch listner for tap and swipe gestures. // Set touch listner for tap and swipe gestures.
setOnTouchListener(playerGestureController) setOnTouchListener(playerGestureController)
initializeGestureProgress() initializeGestureProgress()
enableDoubleTapToSeek()
initRewindAndForward()
initializeAdvancedOptions(context) initializeAdvancedOptions(context)
@ -138,6 +139,29 @@ internal class CustomExoPlayerView(
return false return false
} }
private fun initRewindAndForward() {
val seekIncrementText = (PlayerHelper.seekIncrement / 1000).toString()
listOf(
doubleTapOverlayBinding?.rewindTV,
doubleTapOverlayBinding?.forwardTV,
binding.forwardTV,
binding.rewindTV
).forEach {
it?.text = seekIncrementText
}
binding.forwardBTN.setOnClickListener {
player?.seekTo(player!!.currentPosition + PlayerHelper.seekIncrement)
}
binding.rewindBTN.setOnClickListener {
player?.seekTo(player!!.currentPosition - PlayerHelper.seekIncrement)
}
if (PlayerHelper.doubleTapToSeek) return
listOf(binding.forwardBTN, binding.rewindBTN).forEach {
it.visibility = View.VISIBLE
}
}
private fun initializeAdvancedOptions(context: Context) { private fun initializeAdvancedOptions(context: Context) {
binding.toggleOptions.setOnClickListener { binding.toggleOptions.setOnClickListener {
val items = mutableListOf( val items = mutableListOf(
@ -254,13 +278,6 @@ internal class CustomExoPlayerView(
playerGestureController.isEnabled = isLocked playerGestureController.isEnabled = isLocked
} }
private fun enableDoubleTapToSeek() {
// set seek increment text
val seekIncrementText = (PlayerHelper.seekIncrement / 1000).toString()
doubleTapOverlayBinding?.rewindTV?.text = seekIncrementText
doubleTapOverlayBinding?.forwardTV?.text = seekIncrementText
}
private fun rewind() { private fun rewind() {
player?.seekTo((player?.currentPosition ?: 0L) - PlayerHelper.seekIncrement) player?.seekTo((player?.currentPosition ?: 0L) - PlayerHelper.seekIncrement)
@ -322,7 +339,8 @@ internal class CustomExoPlayerView(
private fun initializeGestureProgress() { private fun initializeGestureProgress() {
gestureViewBinding.brightnessProgressBar.let { bar -> gestureViewBinding.brightnessProgressBar.let { bar ->
bar.progress = brightnessHelper.getBrightnessWithScale(bar.max.toFloat(), saved = true).toInt() bar.progress =
brightnessHelper.getBrightnessWithScale(bar.max.toFloat(), saved = true).toInt()
} }
gestureViewBinding.volumeProgressBar.let { bar -> gestureViewBinding.volumeProgressBar.let { bar ->
bar.progress = audioHelper.getVolumeWithScale(bar.max) bar.progress = audioHelper.getVolumeWithScale(bar.max)
@ -469,10 +487,12 @@ internal class CustomExoPlayerView(
} }
override fun onDoubleTapLeftScreen() { override fun onDoubleTapLeftScreen() {
if (!PlayerHelper.doubleTapToSeek) return
rewind() rewind()
} }
override fun onDoubleTapRightScreen() { override fun onDoubleTapRightScreen() {
if (!PlayerHelper.doubleTapToSeek) return
forward() forward()
} }

View File

@ -306,6 +306,12 @@ object PlayerHelper {
"18" "18"
).toFloat() ).toFloat()
val doubleTapToSeek: Boolean
get() = PreferenceHelper.getBoolean(
PreferenceKeys.DOUBLE_TAP_TO_SEEK,
true
)
fun getDefaultResolution(context: Context): String { fun getDefaultResolution(context: Context): String {
return if (NetworkHelper.isNetworkMobile(context)) { return if (NetworkHelper.isNetworkMobile(context)) {
PreferenceHelper.getString( PreferenceHelper.getString(

View File

@ -237,7 +237,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:clipToPadding="false"
android:gravity="center" android:gravity="center"
android:padding="20dp"> android:padding="20dp">
@ -249,12 +248,69 @@
android:visibility="invisible" android:visibility="invisible"
app:tint="@android:color/white" /> app:tint="@android:color/white" />
<FrameLayout
android:id="@+id/rewindBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="10dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleX="0.8"
android:scaleY="0.8"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_rewind"
app:tint="@android:color/white" />
<TextView
android:id="@+id/rewindTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:textColor="@android:color/white"
android:textSize="12sp" />
</FrameLayout>
<ImageButton <ImageButton
android:id="@id/exo_play_pause" android:id="@id/exo_play_pause"
style="@style/ExoStyledControls.Button.Center.PlayPause" style="@style/ExoStyledControls.Button.Center.PlayPause"
android:layout_marginHorizontal="10dp"
android:background="?android:selectableItemBackgroundBorderless" android:background="?android:selectableItemBackgroundBorderless"
app:tint="@android:color/white" /> app:tint="@android:color/white" />
<FrameLayout
android:id="@+id/forwardBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="10dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleX="0.8"
android:scaleY="0.8"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_forward"
app:tint="@android:color/white" />
<TextView
android:id="@+id/forwardTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:textColor="@android:color/white"
android:textSize="12sp" />
</FrameLayout>
<ImageView <ImageView
android:id="@+id/skip_next" android:id="@+id/skip_next"
style="@style/PlayerControlCenter" style="@style/PlayerControlCenter"

View File

@ -399,6 +399,8 @@
<string name="comments_disabled">Comments are disabled by the uploader.</string> <string name="comments_disabled">Comments are disabled by the uploader.</string>
<string name="no_comments_available">This video has no comments available.</string> <string name="no_comments_available">This video has no comments available.</string>
<string name="captions_size">Captions size</string> <string name="captions_size">Captions size</string>
<string name="double_tap_seek">Double tap to seek</string>
<string name="double_tap_seek_summary">Tap twice at the left or right to rewind or forward the player position.</string>
<!-- Notification channel strings --> <!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string> <string name="download_channel_name">Download Service</string>

View File

@ -18,6 +18,13 @@
app:key="skip_buttons" app:key="skip_buttons"
app:title="@string/skip_buttons" /> app:title="@string/skip_buttons" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_skip"
android:summary="@string/double_tap_seek_summary"
app:key="double_tap_seek"
app:title="@string/double_tap_seek" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
android:icon="@drawable/ic_window" android:icon="@drawable/ic_window"
@ -27,7 +34,7 @@
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:icon="@drawable/ic_rotating_circle" android:icon="@drawable/ic_rotating_circle"
android:summary="@string/autoRotatePlayer_summary" android:summary="@string/autoRotatePlayer_summary"
app:defaultValue="false" app:defaultValue="true"
app:key="auto_fullscreen" app:key="auto_fullscreen"
app:title="@string/autoRotatePlayer" /> app:title="@string/autoRotatePlayer" />