From 6694eb972e2c5a7e860794d2e653ef34866478a8 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 14 Aug 2022 17:53:51 +0200 Subject: [PATCH] add resize mode pref --- .../github/libretube/api/ResettableLazy.kt | 2 +- .../libretube/fragments/PlayerFragment.kt | 23 ++++++++++++------- .../interfaces/PlayerOptionsInterface.kt | 2 +- .../libretube/preferences/PreferenceKeys.kt | 1 + .../views/PlayerOptionsBottomSheet.kt | 8 +++---- app/src/main/res/drawable/ic_zoom.xml | 10 ++++++++ app/src/main/res/layout/bottom_sheet.xml | 4 ++-- app/src/main/res/values/array.xml | 12 ++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/player_settings.xml | 9 ++++++++ 10 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 app/src/main/res/drawable/ic_zoom.xml diff --git a/app/src/main/java/com/github/libretube/api/ResettableLazy.kt b/app/src/main/java/com/github/libretube/api/ResettableLazy.kt index 432dff009..129e27de6 100644 --- a/app/src/main/java/com/github/libretube/api/ResettableLazy.kt +++ b/app/src/main/java/com/github/libretube/api/ResettableLazy.kt @@ -1,7 +1,7 @@ package com.github.libretube.util -import kotlin.reflect.KProperty import java.util.* +import kotlin.reflect.KProperty class ResettableLazyManager { // we synchronize to make sure the timing of a reset() call and new inits do not collide 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 54e9363b9..37407e5e4 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -92,7 +92,6 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSource import com.google.android.exoplayer2.util.RepeatModeUtil import com.google.android.exoplayer2.video.VideoSize import com.google.android.material.dialog.MaterialAlertDialogBuilder -import kotlin.math.abs import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -100,6 +99,7 @@ import org.chromium.net.CronetEngine import retrofit2.HttpException import java.io.IOException import java.util.concurrent.Executors +import kotlin.math.abs class PlayerFragment : BaseFragment() { @@ -168,6 +168,7 @@ class PlayerFragment : BaseFragment() { private var sponsorBlockNotifications = true private var skipButtonsEnabled = false private var pipEnabled = true + private var resizeModePref = "fit" /** * for autoplay @@ -336,6 +337,11 @@ class PlayerFragment : BaseFragment() { PreferenceKeys.PICTURE_IN_PICTURE, true ) + + resizeModePref = PreferenceHelper.getString( + PreferenceKeys.PLAYER_RESIZE_MODE, + "fit" + ) } private fun initializeTransitionLayout() { @@ -513,13 +519,9 @@ class PlayerFragment : BaseFragment() { .show() } - override fun onAspectRatioClicked() { + override fun onResizeModeClicked() { // switching between original aspect ratio (black bars) and zoomed to fill device screen - val aspectRatioModeNames = arrayOf( - context?.getString(R.string.resize_mode_fit), - context?.getString(R.string.resize_mode_zoom), - context?.getString(R.string.resize_mode_fill) - ) + val aspectRatioModeNames = context?.resources?.getStringArray(R.array.resizeMode) val aspectRatioModes = arrayOf( AspectRatioFrameLayout.RESIZE_MODE_FIT, @@ -605,7 +607,7 @@ class PlayerFragment : BaseFragment() { context.getString(R.string.repeat_mode_none) } else context.getString(R.string.repeat_mode_current) // set the aspect ratio mode - currentAspectRatio = when (exoPlayerView.resizeMode) { + currentResizeMode = when (exoPlayerView.resizeMode) { AspectRatioFrameLayout.RESIZE_MODE_FIT -> context.getString(R.string.resize_mode_fit) AspectRatioFrameLayout.RESIZE_MODE_FILL -> context.getString(R.string.resize_mode_fill) else -> context.getString(R.string.resize_mode_zoom) @@ -979,6 +981,11 @@ class PlayerFragment : BaseFragment() { controllerHideOnTouch = true useController = false player = exoPlayer + resizeMode = when (resizeModePref) { + "fill" -> AspectRatioFrameLayout.RESIZE_MODE_FILL + "zoom" -> AspectRatioFrameLayout.RESIZE_MODE_ZOOM + else -> AspectRatioFrameLayout.RESIZE_MODE_FIT + } } if (useSystemCaptionStyle) { diff --git a/app/src/main/java/com/github/libretube/interfaces/PlayerOptionsInterface.kt b/app/src/main/java/com/github/libretube/interfaces/PlayerOptionsInterface.kt index 1f7bfbcb1..fe5d7377f 100644 --- a/app/src/main/java/com/github/libretube/interfaces/PlayerOptionsInterface.kt +++ b/app/src/main/java/com/github/libretube/interfaces/PlayerOptionsInterface.kt @@ -10,7 +10,7 @@ interface PlayerOptionsInterface { fun onPlaybackSpeedClicked() - fun onAspectRatioClicked() + fun onResizeModeClicked() fun onRepeatModeClicked() } diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt index 90809cbf9..fa3fdff01 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -67,6 +67,7 @@ object PreferenceKeys { const val DEFAULT_SUBTITLE = "default_subtitle" const val SKIP_BUTTONS = "skip_buttons" const val PICTURE_IN_PICTURE = "picture_in_picture" + const val PLAYER_RESIZE_MODE = "player_resize_mode" /** * Background mode diff --git a/app/src/main/java/com/github/libretube/views/PlayerOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/views/PlayerOptionsBottomSheet.kt index bf3fb6784..ece3d1865 100644 --- a/app/src/main/java/com/github/libretube/views/PlayerOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/views/PlayerOptionsBottomSheet.kt @@ -25,7 +25,7 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() { var currentAutoplayMode: String? = null var currentRepeatMode: String? = null var currentQuality: String? = null - var currentAspectRatio: String? = null + var currentResizeMode: String? = null var currentCaptions: String? = null override fun onCreateView( @@ -67,10 +67,10 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() { binding.repeatMode.updateText(currentRepeatMode) - binding.aspectRatio.updateText(currentAspectRatio) + binding.resizeMode.updateText(currentResizeMode) - binding.aspectRatio.setOnClickListener { - playerOptionsInterface.onAspectRatioClicked() + binding.resizeMode.setOnClickListener { + playerOptionsInterface.onResizeModeClicked() this.dismiss() } diff --git a/app/src/main/res/drawable/ic_zoom.xml b/app/src/main/res/drawable/ic_zoom.xml new file mode 100644 index 000000000..403fd50e1 --- /dev/null +++ b/app/src/main/res/drawable/ic_zoom.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/bottom_sheet.xml b/app/src/main/res/layout/bottom_sheet.xml index 52e139875..101a1569f 100644 --- a/app/src/main/res/layout/bottom_sheet.xml +++ b/app/src/main/res/layout/bottom_sheet.xml @@ -39,8 +39,8 @@ app:drawableStartCompat="@drawable/ic_repeat" /> \ No newline at end of file diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 7aaf15a4b..7488678f1 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -846,4 +846,16 @@ 120 + + @string/resize_mode_fit + @string/resize_mode_zoom + @string/resize_mode_fill + + + + fit + zoom + fill + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5a4bee15d..a096ddd64 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -313,4 +313,5 @@ Backup & restore Backup Picture in Picture + Resize mode diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index 660f19e37..f7f9439dd 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -77,6 +77,15 @@ app:key="default_subtitle" app:title="@string/default_subtitle_language" /> + +