mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #804 from Bnyro/master
double tap overlay improvements
This commit is contained in:
commit
2072b1907f
@ -20,7 +20,10 @@ import android.support.v4.media.session.MediaSessionCompat
|
||||
import android.text.Html
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
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.RetrofitInstance
|
||||
import com.github.libretube.util.formatShort
|
||||
import com.github.libretube.views.DoubleClickListener
|
||||
import com.google.android.exoplayer2.C
|
||||
import com.google.android.exoplayer2.DefaultLoadControl
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
@ -983,44 +985,69 @@ class PlayerFragment : Fragment() {
|
||||
val seekIncrement =
|
||||
PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000
|
||||
|
||||
val hideDoubleTapOverlayDelay = 700L
|
||||
|
||||
// enable rewind button
|
||||
binding.rewindFL.setOnClickListener(
|
||||
DoubleClickListener(
|
||||
callback = object : DoubleClickListener.Callback {
|
||||
override fun doubleClicked() {
|
||||
binding.rewindBTN.visibility = View.VISIBLE
|
||||
val rewindGestureDetector = GestureDetector(
|
||||
context,
|
||||
object : SimpleOnGestureListener() {
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement)
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
binding.rewindBTN.visibility = View.INVISIBLE
|
||||
}, 700)
|
||||
|
||||
// show the rewind button
|
||||
binding.rewindBTN.apply {
|
||||
visibility = View.VISIBLE
|
||||
removeCallbacks(hideRewindButtonRunnable)
|
||||
postDelayed(hideRewindButtonRunnable, hideDoubleTapOverlayDelay)
|
||||
}
|
||||
return super.onDoubleTap(e)
|
||||
}
|
||||
|
||||
override fun singleClicked() {
|
||||
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
|
||||
toggleController()
|
||||
return super.onSingleTapConfirmed(e)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
// enable fast forward button
|
||||
binding.forwardFL.setOnClickListener(
|
||||
DoubleClickListener(
|
||||
callback = object : DoubleClickListener.Callback {
|
||||
override fun doubleClicked() {
|
||||
binding.forwardBTN.visibility = View.VISIBLE
|
||||
binding.rewindFL.setOnTouchListener { view, event ->
|
||||
rewindGestureDetector.onTouchEvent(event)
|
||||
view.performClick()
|
||||
true
|
||||
}
|
||||
|
||||
// enable forward button
|
||||
val forwardGestureDetector = GestureDetector(
|
||||
context,
|
||||
object : SimpleOnGestureListener() {
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement)
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
binding.forwardBTN.visibility = View.INVISIBLE
|
||||
}, 700)
|
||||
|
||||
// show the forward button
|
||||
binding.forwardBTN.apply {
|
||||
visibility = View.VISIBLE
|
||||
removeCallbacks(hideForwardButtonRunnable)
|
||||
postDelayed(hideForwardButtonRunnable, hideDoubleTapOverlayDelay)
|
||||
}
|
||||
return super.onDoubleTap(e)
|
||||
}
|
||||
|
||||
override fun singleClicked() {
|
||||
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() {
|
||||
// disable fast forward and rewind by double tapping
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
28
app/src/main/res/drawable/ic_open.xml
Normal file
28
app/src/main/res/drawable/ic_open.xml
Normal 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>
|
@ -192,7 +192,7 @@
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="25dp"
|
||||
android:padding="2dp"
|
||||
android:src="@drawable/ic_videocam" />
|
||||
android:src="@drawable/ic_open" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
Loading…
Reference in New Issue
Block a user