From 20d78688cd7e12d1db7ac3ba2e3f3d7f1c848b30 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 8 Nov 2025 13:53:06 -0700 Subject: [PATCH 1/5] Lock orientation when using the rotate button Fixes #2026 --- .../com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index 186369e4f4..a1d5f03b0f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -142,6 +142,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() { protected var doubleTapEnabled = false protected var doubleTapPauseEnabled = true protected var playerRotateEnabled = false + protected var manualOrientation = false protected var autoPlayerRotateEnabled = false private var hideControlsNames = false protected var speedupEnabled = false @@ -447,7 +448,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() { private fun updateOrientation(ignoreDynamicOrientation: Boolean = false) { activity?.apply { if (lockRotation) { - if (isLocked) { + if (isLocked || manualOrientation) { lockOrientation(this) } else { if (ignoreDynamicOrientation) { @@ -2027,6 +2028,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() { private fun toggleRotate() { activity?.let { toggleOrientationWithSensor(it) + manualOrientation = true } } From 843ad6971b37e0aaaecf07631c3f8596a6be8a43 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:44:47 -0700 Subject: [PATCH 2/5] Still allow reverse rotation --- .../ui/player/FullScreenPlayer.kt | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index a1d5f03b0f..a4449677d9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -142,7 +142,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() { protected var doubleTapEnabled = false protected var doubleTapPauseEnabled = true protected var playerRotateEnabled = false - protected var manualOrientation = false + protected var rotatedManually = false protected var autoPlayerRotateEnabled = false private var hideControlsNames = false protected var speedupEnabled = false @@ -417,39 +417,54 @@ open class FullScreenPlayer : AbstractPlayerFragment() { activity.requestedOrientation = orientation } - open fun lockOrientation(activity: Activity) { - @Suppress("DEPRECATION") - val display = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) + open fun lockOrientation(activity: Activity, allowReverse: Boolean = false) { + val display = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + @Suppress("DEPRECATION") (activity.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay - else activity.display!! + } else activity.display!! + val rotation = display.rotation val currentOrientation = activity.resources.configuration.orientation val orientation: Int + when (currentOrientation) { - Configuration.ORIENTATION_LANDSCAPE -> - orientation = - if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) + Configuration.ORIENTATION_LANDSCAPE -> { + orientation = if (allowReverse) { + // Allow both landscape and reverse landscape + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + } else { + // Lock to current landscape direction only + if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE - else - ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE + } else ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE + } + } - Configuration.ORIENTATION_PORTRAIT -> - orientation = - if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) + Configuration.ORIENTATION_PORTRAIT -> { + orientation = if (allowReverse) { + // Allow both portrait and reverse portrait + ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT + } else { + // Lock to current portrait direction only + if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) { ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - else - ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT + } else ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT + } + } else -> orientation = dynamicOrientation() } + activity.requestedOrientation = orientation } private fun updateOrientation(ignoreDynamicOrientation: Boolean = false) { activity?.apply { if (lockRotation) { - if (isLocked || manualOrientation) { - lockOrientation(this) + if (isLocked || rotatedManually) { + // Allow flipping with manual rotation but lock + // between portrait and landscape. + lockOrientation(this, rotatedManually) } else { if (ignoreDynamicOrientation) { // restore when lock is disabled @@ -2028,7 +2043,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() { private fun toggleRotate() { activity?.let { toggleOrientationWithSensor(it) - manualOrientation = true + rotatedManually = true } } From fe43099d07294f175ddcee43f00b9df9026c24d5 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:51:50 -0700 Subject: [PATCH 3/5] Fix conflict with locking --- .../com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index a4449677d9..a41e6bff28 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -464,7 +464,9 @@ open class FullScreenPlayer : AbstractPlayerFragment() { if (isLocked || rotatedManually) { // Allow flipping with manual rotation but lock // between portrait and landscape. - lockOrientation(this, rotatedManually) + // Allow reverse rotation within the same orientation (landscape to reverse landscape + // or portrait to reverse portrait) only when manually rotated and not fully locked. + lockOrientation(this, rotatedManually && !isLocked) } else { if (ignoreDynamicOrientation) { // restore when lock is disabled From ff56808dcbe8f3bd8f0585f5be600c142de6c324 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 8 Nov 2025 15:41:02 -0700 Subject: [PATCH 4/5] Remove accidental duplicate comment --- .../com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index a41e6bff28..670b6e07e9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -462,8 +462,6 @@ open class FullScreenPlayer : AbstractPlayerFragment() { activity?.apply { if (lockRotation) { if (isLocked || rotatedManually) { - // Allow flipping with manual rotation but lock - // between portrait and landscape. // Allow reverse rotation within the same orientation (landscape to reverse landscape // or portrait to reverse portrait) only when manually rotated and not fully locked. lockOrientation(this, rotatedManually && !isLocked) From 03c3af65b8bbc1c59422001a702ba2680105aca9 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Tue, 11 Nov 2025 16:33:30 -0700 Subject: [PATCH 5/5] Use better method --- .../ui/player/FullScreenPlayer.kt | 49 +++++++------------ 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index b32f1c34e8..fb5acb6fd4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -417,56 +417,41 @@ open class FullScreenPlayer : AbstractPlayerFragment() { activity.requestedOrientation = orientation } - open fun lockOrientation(activity: Activity, allowReverse: Boolean = false) { - val display = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { - @Suppress("DEPRECATION") + open fun lockOrientation(activity: Activity) { + @Suppress("DEPRECATION") + val display = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) (activity.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay - } else activity.display!! - + else activity.display!! val rotation = display.rotation val currentOrientation = activity.resources.configuration.orientation val orientation: Int - when (currentOrientation) { - Configuration.ORIENTATION_LANDSCAPE -> { - orientation = if (allowReverse) { - // Allow both landscape and reverse landscape - ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE - } else { - // Lock to current landscape direction only - if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { + Configuration.ORIENTATION_LANDSCAPE -> + orientation = + if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE - } else ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE - } - } + else + ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE - Configuration.ORIENTATION_PORTRAIT -> { - orientation = if (allowReverse) { - // Allow both portrait and reverse portrait - ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT - } else { - // Lock to current portrait direction only - if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) { + Configuration.ORIENTATION_PORTRAIT -> + orientation = + if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - } else ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT - } - } + else + ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT else -> orientation = dynamicOrientation() } - activity.requestedOrientation = orientation } private fun updateOrientation(ignoreDynamicOrientation: Boolean = false) { activity?.apply { if (lockRotation) { - if (isLocked || rotatedManually) { - // Allow reverse rotation within the same orientation (landscape to reverse landscape - // or portrait to reverse portrait) only when manually rotated and not fully locked. - lockOrientation(this, rotatedManually && !isLocked) + if (isLocked) { + lockOrientation(this) } else { - if (ignoreDynamicOrientation) { + if (ignoreDynamicOrientation || rotatedManually) { // restore when lock is disabled restoreOrientationWithSensor(this) } else {