Refactoring and made the player returning from landscape & fullscreen on vertical video to portrait after clicking on fullscreen button
This commit is contained in:
parent
d0fc9fda71
commit
9a0c2c40bd
|
@ -112,6 +112,7 @@ import static org.schabi.newpipe.player.MainPlayer.ACTION_REPEAT;
|
|||
import static org.schabi.newpipe.player.MainPlayer.NOTIFICATION_ID;
|
||||
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
|
||||
import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;
|
||||
import static org.schabi.newpipe.player.helper.PlayerHelper.globalScreenOrientationLocked;
|
||||
import static org.schabi.newpipe.util.AnimationUtils.Type.SLIDE_AND_ALPHA;
|
||||
import static org.schabi.newpipe.util.AnimationUtils.animateRotation;
|
||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||
|
@ -716,11 +717,46 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
if (DEBUG) {
|
||||
Log.d(TAG, "toggleFullscreen() called");
|
||||
}
|
||||
if (simpleExoPlayer == null || getCurrentMetadata() == null) {
|
||||
if (popupPlayerSelected()
|
||||
|| simpleExoPlayer == null
|
||||
|| getCurrentMetadata() == null
|
||||
|| fragmentListener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
isFullscreen = !isFullscreen;
|
||||
if (!isFullscreen) {
|
||||
// Apply window insets because Android will not do it when orientation changes
|
||||
// from landscape to portrait (open vertical video to reproduce)
|
||||
getControlsRoot().setPadding(0, 0, 0, 0);
|
||||
} else {
|
||||
// Android needs tens milliseconds to send new insets but a user is able to see
|
||||
// how controls changes it's position from `0` to `nav bar height` padding.
|
||||
// So just hide the controls to hide this visual inconsistency
|
||||
hideControls(0, 0);
|
||||
}
|
||||
fragmentListener.onFullscreenStateChanged(isFullscreen());
|
||||
|
||||
if (!isFullscreen()) {
|
||||
titleTextView.setVisibility(View.GONE);
|
||||
channelTextView.setVisibility(View.GONE);
|
||||
playerCloseButton.setVisibility(videoPlayerSelected() ? View.VISIBLE : View.GONE);
|
||||
} else {
|
||||
titleTextView.setVisibility(View.VISIBLE);
|
||||
channelTextView.setVisibility(View.VISIBLE);
|
||||
playerCloseButton.setVisibility(View.GONE);
|
||||
}
|
||||
setupScreenRotationButton();
|
||||
}
|
||||
|
||||
public void switchFromPopupToMain() {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "switchFromPopupToMain() called");
|
||||
}
|
||||
if (!popupPlayerSelected() || simpleExoPlayer == null || getCurrentMetadata() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (popupPlayerSelected()) {
|
||||
setRecovery();
|
||||
service.removeViewFromParent();
|
||||
final Intent intent = NavigationHelper.getPlayerIntent(
|
||||
|
@ -745,36 +781,6 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
intent.putExtra(VideoDetailFragment.AUTO_PLAY, true);
|
||||
service.onDestroy();
|
||||
context.startActivity(intent);
|
||||
return;
|
||||
} else {
|
||||
if (fragmentListener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
isFullscreen = !isFullscreen;
|
||||
if (!isFullscreen) {
|
||||
// Apply window insets because Android will not do it when orientation changes
|
||||
// from landscape to portrait (open vertical video to reproduce)
|
||||
getControlsRoot().setPadding(0, 0, 0, 0);
|
||||
} else {
|
||||
// Android needs tens milliseconds to send new insets but a user is able to see
|
||||
// how controls changes it's position from `0` to `nav bar height` padding.
|
||||
// So just hide the controls to hide this visual inconsistency
|
||||
hideControls(0, 0);
|
||||
}
|
||||
fragmentListener.onFullscreenStateChanged(isFullscreen());
|
||||
}
|
||||
|
||||
if (!isFullscreen()) {
|
||||
titleTextView.setVisibility(View.GONE);
|
||||
channelTextView.setVisibility(View.GONE);
|
||||
playerCloseButton.setVisibility(videoPlayerSelected() ? View.VISIBLE : View.GONE);
|
||||
} else {
|
||||
titleTextView.setVisibility(View.VISIBLE);
|
||||
channelTextView.setVisibility(View.VISIBLE);
|
||||
playerCloseButton.setVisibility(View.GONE);
|
||||
}
|
||||
setupScreenRotationButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -804,9 +810,12 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
} else if (v.getId() == openInBrowser.getId()) {
|
||||
onOpenInBrowserClicked();
|
||||
} else if (v.getId() == fullscreenButton.getId()) {
|
||||
toggleFullscreen();
|
||||
switchFromPopupToMain();
|
||||
} else if (v.getId() == screenRotationButton.getId()) {
|
||||
if (!isVerticalVideo) {
|
||||
// Only if it's not a vertical video or vertical video but in landscape with locked
|
||||
// orientation a screen orientation can be changed automatically
|
||||
if (!isVerticalVideo
|
||||
|| (service.isLandscape() && globalScreenOrientationLocked(service))) {
|
||||
fragmentListener.onScreenRotationButtonClicked();
|
||||
} else {
|
||||
toggleFullscreen();
|
||||
|
|
Loading…
Reference in New Issue