Skip to content

Commit

Permalink
Fix restoring orientation in onBack
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Sep 19, 2021
1 parent 9346f9b commit 7667b2c
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -742,20 +742,19 @@ public boolean onBackPressed() {
&& player.getPlayQueue() != null
&& player.videoPlayerSelected()
&& player.getPlayQueue().previous()) {
return true;
return true; // no code here, as previous() was used in the if
}

// That means that we are on the start of the stack,
// return false to let the MainActivity handle the onBack
if (stack.size() <= 1) {
restoreDefaultOrientation();

return false;
return false; // let MainActivity handle the onBack (e.g. to minimize the mini player)
}

// Remove top
stack.pop();
// Get stack item from the new top
assert stack.peek() != null;
setupFromHistoryItem(stack.peek());
setupFromHistoryItem(Objects.requireNonNull(stack.peek()));

return true;
}
Expand Down Expand Up @@ -1432,17 +1431,15 @@ public void onReceive(final Context context, final Intent intent) {
//////////////////////////////////////////////////////////////////////////*/

private void restoreDefaultOrientation() {
if (!isPlayerAvailable() || !player.videoPlayerSelected() || activity == null) {
return;
if (isPlayerAvailable() && player.videoPlayerSelected()) {
toggleFullscreenIfInFullscreenMode();
}

toggleFullscreenIfInFullscreenMode();

// This will show systemUI and pause the player.
// User can tap on Play button and video will be in fullscreen mode again
// Note for tablet: trying to avoid orientation changes since it's not easy
// to physically rotate the tablet every time
if (!DeviceUtils.isTablet(activity)) {
if (activity != null && !DeviceUtils.isTablet(activity)) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
}
Expand Down

0 comments on commit 7667b2c

Please sign in to comment.