From 49e95d95a15abb021db79ce6f7b0514dbe22e6b2 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 28 Jan 2026 01:44:39 +0100 Subject: [PATCH] Revert "Remember and restore orientation on fullscreen exit" --- .../fragments/detail/VideoDetailFragment.java | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 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 9bffa149c..a07e9c06e 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,8 +206,6 @@ public final class VideoDetailFragment int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED; @State protected boolean autoPlayEnabled = true; - @State - protected int originalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; @Nullable private StreamInfo currentInfo = null; @@ -1908,29 +1906,23 @@ public final class VideoDetailFragment @Override public void onScreenRotationButtonClicked() { - final Optional playerUi = player != null - ? player.UIs().get(MainPlayerUi.class) - : Optional.empty(); - if (playerUi.isEmpty()) { + // On Android TV screen rotation is not supported + // 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.isTv(activity) || DeviceUtils.isTablet(activity) + && (!globalScreenOrientationLocked(activity) || isLandscape)) { + player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen); return; } - // On tablets and TVs, just toggle fullscreen UI without orientation change. - if (DeviceUtils.isTablet(activity) || DeviceUtils.isTv(activity)) { - playerUi.get().toggleFullscreen(); - return; - } + final int newOrientation = isLandscape + ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; - 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); - } + activity.setRequestedOrientation(newOrientation); } /*