LibreTube/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt

61 lines
2.0 KiB
Kotlin
Raw Normal View History

2022-07-02 21:53:24 +05:30
package com.github.libretube.views
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
2022-07-15 14:57:04 +05:30
import android.view.View
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
2021-12-14 02:58:17 +05:30
import com.google.android.exoplayer2.ui.StyledPlayerView
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)
2022-07-19 18:29:16 +05:30
init {
setControllerVisibilityListener {
// hide the advanced options
binding.toggleOptions.animate().rotationX(0F).setDuration(0).start()
binding.advancedOptions.visibility = View.GONE
}
}
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
private fun setDoubleTapOverlayLayoutParams(margin: Int) {
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
}
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
2021-12-14 21:45:53 +05:30
if (isControllerFullyVisible) {
hideController()
2022-05-20 03:52:10 +05:30
} else {
2021-12-14 21:45:53 +05:30
showController()
}
}
}
return false
}
2022-05-20 03:52:10 +05:30
}