mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20: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.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,44 +985,69 @@ 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
|
// show the rewind button
|
||||||
}, 700)
|
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()
|
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
|
|
||||||
|
// enable forward button
|
||||||
|
val forwardGestureDetector = GestureDetector(
|
||||||
|
context,
|
||||||
|
object : SimpleOnGestureListener() {
|
||||||
|
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||||
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement)
|
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement)
|
||||||
Handler(Looper.getMainLooper()).postDelayed({
|
|
||||||
binding.forwardBTN.visibility = View.INVISIBLE
|
// show the forward button
|
||||||
}, 700)
|
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()
|
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
|
||||||
|
@ -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_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"
|
||||||
|
Loading…
Reference in New Issue
Block a user