Skip to content

Commit 635b306

Browse files
authored
Merge pull request #13134 from TeamNewPipe/revert-12781-feat/similar-youtube-client-screen-rotation
2 parents 11af6a2 + 49e95d9 commit 635b306

1 file changed

Lines changed: 13 additions & 21 deletions

File tree

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ 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;
211209

212210
@Nullable
213211
private StreamInfo currentInfo = null;
@@ -1910,29 +1908,23 @@ public void onFullscreenStateChanged(final boolean fullscreen) {
19101908

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

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

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

19381930
/*

0 commit comments

Comments
 (0)