mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #1080 from Bnyro/master
improve double tap behavior and fixes
This commit is contained in:
commit
2bd16877bb
@ -942,21 +942,22 @@ class PlayerFragment : BaseFragment() {
|
|||||||
.postDelayed(this@PlayerFragment::refreshLiveStatus, 100)
|
.postDelayed(this@PlayerFragment::refreshLiveStatus, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// seek to saved watch position if available
|
||||||
private fun seekToWatchPosition() {
|
private fun seekToWatchPosition() {
|
||||||
// seek to saved watch position if available
|
// support for time stamped links
|
||||||
|
val timeStamp: Long? = arguments?.getLong("timeStamp")
|
||||||
|
if (timeStamp != null && timeStamp != 0L) {
|
||||||
|
exoPlayer.seekTo(timeStamp * 1000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// browse the watch positions
|
||||||
var position: Long? = null
|
var position: Long? = null
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
position = DatabaseHolder.db.watchPositionDao().findById(videoId!!).position
|
position = DatabaseHolder.db.watchPositionDao().findById(videoId!!).position
|
||||||
} catch (e: Exception) {
|
if (position!! < streams.duration!! * 0.9) position = null
|
||||||
position = null
|
} catch (e: Exception) {}
|
||||||
}
|
|
||||||
}.await()
|
}.await()
|
||||||
// support for time stamped links
|
|
||||||
val timeStamp: Long? = arguments?.getLong("timeStamp")
|
|
||||||
if (timeStamp != null && timeStamp != 0L) {
|
|
||||||
position = timeStamp * 1000
|
|
||||||
}
|
|
||||||
if (position != null) exoPlayer.seekTo(position!!)
|
if (position != null) exoPlayer.seekTo(position!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,39 +7,34 @@ import android.view.View
|
|||||||
|
|
||||||
abstract class DoubleTapListener : View.OnClickListener {
|
abstract class DoubleTapListener : View.OnClickListener {
|
||||||
|
|
||||||
|
private val maximumTimeDifference = 300L
|
||||||
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
private var isSingleEvent = false
|
private var isSingleEvent = false
|
||||||
private val doubleClickQualificationSpanInMillis: Long
|
private var timeStampLastClick = 0L
|
||||||
private var timestampLastClick: Long
|
private var timeStampLastDoubleClick = 0L
|
||||||
private val handler: Handler
|
|
||||||
private val runnable: Runnable
|
|
||||||
|
|
||||||
override fun onClick(v: View?) {
|
override fun onClick(v: View?) {
|
||||||
if (SystemClock.elapsedRealtime() - timestampLastClick < doubleClickQualificationSpanInMillis) {
|
if (SystemClock.elapsedRealtime() - timeStampLastClick < maximumTimeDifference) {
|
||||||
isSingleEvent = false
|
isSingleEvent = false
|
||||||
handler.removeCallbacks(runnable)
|
handler.removeCallbacks(runnable)
|
||||||
|
timeStampLastDoubleClick = SystemClock.elapsedRealtime()
|
||||||
onDoubleClick()
|
onDoubleClick()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isSingleEvent = true
|
isSingleEvent = true
|
||||||
handler.postDelayed(runnable, DEFAULT_QUALIFICATION_SPAN)
|
handler.removeCallbacks(runnable)
|
||||||
timestampLastClick = SystemClock.elapsedRealtime()
|
handler.postDelayed(runnable, maximumTimeDifference)
|
||||||
|
timeStampLastClick = SystemClock.elapsedRealtime()
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun onDoubleClick()
|
abstract fun onDoubleClick()
|
||||||
abstract fun onSingleClick()
|
abstract fun onSingleClick()
|
||||||
|
|
||||||
companion object {
|
private val runnable = Runnable {
|
||||||
private const val DEFAULT_QUALIFICATION_SPAN: Long = 200
|
if (!isSingleEvent ||
|
||||||
}
|
SystemClock.elapsedRealtime() - timeStampLastDoubleClick < maximumTimeDifference
|
||||||
|
) return@Runnable
|
||||||
init {
|
onSingleClick()
|
||||||
doubleClickQualificationSpanInMillis = DEFAULT_QUALIFICATION_SPAN
|
|
||||||
timestampLastClick = 0
|
|
||||||
handler = Handler(Looper.getMainLooper())
|
|
||||||
runnable = Runnable {
|
|
||||||
if (isSingleEvent) {
|
|
||||||
onSingleClick()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user