Skip to content

Commit a4cc1d1

Browse files
committed
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.
1 parent f836f5e commit a4cc1d1

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

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

Lines changed: 21 additions & 12 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+
private int originalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
209211

210212
@Nullable
211213
private StreamInfo currentInfo = null;
@@ -1900,22 +1902,29 @@ public void onFullscreenStateChanged(final boolean fullscreen) {
19001902

19011903
@Override
19021904
public void onScreenRotationButtonClicked() {
1903-
// In tablet user experience will be better if screen will not be rotated
1904-
// from landscape to portrait every time.
1905-
// Just turn on fullscreen mode in landscape orientation
1906-
// or portrait & unlocked global orientation
1907-
final boolean isLandscape = DeviceUtils.isLandscape(requireContext());
1908-
if (DeviceUtils.isTablet(activity)
1909-
&& (!globalScreenOrientationLocked(activity) || isLandscape)) {
1910-
player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen);
1905+
final Optional<MainPlayerUi> playerUi = player != null
1906+
? player.UIs().get(MainPlayerUi.class)
1907+
: Optional.empty();
1908+
if (playerUi.isEmpty()) {
19111909
return;
19121910
}
19131911

1914-
final int newOrientation = isLandscape
1915-
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
1916-
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
1912+
// On tablets, just toggle fullscreen UI without orientation change.
1913+
if (DeviceUtils.isTablet(activity)) {
1914+
playerUi.get().toggleFullscreen();
1915+
return;
1916+
}
19171917

1918-
activity.setRequestedOrientation(newOrientation);
1918+
if (playerUi.get().isFullscreen()) {
1919+
// EXITING FULLSCREEN
1920+
playerUi.get().toggleFullscreen();
1921+
activity.setRequestedOrientation(originalOrientation);
1922+
} else {
1923+
// ENTERING FULLSCREEN
1924+
originalOrientation = activity.getRequestedOrientation();
1925+
playerUi.get().toggleFullscreen();
1926+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
1927+
}
19191928
}
19201929

19211930
/*

0 commit comments

Comments
 (0)