2022-07-02 21:53:24 +05:30
|
|
|
package com.github.libretube.views
|
2021-12-12 20:31:44 +05:30
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.MotionEvent
|
2022-07-01 18:42:00 +05:30
|
|
|
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
2022-08-12 17:33:55 +05:30
|
|
|
import com.github.libretube.interfaces.DoubleTapInterface
|
2022-07-27 12:25:44 +05:30
|
|
|
import com.github.libretube.util.DoubleTapListener
|
2021-12-14 02:58:17 +05:30
|
|
|
import com.google.android.exoplayer2.ui.StyledPlayerView
|
2021-12-12 20:31:44 +05:30
|
|
|
|
2022-07-27 12:25:44 +05:30
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
2021-12-12 20:31:44 +05:30
|
|
|
internal class CustomExoPlayerView(
|
2022-05-20 03:52:10 +05:30
|
|
|
context: Context,
|
|
|
|
attributeSet: AttributeSet? = null
|
2021-12-14 02:58:17 +05:30
|
|
|
) : StyledPlayerView(context, attributeSet) {
|
2022-07-01 18:42:00 +05:30
|
|
|
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
2021-12-12 20:31:44 +05:30
|
|
|
|
2022-08-12 17:33:55 +05:30
|
|
|
private var doubleTapListener: DoubleTapInterface? = null
|
2022-07-27 12:25:44 +05:30
|
|
|
|
2022-07-27 14:47:05 +05:30
|
|
|
// the x-position of where the user clicked
|
|
|
|
private var xPos = 0F
|
2022-07-27 12:25:44 +05:30
|
|
|
|
|
|
|
fun setOnDoubleTapListener(
|
2022-08-12 17:33:55 +05:30
|
|
|
eventListener: DoubleTapInterface?
|
2022-07-27 12:25:44 +05:30
|
|
|
) {
|
|
|
|
doubleTapListener = eventListener
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun toggleController() {
|
|
|
|
if (isControllerFullyVisible) hideController() else showController()
|
|
|
|
}
|
|
|
|
|
|
|
|
val doubleTouchListener = object : DoubleTapListener() {
|
|
|
|
override fun onDoubleClick() {
|
|
|
|
doubleTapListener?.onEvent(xPos)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSingleClick() {
|
|
|
|
toggleController()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 18:29:16 +05:30
|
|
|
init {
|
2022-07-27 14:47:05 +05:30
|
|
|
// set the double click listener for rewind/forward
|
2022-07-27 12:25:44 +05:30
|
|
|
setOnClickListener(doubleTouchListener)
|
2022-07-19 18:29:16 +05:30
|
|
|
}
|
|
|
|
|
2021-12-12 20:31:44 +05:30
|
|
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
2022-07-27 14:47:05 +05:30
|
|
|
// save the x position of the touch event
|
2022-07-27 12:25:44 +05:30
|
|
|
xPos = event.x
|
2022-07-27 14:47:05 +05:30
|
|
|
// listen for a double touch
|
2022-07-27 12:25:44 +05:30
|
|
|
doubleTouchListener.onClick(this)
|
2021-12-12 20:31:44 +05:30
|
|
|
return false
|
|
|
|
}
|
2022-05-20 03:52:10 +05:30
|
|
|
}
|