From afd71c7c5417a84f5306868ef216ca81c460c1ef Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 1 Jul 2022 15:12:00 +0200 Subject: [PATCH 1/4] viewbind playerview --- .../libretube/fragments/PlayerFragment.kt | 37 +++++++++---------- .../libretube/util/CustomExoPlayerView.kt | 2 + 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 6e7b0186e..4681913f9 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -80,7 +80,6 @@ import com.google.android.exoplayer2.upstream.DefaultDataSource import com.google.android.exoplayer2.upstream.DefaultHttpDataSource import com.google.android.exoplayer2.util.RepeatModeUtil import com.google.android.material.button.MaterialButton -import com.google.android.material.card.MaterialCardView import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.squareup.picasso.Picasso import kotlinx.coroutines.CoroutineScope @@ -233,7 +232,7 @@ class PlayerFragment : Fragment() { .remove(this) .commit() } - view.findViewById(R.id.close_imageButton).setOnClickListener { + binding.player.binding.closeImageButton.setOnClickListener { isMiniPlayerVisible = false binding.playerMotionLayout.transitionToEnd() val mainActivity = activity as MainActivity @@ -261,13 +260,12 @@ class PlayerFragment : Fragment() { if (binding.descLinLayout.isVisible) View.GONE else View.VISIBLE } - view.findViewById(R.id.comments_toggle) - .setOnClickListener { + binding.commentsToggle.setOnClickListener { toggleComments() } - val fullScreenButton = view.findViewById(R.id.fullscreen) - val exoTitle = view.findViewById(R.id.exo_title) + val fullScreenButton = binding.player.binding.fullscreen + val exoTitle = binding.player.binding.exoTitle // FullScreen button trigger fullScreenButton.setOnClickListener { @@ -303,7 +301,8 @@ class PlayerFragment : Fragment() { } // switching between original aspect ratio (black bars) and zoomed to fill device screen - view.findViewById(R.id.aspect_ratio_button).setOnClickListener { + val aspectRatioButton = binding.player.binding.aspectRatioButton + aspectRatioButton.setOnClickListener { if (isZoomed) { exoPlayerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT isZoomed = false @@ -314,7 +313,7 @@ class PlayerFragment : Fragment() { } // lock and unlock the player - val lockPlayerButton = view.findViewById(R.id.lock_player) + val lockPlayerButton = binding.player.binding.lockPlayer lockPlayerButton.setOnClickListener { // change the locked/unlocked icon if (!isPlayerLocked) { @@ -630,7 +629,7 @@ class PlayerFragment : Fragment() { binding.playerTitle.text = response.title binding.playerDescription.text = response.description - view.findViewById(R.id.exo_title).text = response.title + binding.player.binding.exoTitle.text = response.title // Listener for play and pause icon change exoPlayer.addListener(object : Player.Listener { @@ -802,8 +801,8 @@ class PlayerFragment : Fragment() { PreferenceHelper.getString(requireContext(), "player_video_format", "WEBM") val defres = PreferenceHelper.getString(requireContext(), "default_res", "")!! - val qualityText = view.findViewById(R.id.quality_text) - val qualitySelect = view.findViewById(R.id.quality_linLayout) + val qualityText = binding.player.binding.qualityText + val qualitySelect = binding.player.binding.qualitySelect var videosNameArray: Array = arrayOf() var videosUrlArray: Array = arrayOf() @@ -987,12 +986,12 @@ class PlayerFragment : Fragment() { private fun lockPlayer(isLocked: Boolean) { val visibility = if (isLocked) View.VISIBLE else View.INVISIBLE - exoPlayerView.findViewById(R.id.exo_top_bar_right).visibility = visibility - exoPlayerView.findViewById(R.id.exo_play_pause).visibility = visibility - exoPlayerView.findViewById