From 5ada0ae2c7e67a965031b3cf3ae2b91536d046b6 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Tue, 15 Sep 2020 22:10:38 +0300 Subject: [PATCH] Hiding controls when orientation changes to landscape --- .../fragments/detail/VideoDetailFragment.java | 1 - .../newpipe/player/VideoPlayerImpl.java | 19 +++++++++++++++---- .../fragment_video_detail.xml | 1 - 3 files changed, 15 insertions(+), 6 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 bbb30f818..06bff16e0 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 @@ -2105,7 +2105,6 @@ public class VideoDetailFragment // Let's give a user time to look at video information page if video is not playing if (orientationLocked && !player.isPlaying()) { player.onPlay(); - player.showControlsThenHide(); } } 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 c131ed96b..224f2d3e2 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -753,8 +753,16 @@ public class VideoPlayerImpl extends VideoPlayer } isFullscreen = !isFullscreen; - // Prevent applying windows insets twice (open vertical video to reproduce) - getRootView().findViewById(R.id.playbackControlRoot).setPadding(0, 0, 0, 0); + 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()); } @@ -1926,8 +1934,11 @@ public class VideoPlayerImpl extends VideoPlayer public void setFragmentListener(final PlayerServiceEventListener listener) { fragmentListener = listener; fragmentIsVisible = true; - // Prevent applying windows insets twice - getRootView().findViewById(R.id.playbackControlRoot).setPadding(0, 0, 0, 0); + // Apply window insets because Android will not do it when orientation changes + // from landscape to portrait + if (!isFullscreen) { + getControlsRoot().setPadding(0, 0, 0, 0); + } queueLayout.setPadding(0, 0, 0, 0); updateMetadata(); updatePlayback(); diff --git a/app/src/main/res/layout-large-land/fragment_video_detail.xml b/app/src/main/res/layout-large-land/fragment_video_detail.xml index 3a17104e4..e2d18434d 100644 --- a/app/src/main/res/layout-large-land/fragment_video_detail.xml +++ b/app/src/main/res/layout-large-land/fragment_video_detail.xml @@ -20,7 +20,6 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="5" - android:fitsSystemWindows="true" android:isScrollContainer="true">