From 7868695987eb3bc01cc744444e7ece00aa7a70e0 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 1 May 2024 16:12:21 +0200 Subject: [PATCH] fix: activity is sometimes unnecessarily restarted --- .../libretube/ui/fragments/PlayerFragment.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 22a094468..62bf890ac 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -354,6 +354,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { } } + private val lockedOrientations = listOf( + ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT, + ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + ) + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val playerData = requireArguments().parcelable(IntentData.playerData)!! @@ -716,8 +721,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { openOrCloseFullscreenDialog(false) updateResolutionOnFullscreenChange(false) - restartActivityIfNeeded() - binding.player.updateMarginsByFullscreenMode() updateFullscreenButtonVisibility() @@ -1599,12 +1602,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { * If true, the activity will be automatically restarted */ private fun restartActivityIfNeeded() { - val lockedOrientations = - listOf( - ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT, - ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE - ) - if (mainActivity.screenOrientationPref in lockedOrientations) return + if (mainActivity.screenOrientationPref in lockedOrientations || viewModel.isOrientationChangeInProgress) return val orientation = resources.configuration.orientation if (viewModel.isFullscreen.value != true && orientation != playerLayoutOrientation) {