From 5fd26a27a2ddf23e0898c7ab31ad2b387cf80943 Mon Sep 17 00:00:00 2001 From: blackbox87 Date: Fri, 11 Sep 2020 22:24:27 +0100 Subject: [PATCH] Fix rotation when when auto-rotate is disabled --- .../fragments/detail/VideoDetailFragment.java | 12 +++++------- .../org/schabi/newpipe/player/VideoPlayerImpl.java | 9 +++++++++ 2 files changed, 14 insertions(+), 7 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 b731d0270e3..a7165425c25 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 @@ -1421,13 +1421,6 @@ private void restoreDefaultOrientation() { if (player != null && player.isFullscreen()) { player.toggleFullscreen(); } - // This will show systemUI and pause the player. - // User can tap on Play button and video will be in fullscreen mode again - // Note for tablet: trying to avoid orientation changes since it's not easy - // to physically rotate the tablet every time - if (!DeviceUtils.isTablet(activity)) { - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); - } } /*////////////////////////////////////////////////////////////////////////// @@ -1937,6 +1930,11 @@ public void onScreenRotationButtonClicked() { return; } + if (isLandscape() && PlayerHelper.globalScreenOrientationLocked(activity)) { + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + return; + } + final int newOrientation = isLandscape() ? ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index a5758301c6a..9f6e3c2d013 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -743,6 +743,15 @@ public void toggleFullscreen() { return; } + // This makes the button function correctly if you disable auto-rotate + // while watching a vertical video and your phones in landscape + final boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(service); + final boolean isTablet = DeviceUtils.isTablet(service); + if (orientationLocked && isFullscreen && service.isLandscape() && !isTablet) { + fragmentListener.onScreenRotationButtonClicked(); + return; + } + isFullscreen = !isFullscreen; setControlsSize(); fragmentListener.onFullscreenStateChanged(isFullscreen());