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 74609b34e..dc79c69b5 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -3,7 +3,6 @@ package com.github.libretube.activities import android.app.Activity import android.content.Context import android.content.Intent -import android.content.pm.ActivityInfo import android.content.res.Configuration import android.net.Uri import android.os.Build 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 9b06227b2..d24587ed9 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -141,6 +141,8 @@ class PlayerFragment : Fragment() { private lateinit var chapters: List private val sponsorBlockPrefs = SponsorBlockPrefs() + private var autoRotationEnabled = true + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) arguments?.let { @@ -164,9 +166,34 @@ class PlayerFragment : Fragment() { super.onViewCreated(view, savedInstanceState) hideKeyboard() + // save whether auto rotation is enabled + autoRotationEnabled = PreferenceHelper.getBoolean( + requireContext(), + "auto_fullscreen", + true + ) val mainActivity = activity as MainActivity - mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER - onConfigurationChanged(resources.configuration) + if (autoRotationEnabled) { + // enable auto rotation + mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER + onConfigurationChanged(resources.configuration) + } else { + // go to portrait mode + mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + } + + // save whether related streams and autoplay are enabled + autoplay = PreferenceHelper.getBoolean( + requireContext(), + "autoplay", + false + ) + relatedStreamsEnabled = PreferenceHelper.getBoolean( + requireContext(), + "related_streams_toggle", + true + ) + setSponsorBlockPrefs() createExoPlayer(view) initializeTransitionLayout(view) @@ -343,20 +370,23 @@ class PlayerFragment : Fragment() { scaleControls(1.3F) - val orientation = when (fullscreenOrientationPref) { - "ratio" -> { - val videoSize = exoPlayer.videoSize - // probably a youtube shorts video - if (videoSize.height > videoSize.width) ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - // a video with normal aspect ratio - else ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + if (!autoRotationEnabled) { + // different orientations of the video are only available when auto rotation is disabled + val orientation = when (fullscreenOrientationPref) { + "ratio" -> { + val videoSize = exoPlayer.videoSize + // probably a youtube shorts video + if (videoSize.height > videoSize.width) ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + // a video with normal aspect ratio + else ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + } + "auto" -> ActivityInfo.SCREEN_ORIENTATION_USER + "landscape" -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + "portrait" -> ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + else -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE } - "auto" -> ActivityInfo.SCREEN_ORIENTATION_USER - "landscape" -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE - "portrait" -> ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - else -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + mainActivity.requestedOrientation = orientation } - mainActivity.requestedOrientation = orientation Globals.isFullScreen = true } @@ -375,8 +405,11 @@ class PlayerFragment : Fragment() { scaleControls(1F) - val mainActivity = activity as MainActivity - mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER + if (!autoRotationEnabled) { + // switch back to portrait mode if auto rotation disabled + val mainActivity = activity as MainActivity + mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + } Globals.isFullScreen = false } @@ -499,10 +532,6 @@ class PlayerFragment : Fragment() { uploader = response.uploader!! thumbnailUrl = response.thumbnailUrl!! - // save whether related streams and autoplay are enabled - autoplay = PreferenceHelper.getBoolean(requireContext(), "autoplay", false) - relatedStreamsEnabled = - PreferenceHelper.getBoolean(requireContext(), "related_streams_toggle", true) // save related streams for autoplay relatedStreams = response.relatedStreams @@ -1428,14 +1457,7 @@ class PlayerFragment : Fragment() { exoPlayerView.hideController() exoPlayerView.useController = false - // hide anything but the player - binding.linLayout.visibility = View.GONE - binding.mainContainer.isClickable = true - - with(binding.playerMotionLayout) { - getConstraintSet(R.id.start).constrainHeight(R.id.player, -1) - enableTransition(R.id.yt_transition, false) - } + unsetFullscreen() Globals.isFullScreen = false } else { @@ -1464,19 +1486,16 @@ class PlayerFragment : Fragment() { 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() + if (autoRotationEnabled) { + val orientation = newConfig.orientation + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + // go to fullscreen mode + setFullscreen() + } else { + // exit fullscreen if not landscape + unsetFullscreen() + } } } } diff --git a/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt b/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt index f2fdc3fca..e3d014055 100644 --- a/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/PlayerSettings.kt @@ -1,7 +1,9 @@ package com.github.libretube.preferences import android.os.Bundle +import androidx.preference.ListPreference import androidx.preference.PreferenceFragmentCompat +import androidx.preference.SwitchPreferenceCompat import com.github.libretube.R import com.github.libretube.activities.SettingsActivity @@ -13,5 +15,20 @@ class PlayerSettings : PreferenceFragmentCompat() { val settingsActivity = activity as SettingsActivity settingsActivity.changeTopBarText(getString(R.string.audio_video)) + + val playerOrientation = findPreference("fullscreen_orientation") + val autoRotateToFullscreen = findPreference("auto_fullscreen") + + // only show the player orientation option if auto fullscreen is disabled + playerOrientation?.isEnabled != PreferenceHelper.getBoolean( + requireContext(), + "auto_fullscreen", + true + ) + + autoRotateToFullscreen?.setOnPreferenceChangeListener { _, newValue -> + playerOrientation?.isEnabled = newValue != true + true + } } } diff --git a/app/src/main/res/drawable/ic_rotating_circle.xml b/app/src/main/res/drawable/ic_rotating_circle.xml new file mode 100644 index 000000000..7339373fe --- /dev/null +++ b/app/src/main/res/drawable/ic_rotating_circle.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 141527a8f..ac64401d1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -237,4 +237,6 @@ Always Selected Never + Auto fullscreen + Automatically switch to player fullscreen when the device gets turned. \ No newline at end of file diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index dc0efc7b1..da3e50bf4 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -60,16 +60,26 @@ + +