Merge pull request #12781 from iampopovich/feat/similar-youtube-client-screen-rotation

Remember and restore orientation on fullscreen exit
This commit is contained in:
Tobi 2025-12-14 04:43:19 -08:00 committed by GitHub
commit d83b4b2a36

View file

@ -206,6 +206,8 @@ public final class VideoDetailFragment
int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED; int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
@State @State
protected boolean autoPlayEnabled = true; protected boolean autoPlayEnabled = true;
@State
protected int originalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
@Nullable @Nullable
private StreamInfo currentInfo = null; private StreamInfo currentInfo = null;
@ -1906,23 +1908,29 @@ public final class VideoDetailFragment
@Override @Override
public void onScreenRotationButtonClicked() { public void onScreenRotationButtonClicked() {
// On Android TV screen rotation is not supported final Optional<MainPlayerUi> playerUi = player != null
// In tablet user experience will be better if screen will not be rotated ? player.UIs().get(MainPlayerUi.class)
// from landscape to portrait every time. : Optional.empty();
// Just turn on fullscreen mode in landscape orientation if (playerUi.isEmpty()) {
// 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; return;
} }
final int newOrientation = isLandscape // On tablets and TVs, just toggle fullscreen UI without orientation change.
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT if (DeviceUtils.isTablet(activity) || DeviceUtils.isTv(activity)) {
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; 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);
}
} }
/* /*