Skip to content

Commit c603c82

Browse files
authored
Merge pull request #12781 from iampopovich/feat/similar-youtube-client-screen-rotation
Remember and restore orientation on fullscreen exit
2 parents 0c17956 + 17ce699 commit c603c82

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public final class VideoDetailFragment
206206
int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
207207
@State
208208
protected boolean autoPlayEnabled = true;
209+
@State
210+
protected int originalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
209211

210212
@Nullable
211213
private StreamInfo currentInfo = null;
@@ -1906,23 +1908,29 @@ public void onFullscreenStateChanged(final boolean fullscreen) {
19061908

19071909
@Override
19081910
public void onScreenRotationButtonClicked() {
1909-
// On Android TV screen rotation is not supported
1910-
// In tablet user experience will be better if screen will not be rotated
1911-
// from landscape to portrait every time.
1912-
// Just turn on fullscreen mode in landscape orientation
1913-
// or portrait & unlocked global orientation
1914-
final boolean isLandscape = DeviceUtils.isLandscape(requireContext());
1915-
if (DeviceUtils.isTv(activity) || DeviceUtils.isTablet(activity)
1916-
&& (!globalScreenOrientationLocked(activity) || isLandscape)) {
1917-
player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen);
1911+
final Optional<MainPlayerUi> playerUi = player != null
1912+
? player.UIs().get(MainPlayerUi.class)
1913+
: Optional.empty();
1914+
if (playerUi.isEmpty()) {
19181915
return;
19191916
}
19201917

1921-
final int newOrientation = isLandscape
1922-
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
1923-
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
1918+
// On tablets and TVs, just toggle fullscreen UI without orientation change.
1919+
if (DeviceUtils.isTablet(activity) || DeviceUtils.isTv(activity)) {
1920+
playerUi.get().toggleFullscreen();
1921+
return;
1922+
}
19241923

1925-
activity.setRequestedOrientation(newOrientation);
1924+
if (playerUi.get().isFullscreen()) {
1925+
// EXITING FULLSCREEN
1926+
playerUi.get().toggleFullscreen();
1927+
activity.setRequestedOrientation(originalOrientation);
1928+
} else {
1929+
// ENTERING FULLSCREEN
1930+
originalOrientation = activity.getRequestedOrientation();
1931+
playerUi.get().toggleFullscreen();
1932+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
1933+
}
19261934
}
19271935

19281936
/*

0 commit comments

Comments
 (0)