Merge pull request #804 from Bnyro/master

double tap overlay improvements
This commit is contained in:
Bnyro 2022-07-17 12:03:26 +02:00 committed by GitHub
commit 2072b1907f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 80 deletions

View File

@ -20,7 +20,10 @@ import android.support.v4.media.session.MediaSessionCompat
import android.text.Html import android.text.Html
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import android.view.GestureDetector
import android.view.GestureDetector.SimpleOnGestureListener
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
@ -62,7 +65,6 @@ import com.github.libretube.util.DescriptionAdapter
import com.github.libretube.util.PlayerHelper import com.github.libretube.util.PlayerHelper
import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.formatShort import com.github.libretube.util.formatShort
import com.github.libretube.views.DoubleClickListener
import com.google.android.exoplayer2.C import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.DefaultLoadControl import com.google.android.exoplayer2.DefaultLoadControl
import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.ExoPlayer
@ -983,45 +985,70 @@ class PlayerFragment : Fragment() {
val seekIncrement = val seekIncrement =
PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000 PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000
val hideDoubleTapOverlayDelay = 700L
// enable rewind button // enable rewind button
binding.rewindFL.setOnClickListener( val rewindGestureDetector = GestureDetector(
DoubleClickListener( context,
callback = object : DoubleClickListener.Callback { object : SimpleOnGestureListener() {
override fun doubleClicked() { override fun onDoubleTap(e: MotionEvent): Boolean {
binding.rewindBTN.visibility = View.VISIBLE exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement)
exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement)
Handler(Looper.getMainLooper()).postDelayed({
binding.rewindBTN.visibility = View.INVISIBLE
}, 700)
}
override fun singleClicked() { // show the rewind button
toggleController() binding.rewindBTN.apply {
visibility = View.VISIBLE
removeCallbacks(hideRewindButtonRunnable)
postDelayed(hideRewindButtonRunnable, hideDoubleTapOverlayDelay)
} }
return super.onDoubleTap(e)
} }
)
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
toggleController()
return super.onSingleTapConfirmed(e)
}
}
) )
// enable fast forward button binding.rewindFL.setOnTouchListener { view, event ->
binding.forwardFL.setOnClickListener( rewindGestureDetector.onTouchEvent(event)
DoubleClickListener( view.performClick()
callback = object : DoubleClickListener.Callback { true
override fun doubleClicked() { }
binding.forwardBTN.visibility = View.VISIBLE
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement)
Handler(Looper.getMainLooper()).postDelayed({
binding.forwardBTN.visibility = View.INVISIBLE
}, 700)
}
override fun singleClicked() { // enable forward button
toggleController() val forwardGestureDetector = GestureDetector(
context,
object : SimpleOnGestureListener() {
override fun onDoubleTap(e: MotionEvent): Boolean {
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement)
// show the forward button
binding.forwardBTN.apply {
visibility = View.VISIBLE
removeCallbacks(hideForwardButtonRunnable)
postDelayed(hideForwardButtonRunnable, hideDoubleTapOverlayDelay)
} }
return super.onDoubleTap(e)
} }
)
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
toggleController()
return super.onSingleTapConfirmed(e)
}
}
) )
binding.forwardFL.setOnTouchListener { view, event ->
forwardGestureDetector.onTouchEvent(event)
view.performClick()
true
}
} }
private val hideForwardButtonRunnable = Runnable { binding.forwardBTN.visibility = View.GONE }
private val hideRewindButtonRunnable = Runnable { binding.rewindBTN.visibility = View.GONE }
private fun disableDoubleTapToSeek() { private fun disableDoubleTapToSeek() {
// disable fast forward and rewind by double tapping // disable fast forward and rewind by double tapping
binding.forwardFL.visibility = View.GONE binding.forwardFL.visibility = View.GONE

View File

@ -1,51 +0,0 @@
package com.github.libretube.views
import android.os.Handler
import android.os.Looper
import android.view.View
class DoubleClickListener(
private val doubleClickTimeLimitMills: Long = 200,
private val callback: Callback
) : View.OnClickListener {
private var lastClicked: Long = -1L
override fun onClick(v: View?) {
lastClicked = when {
lastClicked == -1L -> {
checkForSingleClick()
System.currentTimeMillis()
}
isDoubleClicked() -> {
callback.doubleClicked()
-1L
}
else -> {
checkForSingleClick()
System.currentTimeMillis()
}
}
}
private fun checkForSingleClick() {
Handler(Looper.getMainLooper()).postDelayed({
if (lastClicked != -1L) callback.singleClicked()
}, doubleClickTimeLimitMills)
}
private fun getTimeDiff(from: Long, to: Long): Long {
return to - from
}
private fun isDoubleClicked(): Boolean {
return getTimeDiff(
lastClicked,
System.currentTimeMillis()
) <= doubleClickTimeLimitMills
}
interface Callback {
fun doubleClicked()
fun singleClicked()
}
}

View File

@ -0,0 +1,28 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?android:attr/colorControlNormal"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:fillColor="#00000000"
android:pathData="M233.95,94.29l0,-72.24l-72.24,0"
android:strokeWidth="24"
android:strokeColor="#000000"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M147.26,108.74L233.95,22.05"
android:strokeWidth="24"
android:strokeColor="#000000"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="m195.42,147.26v77.05a9.63,9.63 0,0 1,-9.63 9.63H31.68a9.63,9.63 0,0 1,-9.63 -9.63V70.21a9.63,9.63 0,0 1,9.63 -9.63h77.05"
android:strokeWidth="24"
android:strokeColor="#000000"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</vector>

View File

@ -192,7 +192,7 @@
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="25dp" android:layout_height="25dp"
android:padding="2dp" android:padding="2dp"
android:src="@drawable/ic_videocam" /> android:src="@drawable/ic_open" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"