Merge pull request #825 from Bnyro/master

improve double tap and controller behavior
This commit is contained in:
Bnyro 2022-07-19 15:00:13 +02:00 committed by GitHub
commit b32b29efc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 158 additions and 100 deletions

View File

@ -42,6 +42,7 @@ import com.github.libretube.activities.hideKeyboard
import com.github.libretube.adapters.ChaptersAdapter
import com.github.libretube.adapters.CommentsAdapter
import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.databinding.DoubleTapOverlayBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.databinding.FragmentPlayerBinding
import com.github.libretube.dialogs.AddtoPlaylistDialog
@ -105,6 +106,7 @@ class PlayerFragment : Fragment() {
private val TAG = "PlayerFragment"
private lateinit var binding: FragmentPlayerBinding
private lateinit var playerBinding: ExoStyledPlayerControlViewBinding
private lateinit var doubleTapOverlayBinding: DoubleTapOverlayBinding
/**
* video information
@ -199,6 +201,8 @@ class PlayerFragment : Fragment() {
): View {
binding = FragmentPlayerBinding.inflate(layoutInflater, container, false)
playerBinding = binding.player.binding
doubleTapOverlayBinding = binding.doubleTapOverlay.binding
// Inflate the layout for this fragment
return binding.root
}
@ -1061,8 +1065,8 @@ class PlayerFragment : Fragment() {
private fun enableDoubleTapToSeek() {
// set seek increment text
val seekIncrementText = (seekIncrement / 1000).toString()
binding.rewindTV.text = seekIncrementText
binding.forwardTV.text = seekIncrementText
doubleTapOverlayBinding.rewindTV.text = seekIncrementText
doubleTapOverlayBinding.forwardTV.text = seekIncrementText
// enable rewind button
val rewindGestureDetector = GestureDetector(
@ -1074,13 +1078,13 @@ class PlayerFragment : Fragment() {
}
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
binding.player.performClick()
toggleController()
return super.onSingleTapConfirmed(e)
}
}
)
binding.rewindFL.setOnTouchListener { view, event ->
doubleTapOverlayBinding.rewindFL.setOnTouchListener { view, event ->
rewindGestureDetector.onTouchEvent(event)
view.performClick()
true
@ -1096,13 +1100,13 @@ class PlayerFragment : Fragment() {
}
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
binding.player.performClick()
toggleController()
return super.onSingleTapConfirmed(e)
}
}
)
binding.forwardFL.setOnTouchListener { view, event ->
doubleTapOverlayBinding.forwardFL.setOnTouchListener { view, event ->
forwardGestureDetector.onTouchEvent(event)
view.performClick()
true
@ -1113,7 +1117,7 @@ class PlayerFragment : Fragment() {
exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement)
// show the rewind button
binding.rewindBTN.apply {
doubleTapOverlayBinding.rewindBTN.apply {
visibility = View.VISIBLE
// clear previous animation
animate().rotation(0F).setDuration(0).start()
@ -1137,7 +1141,7 @@ class PlayerFragment : Fragment() {
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement)
// show the forward button
binding.forwardBTN.apply {
doubleTapOverlayBinding.forwardBTN.apply {
visibility = View.VISIBLE
// clear previous animation
animate().rotation(0F).setDuration(0).start()
@ -1158,16 +1162,21 @@ class PlayerFragment : Fragment() {
}
private val hideForwardButtonRunnable = Runnable {
binding.forwardBTN.apply {
doubleTapOverlayBinding.forwardBTN.apply {
visibility = View.GONE
}
}
private val hideRewindButtonRunnable = Runnable {
binding.rewindBTN.apply {
doubleTapOverlayBinding.rewindBTN.apply {
visibility = View.GONE
}
}
private fun toggleController() {
if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController()
else exoPlayerView.showController()
}
// enable seek bar preview
private fun enableSeekbarPreview() {
playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener {
@ -1515,12 +1524,10 @@ class PlayerFragment : Fragment() {
// disable double tap to seek when the player is locked
if (isLocked) {
// enable fast forward and rewind by double tapping
binding.forwardFL.visibility = View.VISIBLE
binding.rewindFL.visibility = View.VISIBLE
binding.doubleTapOverlay.visibility = View.VISIBLE
} else {
// disable fast forward and rewind by double tapping
binding.forwardFL.visibility = View.GONE
binding.rewindFL.visibility = View.GONE
binding.doubleTapOverlay.visibility = View.GONE
}
}

View File

@ -5,6 +5,7 @@ import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import com.github.libretube.R
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.google.android.exoplayer2.ui.StyledPlayerView
@ -12,12 +13,35 @@ internal class CustomExoPlayerView(
context: Context,
attributeSet: AttributeSet? = null
) : StyledPlayerView(context, attributeSet) {
val TAG = "CustomExoPlayerView"
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
init {
setControllerVisibilityListener {
// hide the advanced options
binding.toggleOptions.animate().rotationX(0F).setDuration(0).start()
binding.advancedOptions.visibility = View.GONE
}
}
override fun hideController() {
super.hideController()
binding.toggleOptions.animate().rotationX(0F).setDuration(1000).start()
binding.advancedOptions.visibility = View.GONE
setDoubleTapOverlayLayoutParams(0)
}
override fun showController() {
setDoubleTapOverlayLayoutParams(90)
super.showController()
}
// set the top and bottom margin of the double tap overlay
private fun setDoubleTapOverlayLayoutParams(margin: Int) {
val dpMargin = resources?.displayMetrics?.density!!.toInt() * margin
val doubleTapOverlay = binding.root.findViewById<DoubleTapOverlay>(R.id.doubleTapOverlay)
val params = doubleTapOverlay.layoutParams as MarginLayoutParams
params.topMargin = dpMargin
params.bottomMargin = dpMargin
doubleTapOverlay.layoutParams = params
}
@SuppressLint("ClickableViewAccessibility")

View File

@ -0,0 +1,19 @@
package com.github.libretube.views
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.github.libretube.databinding.DoubleTapOverlayBinding
class DoubleTapOverlay(
context: Context,
attrs: AttributeSet? = null
) : LinearLayout(context, attrs) {
var binding: DoubleTapOverlayBinding
init {
val layoutInflater = LayoutInflater.from(context)
binding = DoubleTapOverlayBinding.inflate(layoutInflater, this, true)
}
}

View File

@ -26,7 +26,7 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
private val transitionListenerList = mutableListOf<TransitionListener?>()
init {
addTransitionListener(object : MotionLayout.TransitionListener {
addTransitionListener(object : TransitionListener {
override fun onTransitionStarted(
motionLayout: MotionLayout?,
startId: Int,
@ -50,7 +50,7 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
}
})
super.setTransitionListener(object : MotionLayout.TransitionListener {
super.setTransitionListener(object : TransitionListener {
override fun onTransitionStarted(
motionLayout: MotionLayout?,
startId: Int,

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:baselineAligned="false">
<!-- double tap rewind btn -->
<FrameLayout
android:id="@+id/rewindFL"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".40">
<FrameLayout
android:id="@+id/rewindBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="30dp"
android:visibility="invisible">
<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="11sp" />
</FrameLayout>
</FrameLayout>
<!-- place holder for the center controls -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".20" />
<!-- double tap forward btn -->
<FrameLayout
android:id="@+id/forwardFL"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".40">
<FrameLayout
android:id="@+id/forwardBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="30dp"
android:visibility="invisible">
<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="11sp" />
</FrameLayout>
</FrameLayout>
</LinearLayout>

View File

@ -372,93 +372,17 @@
app:layout_constraintBottom_toBottomOf="@id/main_container"
app:layout_constraintStart_toStartOf="@id/main_container"
app:layout_constraintTop_toTopOf="@id/main_container"
app:show_buffering="when_playing">
app:show_buffering="when_playing" >
<!-- double tap to rewind/forward overlay -->
<LinearLayout
android:id="@+id/doubleTapOverlayLL"
<com.github.libretube.views.DoubleTapOverlay
android:id="@+id/doubleTapOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="65dp">
<!-- double tap rewind btn -->
<FrameLayout
android:id="@+id/rewindFL"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".40">
<FrameLayout
android:id="@+id/rewindBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="30dp"
android:visibility="invisible">
<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="11sp" />
</FrameLayout>
</FrameLayout>
<!-- place holder for the center controls -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".20" />
<!-- double tap forward btn -->
<FrameLayout
android:id="@+id/forwardFL"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".40">
<FrameLayout
android:id="@+id/forwardBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="30dp"
android:visibility="invisible">
<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="11sp" />
</FrameLayout>
</FrameLayout>
</LinearLayout>
android:layout_height="match_parent" />
</com.github.libretube.views.CustomExoPlayerView>
<ImageView
android:id="@+id/close_imageView"
android:layout_width="wrap_content"

View File

@ -66,6 +66,7 @@
motion:layout_constraintBottom_toBottomOf="@id/main_container"
motion:layout_constraintStart_toStartOf="@id/main_container"
motion:layout_constraintTop_toTopOf="@id/main_container" />
<Constraint android:id="@+id/doubleTapOverlay" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">