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
|
2022-07-27 12:25:44 +05:30
|
|
|
import android.util.Log
|
|
|
|
import android.view.GestureDetector
|
2021-12-12 20:31:44 +05:30
|
|
|
import android.view.MotionEvent
|
2022-07-15 14:57:04 +05:30
|
|
|
import android.view.View
|
2022-07-27 12:25:44 +05:30
|
|
|
import android.view.View.OnTouchListener
|
2022-07-19 18:29:16 +05:30
|
|
|
import com.github.libretube.R
|
2022-07-01 18:42:00 +05:30
|
|
|
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
2022-07-27 12:25:44 +05:30
|
|
|
import com.github.libretube.util.DoubleTapListener
|
|
|
|
import com.github.libretube.util.OnCustomEventListener
|
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-19 18:29:16 +05:30
|
|
|
val TAG = "CustomExoPlayerView"
|
2022-07-01 18:42:00 +05:30
|
|
|
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
2021-12-12 20:31:44 +05:30
|
|
|
|
2022-07-27 12:25:44 +05:30
|
|
|
var doubleTapListener: OnCustomEventListener? = null
|
|
|
|
|
|
|
|
var lastToggled: Long? = null
|
|
|
|
var xPos = 0F
|
|
|
|
|
|
|
|
fun setOnDoubleTapListener(
|
|
|
|
eventListener: OnCustomEventListener
|
|
|
|
) {
|
|
|
|
doubleTapListener = eventListener
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun toggleController() {
|
|
|
|
lastToggled = System.currentTimeMillis()
|
|
|
|
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 {
|
|
|
|
setControllerVisibilityListener {
|
|
|
|
// hide the advanced options
|
2022-07-20 17:19:56 +05:30
|
|
|
binding.toggleOptions.animate().rotation(0F).setDuration(250).start()
|
2022-07-19 18:29:16 +05:30
|
|
|
binding.advancedOptions.visibility = View.GONE
|
|
|
|
}
|
2022-07-27 12:25:44 +05:30
|
|
|
setOnClickListener(doubleTouchListener)
|
2022-07-19 18:29:16 +05:30
|
|
|
}
|
|
|
|
|
2022-07-15 14:57:04 +05:30
|
|
|
override fun hideController() {
|
|
|
|
super.hideController()
|
2022-07-19 18:29:16 +05:30
|
|
|
setDoubleTapOverlayLayoutParams(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun showController() {
|
|
|
|
setDoubleTapOverlayLayoutParams(90)
|
|
|
|
super.showController()
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the top and bottom margin of the double tap overlay
|
2022-07-21 01:33:09 +05:30
|
|
|
fun setDoubleTapOverlayLayoutParams(margin: Int) {
|
2022-07-19 18:29:16 +05:30
|
|
|
val dpMargin = resources?.displayMetrics?.density!!.toInt() * margin
|
|
|
|
val doubleTapOverlay = binding.root.findViewById<DoubleTapOverlay>(R.id.doubleTapOverlay)
|
|
|
|
val params = doubleTapOverlay.layoutParams as MarginLayoutParams
|
|
|
|
params.topMargin = dpMargin
|
|
|
|
params.bottomMargin = dpMargin
|
|
|
|
doubleTapOverlay.layoutParams = params
|
2022-07-15 14:57:04 +05:30
|
|
|
}
|
|
|
|
|
2021-12-12 20:31:44 +05:30
|
|
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
2022-07-27 12:25:44 +05:30
|
|
|
xPos = event.x
|
|
|
|
doubleTouchListener.onClick(this)
|
2021-12-12 20:31:44 +05:30
|
|
|
return false
|
|
|
|
}
|
2022-05-20 03:52:10 +05:30
|
|
|
}
|