From 3c432aa49fac491b2299bd53fbc19a64b00f8d6f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 14 Jul 2022 12:15:58 +0200 Subject: [PATCH] basic landscape implementation --- app/src/main/AndroidManifest.xml | 2 +- .../libretube/activities/MainActivity.kt | 3 -- .../libretube/fragments/PlayerFragment.kt | 29 +++++++++++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dbc40491c..8ed717cba 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,7 +37,7 @@ android:exported="true" android:hardwareAccelerated="true" android:launchMode="singleTop" - android:screenOrientation="userPortrait" + android:screenOrientation="user" android:supportsPictureInPicture="true"> diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 1156f1efe..74609b34e 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -84,8 +84,6 @@ class MainActivity : AppCompatActivity() { binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - navController = findNavController(R.id.fragment) binding.bottomNav.setupWithNavController(navController) @@ -290,7 +288,6 @@ class MainActivity : AppCompatActivity() { // set the animation duration motionLayout.setTransitionDuration(250) motionLayout.transitionToEnd() - requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT with(motionLayout) { getConstraintSet(R.id.start).constrainHeight(R.id.player, 0) enableTransition(R.id.yt_transition, true) 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 edcdda4c3..9b06227b2 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -6,6 +6,7 @@ import android.app.PictureInPictureParams import android.content.Context import android.content.Intent import android.content.pm.ActivityInfo +import android.content.res.Configuration import android.graphics.Color import android.graphics.Rect import android.net.Uri @@ -163,6 +164,9 @@ class PlayerFragment : Fragment() { super.onViewCreated(view, savedInstanceState) hideKeyboard() + val mainActivity = activity as MainActivity + mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER + onConfigurationChanged(resources.configuration) setSponsorBlockPrefs() createExoPlayer(view) initializeTransitionLayout(view) @@ -232,7 +236,6 @@ class PlayerFragment : Fragment() { Globals.isMiniPlayerVisible = false binding.playerMotionLayout.transitionToEnd() val mainActivity = activity as MainActivity - mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT mainActivity.supportFragmentManager.beginTransaction() .remove(this) .commit() @@ -241,7 +244,6 @@ class PlayerFragment : Fragment() { Globals.isMiniPlayerVisible = false binding.playerMotionLayout.transitionToEnd() val mainActivity = activity as MainActivity - mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT mainActivity.supportFragmentManager.beginTransaction() .remove(this) .commit() @@ -374,7 +376,7 @@ class PlayerFragment : Fragment() { scaleControls(1F) val mainActivity = activity as MainActivity - mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER Globals.isFullScreen = false } @@ -1435,9 +1437,6 @@ class PlayerFragment : Fragment() { enableTransition(R.id.yt_transition, false) } - val mainActivity = activity as MainActivity - mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - Globals.isFullScreen = false } else { // enable exoPlayer controls again @@ -1462,4 +1461,22 @@ class PlayerFragment : Fragment() { private fun updatePipParams() = PictureInPictureParams.Builder() .setActions(emptyList()) .build() + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + val orientation = newConfig.orientation + + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + // go to fullscreen mode + setFullscreen() + } else { + // leave fullscreen mode + val rotationPref = PreferenceHelper.getString( + requireContext(), + "fullscreen_orientation", + "ratio" + ) + if (rotationPref!! != "portrait") unsetFullscreen() + } + } }