@@ -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 ;
@@ -1908,29 +1906,23 @@ public void onFullscreenStateChanged(final boolean fullscreen) {
19081906
19091907 @ Override
19101908 public void onScreenRotationButtonClicked () {
1911- final Optional <MainPlayerUi > playerUi = player != null
1912- ? player .UIs ().get (MainPlayerUi .class )
1913- : Optional .empty ();
1914- if (playerUi .isEmpty ()) {
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 );
19151918 return ;
19161919 }
19171920
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- }
1921+ final int newOrientation = isLandscape
1922+ ? ActivityInfo .SCREEN_ORIENTATION_PORTRAIT
1923+ : ActivityInfo .SCREEN_ORIENTATION_SENSOR_LANDSCAPE ;
19231924
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- }
1925+ activity .setRequestedOrientation (newOrientation );
19341926 }
19351927
19361928 /*
0 commit comments