mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
viewbind playerview
This commit is contained in:
parent
13ba954c6d
commit
afd71c7c54
@ -80,7 +80,6 @@ import com.google.android.exoplayer2.upstream.DefaultDataSource
|
|||||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
|
||||||
import com.google.android.exoplayer2.util.RepeatModeUtil
|
import com.google.android.exoplayer2.util.RepeatModeUtil
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.card.MaterialCardView
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -233,7 +232,7 @@ class PlayerFragment : Fragment() {
|
|||||||
.remove(this)
|
.remove(this)
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
view.findViewById<ImageButton>(R.id.close_imageButton).setOnClickListener {
|
binding.player.binding.closeImageButton.setOnClickListener {
|
||||||
isMiniPlayerVisible = false
|
isMiniPlayerVisible = false
|
||||||
binding.playerMotionLayout.transitionToEnd()
|
binding.playerMotionLayout.transitionToEnd()
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
@ -261,13 +260,12 @@ class PlayerFragment : Fragment() {
|
|||||||
if (binding.descLinLayout.isVisible) View.GONE else View.VISIBLE
|
if (binding.descLinLayout.isVisible) View.GONE else View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
view.findViewById<MaterialCardView>(R.id.comments_toggle)
|
binding.commentsToggle.setOnClickListener {
|
||||||
.setOnClickListener {
|
|
||||||
toggleComments()
|
toggleComments()
|
||||||
}
|
}
|
||||||
|
|
||||||
val fullScreenButton = view.findViewById<ImageButton>(R.id.fullscreen)
|
val fullScreenButton = binding.player.binding.fullscreen
|
||||||
val exoTitle = view.findViewById<TextView>(R.id.exo_title)
|
val exoTitle = binding.player.binding.exoTitle
|
||||||
|
|
||||||
// FullScreen button trigger
|
// FullScreen button trigger
|
||||||
fullScreenButton.setOnClickListener {
|
fullScreenButton.setOnClickListener {
|
||||||
@ -303,7 +301,8 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// switching between original aspect ratio (black bars) and zoomed to fill device screen
|
// switching between original aspect ratio (black bars) and zoomed to fill device screen
|
||||||
view.findViewById<ImageButton>(R.id.aspect_ratio_button).setOnClickListener {
|
val aspectRatioButton = binding.player.binding.aspectRatioButton
|
||||||
|
aspectRatioButton.setOnClickListener {
|
||||||
if (isZoomed) {
|
if (isZoomed) {
|
||||||
exoPlayerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
|
exoPlayerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
|
||||||
isZoomed = false
|
isZoomed = false
|
||||||
@ -314,7 +313,7 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lock and unlock the player
|
// lock and unlock the player
|
||||||
val lockPlayerButton = view.findViewById<ImageButton>(R.id.lock_player)
|
val lockPlayerButton = binding.player.binding.lockPlayer
|
||||||
lockPlayerButton.setOnClickListener {
|
lockPlayerButton.setOnClickListener {
|
||||||
// change the locked/unlocked icon
|
// change the locked/unlocked icon
|
||||||
if (!isPlayerLocked) {
|
if (!isPlayerLocked) {
|
||||||
@ -630,7 +629,7 @@ class PlayerFragment : Fragment() {
|
|||||||
binding.playerTitle.text = response.title
|
binding.playerTitle.text = response.title
|
||||||
binding.playerDescription.text = response.description
|
binding.playerDescription.text = response.description
|
||||||
|
|
||||||
view.findViewById<TextView>(R.id.exo_title).text = response.title
|
binding.player.binding.exoTitle.text = response.title
|
||||||
|
|
||||||
// Listener for play and pause icon change
|
// Listener for play and pause icon change
|
||||||
exoPlayer.addListener(object : Player.Listener {
|
exoPlayer.addListener(object : Player.Listener {
|
||||||
@ -802,8 +801,8 @@ class PlayerFragment : Fragment() {
|
|||||||
PreferenceHelper.getString(requireContext(), "player_video_format", "WEBM")
|
PreferenceHelper.getString(requireContext(), "player_video_format", "WEBM")
|
||||||
val defres = PreferenceHelper.getString(requireContext(), "default_res", "")!!
|
val defres = PreferenceHelper.getString(requireContext(), "default_res", "")!!
|
||||||
|
|
||||||
val qualityText = view.findViewById<TextView>(R.id.quality_text)
|
val qualityText = binding.player.binding.qualityText
|
||||||
val qualitySelect = view.findViewById<LinearLayout>(R.id.quality_linLayout)
|
val qualitySelect = binding.player.binding.qualitySelect
|
||||||
|
|
||||||
var videosNameArray: Array<CharSequence> = arrayOf()
|
var videosNameArray: Array<CharSequence> = arrayOf()
|
||||||
var videosUrlArray: Array<Uri> = arrayOf()
|
var videosUrlArray: Array<Uri> = arrayOf()
|
||||||
@ -987,12 +986,12 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
private fun lockPlayer(isLocked: Boolean) {
|
private fun lockPlayer(isLocked: Boolean) {
|
||||||
val visibility = if (isLocked) View.VISIBLE else View.INVISIBLE
|
val visibility = if (isLocked) View.VISIBLE else View.INVISIBLE
|
||||||
exoPlayerView.findViewById<LinearLayout>(R.id.exo_top_bar_right).visibility = visibility
|
binding.player.binding.exoTopBarRight.visibility = visibility
|
||||||
exoPlayerView.findViewById<ImageButton>(R.id.exo_play_pause).visibility = visibility
|
binding.player.binding.exoPlayPause.visibility = visibility
|
||||||
exoPlayerView.findViewById<Button>(R.id.exo_ffwd_with_amount).visibility = visibility
|
binding.player.binding.exoFfwdWithAmount.visibility = visibility
|
||||||
exoPlayerView.findViewById<Button>(R.id.exo_rew_with_amount).visibility = visibility
|
binding.player.binding.exoRewWithAmount.visibility = visibility
|
||||||
exoPlayerView.findViewById<FrameLayout>(R.id.exo_bottom_bar).visibility = visibility
|
binding.player.binding.exoBottomBar.visibility = visibility
|
||||||
exoPlayerView.findViewById<TextView>(R.id.exo_title).visibility =
|
binding.player.binding.exoTitle.visibility =
|
||||||
if (isLocked && isFullScreen) View.VISIBLE else View.INVISIBLE
|
if (isLocked && isFullScreen) View.VISIBLE else View.INVISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1154,7 +1153,7 @@ class PlayerFragment : Fragment() {
|
|||||||
enableTransition(R.id.yt_transition, false)
|
enableTransition(R.id.yt_transition, false)
|
||||||
}
|
}
|
||||||
binding.mainContainer.isClickable = true
|
binding.mainContainer.isClickable = true
|
||||||
view?.findViewById<LinearLayout>(R.id.exo_top_bar)?.visibility = View.GONE
|
binding.player.binding.exoTopBar.visibility = View.GONE
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
isFullScreen = false
|
isFullScreen = false
|
||||||
@ -1166,7 +1165,7 @@ class PlayerFragment : Fragment() {
|
|||||||
exoPlayerView.showController()
|
exoPlayerView.showController()
|
||||||
exoPlayerView.useController = true
|
exoPlayerView.useController = true
|
||||||
binding.mainContainer.isClickable = false
|
binding.mainContainer.isClickable = false
|
||||||
view?.findViewById<LinearLayout>(R.id.exo_top_bar)?.visibility = View.VISIBLE
|
binding.player.binding.exoTopBar.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,14 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||||
import com.google.android.exoplayer2.ui.StyledPlayerView
|
import com.google.android.exoplayer2.ui.StyledPlayerView
|
||||||
|
|
||||||
internal class CustomExoPlayerView(
|
internal class CustomExoPlayerView(
|
||||||
context: Context,
|
context: Context,
|
||||||
attributeSet: AttributeSet? = null
|
attributeSet: AttributeSet? = null
|
||||||
) : StyledPlayerView(context, attributeSet) {
|
) : StyledPlayerView(context, attributeSet) {
|
||||||
|
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user