From 769d09f98db48bb0d52a7b716d9732b94288baab Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Tue, 6 Dec 2022 12:40:56 +0530 Subject: [PATCH 1/2] Fix subtitles cropped in zoom mode --- .../github/libretube/ui/views/CustomExoPlayerView.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 6ae88e956..71bf0e8e6 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -33,6 +33,7 @@ import com.google.android.exoplayer2.Player import com.google.android.exoplayer2.trackselection.TrackSelector import com.google.android.exoplayer2.ui.AspectRatioFrameLayout import com.google.android.exoplayer2.ui.StyledPlayerView +import com.google.android.exoplayer2.ui.SubtitleView import com.google.android.exoplayer2.util.RepeatModeUtil @SuppressLint("ClickableViewAccessibility") @@ -511,19 +512,28 @@ internal class CustomExoPlayerView( override fun onZoom() { if (!PlayerHelper.pinchGestureEnabled) return resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM + + if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { + subtitleView?.setBottomPaddingFraction(0.158f) + } } override fun onMinimize() { if (!PlayerHelper.pinchGestureEnabled) return resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT + subtitleView?.setBottomPaddingFraction(SubtitleView.DEFAULT_BOTTOM_PADDING_FRACTION) } override fun onFullscreenChange(isFullscreen: Boolean) { if (PlayerHelper.swipeGestureEnabled && this::brightnessHelper.isInitialized) { if (isFullscreen) { brightnessHelper.restoreSavedBrightness() + if (resizeMode == AspectRatioFrameLayout.RESIZE_MODE_ZOOM) { + subtitleView?.setBottomPaddingFraction(0.158f) + } } else { brightnessHelper.resetToSystemBrightness(false) + subtitleView?.setBottomPaddingFraction(SubtitleView.DEFAULT_BOTTOM_PADDING_FRACTION) } } } From 545749434013ee957a4a234f6b41b33ebbe7a3dc Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Tue, 6 Dec 2022 14:20:56 +0530 Subject: [PATCH 2/2] Use constant for subtitle padding fraction --- .../com/github/libretube/ui/views/CustomExoPlayerView.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 71bf0e8e6..fd8b3fce4 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -514,7 +514,7 @@ internal class CustomExoPlayerView( resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { - subtitleView?.setBottomPaddingFraction(0.158f) + subtitleView?.setBottomPaddingFraction(SUBTITLE_BOTTOM_PADDING_FRACTION) } } @@ -529,7 +529,7 @@ internal class CustomExoPlayerView( if (isFullscreen) { brightnessHelper.restoreSavedBrightness() if (resizeMode == AspectRatioFrameLayout.RESIZE_MODE_ZOOM) { - subtitleView?.setBottomPaddingFraction(0.158f) + subtitleView?.setBottomPaddingFraction(SUBTITLE_BOTTOM_PADDING_FRACTION) } } else { brightnessHelper.resetToSystemBrightness(false) @@ -537,4 +537,8 @@ internal class CustomExoPlayerView( } } } + + companion object { + private const val SUBTITLE_BOTTOM_PADDING_FRACTION = 0.158f + } }