mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
cleanup
This commit is contained in:
parent
37dcef7fce
commit
9066db8b11
@ -60,7 +60,7 @@ import com.github.libretube.extensions.await
|
|||||||
import com.github.libretube.extensions.formatShort
|
import com.github.libretube.extensions.formatShort
|
||||||
import com.github.libretube.extensions.hideKeyboard
|
import com.github.libretube.extensions.hideKeyboard
|
||||||
import com.github.libretube.extensions.toID
|
import com.github.libretube.extensions.toID
|
||||||
import com.github.libretube.interfaces.PlayerViewInterface
|
import com.github.libretube.interfaces.OnlinePlayerOptionsInterface
|
||||||
import com.github.libretube.models.PlayerViewModel
|
import com.github.libretube.models.PlayerViewModel
|
||||||
import com.github.libretube.obj.ChapterSegment
|
import com.github.libretube.obj.ChapterSegment
|
||||||
import com.github.libretube.obj.Segment
|
import com.github.libretube.obj.Segment
|
||||||
@ -399,7 +399,7 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val playerViewInterface = object : PlayerViewInterface {
|
private val playerViewInterface = object : OnlinePlayerOptionsInterface {
|
||||||
override fun onCaptionClicked() {
|
override fun onCaptionClicked() {
|
||||||
if (!this@PlayerFragment::streams.isInitialized ||
|
if (!this@PlayerFragment::streams.isInitialized ||
|
||||||
streams.subtitles == null ||
|
streams.subtitles == null ||
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.github.libretube.interfaces
|
package com.github.libretube.interfaces
|
||||||
|
|
||||||
interface PlayerViewInterface {
|
interface OnlinePlayerOptionsInterface {
|
||||||
fun onCaptionClicked()
|
fun onCaptionClicked()
|
||||||
|
|
||||||
fun onQualityClicked()
|
fun onQualityClicked()
|
@ -4,10 +4,6 @@ interface PlayerOptionsInterface {
|
|||||||
|
|
||||||
fun onAutoplayClicked()
|
fun onAutoplayClicked()
|
||||||
|
|
||||||
fun onCaptionClicked()
|
|
||||||
|
|
||||||
fun onQualityClicked()
|
|
||||||
|
|
||||||
fun onPlaybackSpeedClicked()
|
fun onPlaybackSpeedClicked()
|
||||||
|
|
||||||
fun onResizeModeClicked()
|
fun onResizeModeClicked()
|
||||||
|
@ -2,6 +2,8 @@ package com.github.libretube.views
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
@ -16,8 +18,8 @@ import com.github.libretube.databinding.DoubleTapOverlayBinding
|
|||||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||||
import com.github.libretube.extensions.setSliderRangeAndValue
|
import com.github.libretube.extensions.setSliderRangeAndValue
|
||||||
import com.github.libretube.interfaces.DoubleTapInterface
|
import com.github.libretube.interfaces.DoubleTapInterface
|
||||||
|
import com.github.libretube.interfaces.OnlinePlayerOptionsInterface
|
||||||
import com.github.libretube.interfaces.PlayerOptionsInterface
|
import com.github.libretube.interfaces.PlayerOptionsInterface
|
||||||
import com.github.libretube.interfaces.PlayerViewInterface
|
|
||||||
import com.github.libretube.util.DoubleTapListener
|
import com.github.libretube.util.DoubleTapListener
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelector
|
import com.google.android.exoplayer2.trackselection.TrackSelector
|
||||||
@ -34,12 +36,16 @@ internal class CustomExoPlayerView(
|
|||||||
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
||||||
private var doubleTapOverlayBinding: DoubleTapOverlayBinding? = null
|
private var doubleTapOverlayBinding: DoubleTapOverlayBinding? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Objects from the parent fragment
|
||||||
|
*/
|
||||||
private var doubleTapListener: DoubleTapInterface? = null
|
private var doubleTapListener: DoubleTapInterface? = null
|
||||||
private var playerViewInterface: PlayerViewInterface? = null
|
private var onlinePlayerOptionsInterface: OnlinePlayerOptionsInterface? = null
|
||||||
private lateinit var childFragmentManager: FragmentManager
|
private lateinit var childFragmentManager: FragmentManager
|
||||||
|
|
||||||
private lateinit var trackSelector: TrackSelector
|
private lateinit var trackSelector: TrackSelector
|
||||||
|
|
||||||
|
private val runnableHandler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
// the x-position of where the user clicked
|
// the x-position of where the user clicked
|
||||||
private var xPos = 0F
|
private var xPos = 0F
|
||||||
|
|
||||||
@ -79,12 +85,12 @@ internal class CustomExoPlayerView(
|
|||||||
|
|
||||||
fun initialize(
|
fun initialize(
|
||||||
childFragmentManager: FragmentManager,
|
childFragmentManager: FragmentManager,
|
||||||
playerViewInterface: PlayerViewInterface,
|
playerViewInterface: OnlinePlayerOptionsInterface,
|
||||||
doubleTapOverlayBinding: DoubleTapOverlayBinding,
|
doubleTapOverlayBinding: DoubleTapOverlayBinding,
|
||||||
trackSelector: TrackSelector
|
trackSelector: TrackSelector
|
||||||
) {
|
) {
|
||||||
this.childFragmentManager = childFragmentManager
|
this.childFragmentManager = childFragmentManager
|
||||||
this.playerViewInterface = playerViewInterface
|
this.onlinePlayerOptionsInterface = playerViewInterface
|
||||||
this.doubleTapOverlayBinding = doubleTapOverlayBinding
|
this.doubleTapOverlayBinding = doubleTapOverlayBinding
|
||||||
this.trackSelector = trackSelector
|
this.trackSelector = trackSelector
|
||||||
|
|
||||||
@ -99,8 +105,11 @@ internal class CustomExoPlayerView(
|
|||||||
binding.lockPlayer.setOnClickListener {
|
binding.lockPlayer.setOnClickListener {
|
||||||
// change the locked/unlocked icon
|
// change the locked/unlocked icon
|
||||||
binding.lockPlayer.setImageResource(
|
binding.lockPlayer.setImageResource(
|
||||||
if (!isPlayerLocked) R.drawable.ic_locked
|
if (!isPlayerLocked) {
|
||||||
else R.drawable.ic_unlocked
|
R.drawable.ic_locked
|
||||||
|
} else {
|
||||||
|
R.drawable.ic_unlocked
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// show/hide all the controls
|
// show/hide all the controls
|
||||||
@ -133,7 +142,10 @@ internal class CustomExoPlayerView(
|
|||||||
private fun initializeAdvancedOptions() {
|
private fun initializeAdvancedOptions() {
|
||||||
binding.toggleOptions.setOnClickListener {
|
binding.toggleOptions.setOnClickListener {
|
||||||
val bottomSheetFragment = PlayerOptionsBottomSheet().apply {
|
val bottomSheetFragment = PlayerOptionsBottomSheet().apply {
|
||||||
setOnClickListeners(playerOptionsInterface)
|
setOnClickListeners(
|
||||||
|
playerOptionsInterface,
|
||||||
|
onlinePlayerOptionsInterface
|
||||||
|
)
|
||||||
// set the auto play mode
|
// set the auto play mode
|
||||||
currentAutoplayMode = if (autoplayEnabled) {
|
currentAutoplayMode = if (autoplayEnabled) {
|
||||||
context?.getString(R.string.enabled)
|
context?.getString(R.string.enabled)
|
||||||
@ -215,12 +227,12 @@ internal class CustomExoPlayerView(
|
|||||||
player?.seekTo((player?.currentPosition ?: 0L) - seekIncrement)
|
player?.seekTo((player?.currentPosition ?: 0L) - seekIncrement)
|
||||||
|
|
||||||
// show the rewind button
|
// show the rewind button
|
||||||
doubleTapOverlayBinding?.rewindBTN.apply {
|
doubleTapOverlayBinding?.rewindBTN.run {
|
||||||
visibility = View.VISIBLE
|
this!!.visibility = View.VISIBLE
|
||||||
// clear previous animation
|
// clear previous animation
|
||||||
animate().rotation(0F).setDuration(0).start()
|
this.animate().rotation(0F).setDuration(0).start()
|
||||||
// start new animation
|
// start new animation
|
||||||
animate()
|
this.animate()
|
||||||
.rotation(-30F)
|
.rotation(-30F)
|
||||||
.setDuration(100)
|
.setDuration(100)
|
||||||
.withEndAction {
|
.withEndAction {
|
||||||
@ -229,9 +241,9 @@ internal class CustomExoPlayerView(
|
|||||||
}
|
}
|
||||||
.start()
|
.start()
|
||||||
|
|
||||||
removeCallbacks(hideRewindButtonRunnable)
|
runnableHandler.removeCallbacks(hideRewindButtonRunnable)
|
||||||
// start callback to hide the button
|
// start callback to hide the button
|
||||||
postDelayed(hideRewindButtonRunnable, 700)
|
runnableHandler.postDelayed(hideRewindButtonRunnable, 700)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,9 +254,9 @@ internal class CustomExoPlayerView(
|
|||||||
doubleTapOverlayBinding?.forwardBTN.apply {
|
doubleTapOverlayBinding?.forwardBTN.apply {
|
||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
// clear previous animation
|
// clear previous animation
|
||||||
animate().rotation(0F).setDuration(0).start()
|
this!!.animate().rotation(0F).setDuration(0).start()
|
||||||
// start new animation
|
// start new animation
|
||||||
animate()
|
this.animate()
|
||||||
.rotation(30F)
|
.rotation(30F)
|
||||||
.setDuration(100)
|
.setDuration(100)
|
||||||
.withEndAction {
|
.withEndAction {
|
||||||
@ -254,19 +266,19 @@ internal class CustomExoPlayerView(
|
|||||||
.start()
|
.start()
|
||||||
|
|
||||||
// start callback to hide the button
|
// start callback to hide the button
|
||||||
removeCallbacks(hideForwardButtonRunnable)
|
runnableHandler.removeCallbacks(hideForwardButtonRunnable)
|
||||||
postDelayed(hideForwardButtonRunnable, 700)
|
runnableHandler.postDelayed(hideForwardButtonRunnable, 700)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val hideForwardButtonRunnable = Runnable {
|
private val hideForwardButtonRunnable = Runnable {
|
||||||
doubleTapOverlayBinding?.forwardBTN.apply {
|
doubleTapOverlayBinding?.forwardBTN.apply {
|
||||||
visibility = View.GONE
|
this!!.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private val hideRewindButtonRunnable = Runnable {
|
private val hideRewindButtonRunnable = Runnable {
|
||||||
doubleTapOverlayBinding?.rewindBTN.apply {
|
doubleTapOverlayBinding?.rewindBTN.apply {
|
||||||
visibility = View.GONE
|
this!!.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,14 +301,6 @@ internal class CustomExoPlayerView(
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCaptionClicked() {
|
|
||||||
playerViewInterface?.onCaptionClicked()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onQualityClicked() {
|
|
||||||
playerViewInterface?.onQualityClicked()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPlaybackSpeedClicked() {
|
override fun onPlaybackSpeedClicked() {
|
||||||
val playbackSpeedBinding = DialogSliderBinding.inflate(
|
val playbackSpeedBinding = DialogSliderBinding.inflate(
|
||||||
LayoutInflater.from(context)
|
LayoutInflater.from(context)
|
||||||
|
@ -6,6 +6,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.github.libretube.databinding.BottomSheetBinding
|
import com.github.libretube.databinding.BottomSheetBinding
|
||||||
|
import com.github.libretube.interfaces.OnlinePlayerOptionsInterface
|
||||||
import com.github.libretube.interfaces.PlayerOptionsInterface
|
import com.github.libretube.interfaces.PlayerOptionsInterface
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
@ -17,6 +18,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
|||||||
class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
||||||
lateinit var binding: BottomSheetBinding
|
lateinit var binding: BottomSheetBinding
|
||||||
private lateinit var playerOptionsInterface: PlayerOptionsInterface
|
private lateinit var playerOptionsInterface: PlayerOptionsInterface
|
||||||
|
private var onlinePlayerOptionsInterface: OnlinePlayerOptionsInterface? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* current values
|
* current values
|
||||||
@ -46,13 +48,22 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setOnClickListeners(playerOptionsInterface: PlayerOptionsInterface) {
|
fun setOnClickListeners(
|
||||||
|
playerOptionsInterface: PlayerOptionsInterface,
|
||||||
|
onlinePlayerOptionsInterface: OnlinePlayerOptionsInterface?
|
||||||
|
) {
|
||||||
this.playerOptionsInterface = playerOptionsInterface
|
this.playerOptionsInterface = playerOptionsInterface
|
||||||
|
this.onlinePlayerOptionsInterface = onlinePlayerOptionsInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
if (onlinePlayerOptionsInterface == null) {
|
||||||
|
binding.captions.visibility = View.GONE
|
||||||
|
binding.quality.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update the text if a value is selected
|
* update the text if a value is selected
|
||||||
*/
|
*/
|
||||||
@ -75,7 +86,7 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.quality.setOnClickListener {
|
binding.quality.setOnClickListener {
|
||||||
playerOptionsInterface.onQualityClicked()
|
onlinePlayerOptionsInterface?.onQualityClicked()
|
||||||
this.dismiss()
|
this.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +96,7 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.captions.setOnClickListener {
|
binding.captions.setOnClickListener {
|
||||||
playerOptionsInterface.onCaptionClicked()
|
onlinePlayerOptionsInterface?.onCaptionClicked()
|
||||||
this.dismiss()
|
this.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user