From a71cb344a57f88447d34ab65148574854c44c5f8 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 16 Aug 2022 17:23:08 +0200 Subject: [PATCH 1/3] improve double tap behavior --- .../libretube/util/DoubleTapListener.kt | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/github/libretube/util/DoubleTapListener.kt b/app/src/main/java/com/github/libretube/util/DoubleTapListener.kt index 4374b9597..324319054 100644 --- a/app/src/main/java/com/github/libretube/util/DoubleTapListener.kt +++ b/app/src/main/java/com/github/libretube/util/DoubleTapListener.kt @@ -7,39 +7,34 @@ import android.view.View abstract class DoubleTapListener : View.OnClickListener { + private val maximumTimeDifference = 300L + private val handler = Handler(Looper.getMainLooper()) + private var isSingleEvent = false - private val doubleClickQualificationSpanInMillis: Long - private var timestampLastClick: Long - private val handler: Handler - private val runnable: Runnable + private var timeStampLastClick = 0L + private var timeStampLastDoubleClick = 0L override fun onClick(v: View?) { - if (SystemClock.elapsedRealtime() - timestampLastClick < doubleClickQualificationSpanInMillis) { + if (SystemClock.elapsedRealtime() - timeStampLastClick < maximumTimeDifference) { isSingleEvent = false handler.removeCallbacks(runnable) + timeStampLastDoubleClick = SystemClock.elapsedRealtime() onDoubleClick() return } isSingleEvent = true - handler.postDelayed(runnable, DEFAULT_QUALIFICATION_SPAN) - timestampLastClick = SystemClock.elapsedRealtime() + handler.removeCallbacks(runnable) + handler.postDelayed(runnable, maximumTimeDifference) + timeStampLastClick = SystemClock.elapsedRealtime() } abstract fun onDoubleClick() abstract fun onSingleClick() - companion object { - private const val DEFAULT_QUALIFICATION_SPAN: Long = 200 - } - - init { - doubleClickQualificationSpanInMillis = DEFAULT_QUALIFICATION_SPAN - timestampLastClick = 0 - handler = Handler(Looper.getMainLooper()) - runnable = Runnable { - if (isSingleEvent) { - onSingleClick() - } - } + private val runnable = Runnable { + if (!isSingleEvent || + SystemClock.elapsedRealtime() - timeStampLastDoubleClick < maximumTimeDifference + ) return@Runnable + onSingleClick() } } From 751e2fda5f19f26e5d895a2149695befc2f47309 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 16 Aug 2022 17:28:16 +0200 Subject: [PATCH 2/3] fix autoplay skipping videos that are already watched --- .../libretube/fragments/PlayerFragment.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 6b648aeea..393ae018f 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -942,22 +942,21 @@ class PlayerFragment : BaseFragment() { .postDelayed(this@PlayerFragment::refreshLiveStatus, 100) } + // seek to saved watch position if available private fun seekToWatchPosition() { - // seek to saved watch position if available - var position: Long? = null - Thread { - try { - position = DatabaseHolder.db.watchPositionDao().findById(videoId!!).position - } catch (e: Exception) { - position = null - } - }.await() // support for time stamped links val timeStamp: Long? = arguments?.getLong("timeStamp") if (timeStamp != null && timeStamp != 0L) { - position = timeStamp * 1000 + exoPlayer.seekTo(timeStamp * 1000) + return } - if (position != null) exoPlayer.seekTo(position!!) + // browse the watch positions + Thread { + try { + val position = DatabaseHolder.db.watchPositionDao().findById(videoId!!).position + if (position < streams.duration!! * 0.9) exoPlayer.seekTo(position) + } catch (e: Exception) {} + }.start() } // used for autoplay and skipping to next video From 91b172d6613f1e0d0b535ee72f2fd564145a92a9 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 16 Aug 2022 17:30:52 +0200 Subject: [PATCH 3/3] fix again --- .../java/com/github/libretube/fragments/PlayerFragment.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 393ae018f..3b8b514c3 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -951,12 +951,14 @@ class PlayerFragment : BaseFragment() { return } // browse the watch positions + var position: Long? = null Thread { try { - val position = DatabaseHolder.db.watchPositionDao().findById(videoId!!).position - if (position < streams.duration!! * 0.9) exoPlayer.seekTo(position) + position = DatabaseHolder.db.watchPositionDao().findById(videoId!!).position + if (position!! < streams.duration!! * 0.9) position = null } catch (e: Exception) {} - }.start() + }.await() + if (position != null) exoPlayer.seekTo(position!!) } // used for autoplay and skipping to next video