From a4cc1d1ddfa31a24813f17e53935501035ddb574 Mon Sep 17 00:00:00 2001 From: Alex Popov Date: Mon, 10 Nov 2025 02:22:56 +0700 Subject: [PATCH 1/3] feat(player): Remember and restore orientation on fullscreen exit - Store the original screen orientation when entering fullscreen. - Restore the saved orientation when exiting fullscreen. - On tablets, continue to just toggle the fullscreen UI without changing the device orientation. --- .../fragments/detail/VideoDetailFragment.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 7b870556569..7c1d46945ef 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -206,6 +206,8 @@ public final class VideoDetailFragment int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED; @State protected boolean autoPlayEnabled = true; + @State + private int originalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; @Nullable private StreamInfo currentInfo = null; @@ -1900,22 +1902,29 @@ public void onFullscreenStateChanged(final boolean fullscreen) { @Override public void onScreenRotationButtonClicked() { - // In tablet user experience will be better if screen will not be rotated - // from landscape to portrait every time. - // Just turn on fullscreen mode in landscape orientation - // or portrait & unlocked global orientation - final boolean isLandscape = DeviceUtils.isLandscape(requireContext()); - if (DeviceUtils.isTablet(activity) - && (!globalScreenOrientationLocked(activity) || isLandscape)) { - player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen); + final Optional playerUi = player != null + ? player.UIs().get(MainPlayerUi.class) + : Optional.empty(); + if (playerUi.isEmpty()) { return; } - final int newOrientation = isLandscape - ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; + // On tablets, just toggle fullscreen UI without orientation change. + if (DeviceUtils.isTablet(activity)) { + playerUi.get().toggleFullscreen(); + return; + } - activity.setRequestedOrientation(newOrientation); + if (playerUi.get().isFullscreen()) { + // EXITING FULLSCREEN + playerUi.get().toggleFullscreen(); + activity.setRequestedOrientation(originalOrientation); + } else { + // ENTERING FULLSCREEN + originalOrientation = activity.getRequestedOrientation(); + playerUi.get().toggleFullscreen(); + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); + } } /* From d770c6fd880a6a97ba242a2665c423351dde5360 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Wed, 10 Dec 2025 14:46:13 +0100 Subject: [PATCH 2/3] Fix state access --- .../schabi/newpipe/fragments/detail/VideoDetailFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 7c1d46945ef..5ef4b3f1e0f 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -207,7 +207,7 @@ public final class VideoDetailFragment @State protected boolean autoPlayEnabled = true; @State - private int originalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; + protected int originalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; @Nullable private StreamInfo currentInfo = null; From 17ce699037daa8a89387f40c45008ad955b3fd89 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Wed, 10 Dec 2025 14:48:08 +0100 Subject: [PATCH 3/3] Do not change orientation on TVs when entering fullscreen --- .../schabi/newpipe/fragments/detail/VideoDetailFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 5ef4b3f1e0f..c3b7dc8a31f 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -1909,8 +1909,8 @@ public void onScreenRotationButtonClicked() { return; } - // On tablets, just toggle fullscreen UI without orientation change. - if (DeviceUtils.isTablet(activity)) { + // On tablets and TVs, just toggle fullscreen UI without orientation change. + if (DeviceUtils.isTablet(activity) || DeviceUtils.isTv(activity)) { playerUi.get().toggleFullscreen(); return; }