From da8bfe6327f024b56333055b986436dd9c9dc6ea Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 13 Aug 2022 19:06:31 +0200 Subject: [PATCH 1/2] option to disable PiP --- .../com/github/libretube/fragments/PlayerFragment.kt | 7 +++++++ .../com/github/libretube/preferences/PreferenceKeys.kt | 1 + app/src/main/res/drawable/ic_window.xml | 10 ++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/player_settings.xml | 10 ++++++++-- 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_window.xml 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 bcee38708..c80636795 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -1629,6 +1629,13 @@ class PlayerFragment : BaseFragment() { } private fun shouldStartPiP(): Boolean { + val pipEnabled = PreferenceHelper.getBoolean( + PreferenceKeys.PICTURE_IN_PICTURE, + true + ) + + if (!pipEnabled) return false + val bounds = Rect() binding.playerScrollView.getHitRect(bounds) 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 4074128fd..c8e087461 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -59,6 +59,7 @@ object PreferenceKeys { const val PLAYER_AUDIO_QUALITY = "player_audio_quality" const val DEFAULT_SUBTITLE = "default_subtitle" const val SKIP_BUTTONS = "skip_buttons" + const val PICTURE_IN_PICTURE = "picture_in_picture" /** * Background mode diff --git a/app/src/main/res/drawable/ic_window.xml b/app/src/main/res/drawable/ic_window.xml new file mode 100644 index 000000000..e58d327cd --- /dev/null +++ b/app/src/main/res/drawable/ic_window.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6f3ccd18c..5a4bee15d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -312,4 +312,5 @@ Current Backup & restore Backup + Picture in Picture diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index b3b646ed0..660f19e37 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -46,7 +46,7 @@ + + Date: Sat, 13 Aug 2022 19:08:39 +0200 Subject: [PATCH 2/2] cleanup --- .../com/github/libretube/fragments/PlayerFragment.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 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 c80636795..200cdf81f 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -165,6 +165,7 @@ class PlayerFragment : BaseFragment() { private var sponsorBlockEnabled = true private var sponsorBlockNotifications = true private var skipButtonsEnabled = false + private var pipEnabled = true /** * for autoplay @@ -328,6 +329,11 @@ class PlayerFragment : BaseFragment() { PreferenceKeys.SKIP_BUTTONS, false ) + + pipEnabled = PreferenceHelper.getBoolean( + PreferenceKeys.PICTURE_IN_PICTURE, + true + ) } private fun initializeTransitionLayout() { @@ -1629,11 +1635,6 @@ class PlayerFragment : BaseFragment() { } private fun shouldStartPiP(): Boolean { - val pipEnabled = PreferenceHelper.getBoolean( - PreferenceKeys.PICTURE_IN_PICTURE, - true - ) - if (!pipEnabled) return false val bounds = Rect()