From e0639677345af36fc1c3cc1704ebbac7ccf35d17 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Fri, 3 Jan 2020 19:19:14 +0300 Subject: [PATCH] Third block of fixes for review - audio-only streams plays the same way as video streams - fullscreen mode for tablet with controls on the right place - hidden controls while swiping mini player down - mini player works better --- .../fragments/detail/VideoDetailFragment.java | 11 +++----- .../newpipe/player/VideoPlayerImpl.java | 26 ++++++++++++++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 8813d139d..3d42942ba 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -526,12 +526,7 @@ public class VideoDetailFragment openChannel(); break; case R.id.detail_thumbnail_root_layout: - if (currentInfo.getVideoStreams().isEmpty() - && currentInfo.getVideoOnlyStreams().isEmpty()) { - openBackgroundPlayer(false); - } else { - openVideoPlayer(); - } + openVideoPlayer(); break; case R.id.detail_title_root_layout: toggleTitleAndDescription(); @@ -545,6 +540,7 @@ public class VideoDetailFragment if (player != null) { player.onPlayPause(); player.hideControls(0,0); + showSystemUi(); } else openVideoPlayer(); @@ -1869,9 +1865,10 @@ public class VideoDetailFragment case BottomSheetBehavior.STATE_COLLAPSED: // Re-enable clicks setOverlayElementsClickable(true); - if (player != null && player.isInFullscreen()) player.toggleFullscreen(); + if (player != null && player.isInFullscreen() && player.isPlaying()) showSystemUi(); break; case BottomSheetBehavior.STATE_DRAGGING: + if (player != null && player.isControlsVisible()) player.hideControls(0, 0); break; case BottomSheetBehavior.STATE_SETTLING: break; diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 76c8106be..d5bb5c86d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -534,7 +534,7 @@ public class VideoPlayerImpl extends VideoPlayer if (fragmentListener == null) return; isFullscreen = !isFullscreen; - setControlsWidth(); + setControlsSize(); fragmentListener.onFullscreenStateChanged(isInFullscreen()); // When user presses back button in landscape mode and in fullscreen and uses ZOOM mode // a video can be larger than screen. Prevent it like this @@ -1102,19 +1102,39 @@ public class VideoPlayerImpl extends VideoPlayer fragmentListener.hideSystemUIIfNeeded(); } - private void setControlsWidth() { + /* + * This method measures width and height of controls visible on screen. It ensures that controls will be side-by-side with + * NavigationBar and notches but not under them. Tablets have only bottom NavigationBar + * */ + void setControlsSize() { Point size = new Point(); + Display display = getRootView().getDisplay(); + if (display == null) return; // This method will give a correct size of a usable area of a window. // It doesn't include NavigationBar, notches, etc. - getRootView().getDisplay().getSize(size); + display.getSize(size); int width = isFullscreen ? size.x : ViewGroup.LayoutParams.MATCH_PARENT; + int gravity = isFullscreen ? (display.getRotation() == Surface.ROTATION_90 ? Gravity.START : Gravity.END) : Gravity.TOP; + primaryControls.getLayoutParams().width = width; + ((LinearLayout.LayoutParams) primaryControls.getLayoutParams()).gravity = gravity; primaryControls.requestLayout(); + secondaryControls.getLayoutParams().width = width; + ((LinearLayout.LayoutParams) secondaryControls.getLayoutParams()).gravity = gravity; secondaryControls.requestLayout(); + getBottomControlsRoot().getLayoutParams().width = width; + RelativeLayout.LayoutParams bottomParams = ((RelativeLayout.LayoutParams) getBottomControlsRoot().getLayoutParams()); + bottomParams.removeRule(RelativeLayout.ALIGN_PARENT_START); + bottomParams.removeRule(RelativeLayout.ALIGN_PARENT_END); + bottomParams.addRule(gravity == Gravity.END ? RelativeLayout.ALIGN_PARENT_END : RelativeLayout.ALIGN_PARENT_START); getBottomControlsRoot().requestLayout(); + + ViewGroup controlsRoot = getRootView().findViewById(R.id.playbackControlRoot); + controlsRoot.getLayoutParams().height = isFullscreen ? size.y : ViewGroup.LayoutParams.MATCH_PARENT; + controlsRoot.requestLayout(); } private void updatePlaybackButtons() {