From fc9b63298c619305926dae9f7f3b4d2f7b5ea6ab Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Tue, 31 Dec 2019 05:07:07 +0300 Subject: [PATCH] Optimizations and fixes of rare situations - popup after orientation change had incorrect allowed bounds for swiping - popup could cause a crash after many quick switches to main player and back - better method of setting fullscreen/non-fullscreen layout using thumbnail view. Also fixed thumbnail height in fullscreen layout - global settings observer didn't work when a user closed a service manually via notification because it checked for service existing - app will now exits from fullscreen mode when the user switches players - playQueuePanel has visibility "gone" by default (not "invisible") because "invisible" can cause problems --- .../fragments/detail/VideoDetailFragment.java | 32 +++++++++---------- .../newpipe/player/VideoPlayerImpl.java | 4 +-- .../player/event/PlayerGestureListener.java | 3 +- .../activity_main_player.xml | 2 +- .../main/res/layout/activity_main_player.xml | 2 +- 5 files changed, 22 insertions(+), 21 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 bae6e57aa..245a9a495 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 @@ -1040,6 +1040,9 @@ public class VideoDetailFragment boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity) .getBoolean(activity.getString(R.string.use_external_audio_player_key), false); + // If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode + if (player != null && player.isInFullscreen()) player.toggleFullscreen(); + if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) { openNormalBackgroundPlayer(append); } else { @@ -1056,6 +1059,9 @@ public class VideoDetailFragment // See UI changes while remote playQueue changes if (!bounded) startService(false); + // If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode + if (player != null && player.isInFullscreen()) player.toggleFullscreen(); + PlayQueue queue = setupPlayQueueForIntent(append); if (append) { NavigationHelper.enqueueOnPopupPlayer(activity, queue, false); @@ -1181,17 +1187,7 @@ public class VideoDetailFragment // Check if viewHolder already contains a child if (player.getRootView() != viewHolder) removeVideoPlayerView(); - - final int newHeight; - if (player.isInFullscreen()) - newHeight = activity.getWindow().getDecorView().getHeight(); - else - newHeight = FrameLayout.LayoutParams.MATCH_PARENT; - - if (viewHolder.getLayoutParams().height != newHeight) { - viewHolder.getLayoutParams().height = newHeight; - viewHolder.requestLayout(); - } + setHeightThumbnail(); // Prevent from re-adding a view multiple times if (player.getRootView().getParent() == null) viewHolder.addView(player.getRootView()); @@ -1242,9 +1238,15 @@ public class VideoDetailFragment private void setHeightThumbnail() { final DisplayMetrics metrics = getResources().getDisplayMetrics(); boolean isPortrait = metrics.heightPixels > metrics.widthPixels; - int height = isPortrait - ? (int) (metrics.widthPixels / (16.0f / 9.0f)) - : (int) (metrics.heightPixels / 2f); + + int height; + if (player != null && player.isInFullscreen()) + height = activity.getWindow().getDecorView().getHeight(); + else + height = isPortrait + ? (int) (metrics.widthPixels / (16.0f / 9.0f)) + : (int) (metrics.heightPixels / 2f);; + thumbnailImageView.setLayoutParams( new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height)); thumbnailImageView.setMinimumHeight(height); @@ -1334,8 +1336,6 @@ public class VideoDetailFragment @Override public void onSettingsChanged() { - if (player == null) return; - if(!globalScreenOrientationLocked()) getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } 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 8cef5b453..492fd9ac5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -1329,7 +1329,7 @@ public class VideoPlayerImpl extends VideoPlayer public void updatePopupSize(int width, int height) { if (DEBUG) Log.d(TAG, "updatePopupSize() called with: width = [" + width + "], height = [" + height + "]"); - if (popupLayoutParams == null || windowManager == null || !popupPlayerSelected() || getRootView().getParent() == null) + if (popupLayoutParams == null || windowManager == null || getParentActivity() != null || getRootView().getParent() == null) return; width = (int) (width > maximumWidth ? maximumWidth : width < minimumWidth ? minimumWidth : width); @@ -1347,7 +1347,7 @@ public class VideoPlayerImpl extends VideoPlayer } private void updateWindowFlags(final int flags) { - if (popupLayoutParams == null || windowManager == null || !popupPlayerSelected() || getRootView().getParent() == null) + if (popupLayoutParams == null || windowManager == null || getParentActivity() != null || getRootView().getParent() == null) return; popupLayoutParams.flags = flags; diff --git a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java index 72462beff..398cf9534 100644 --- a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java +++ b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java @@ -299,7 +299,8 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen private boolean onDownInPopup(MotionEvent e) { // Fix popup position when the user touch it, it may have the wrong one // because the soft input is visible (the draggable area is currently resized). - playerImpl.checkPopupPositionBounds(playerImpl.getCloseOverlayView().getWidth(), playerImpl.getCloseOverlayView().getHeight()); + playerImpl.updateScreenSize(); + playerImpl.checkPopupPositionBounds(); initialPopupX = playerImpl.getPopupLayoutParams().x; initialPopupY = playerImpl.getPopupLayoutParams().y; diff --git a/app/src/main/res/layout-large-land/activity_main_player.xml b/app/src/main/res/layout-large-land/activity_main_player.xml index cbcc6eeb0..0e2011910 100644 --- a/app/src/main/res/layout-large-land/activity_main_player.xml +++ b/app/src/main/res/layout-large-land/activity_main_player.xml @@ -53,7 +53,7 @@ android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_height="match_parent" - android:visibility="invisible" + android:visibility="gone" android:background="?attr/queue_background_color" tools:visibility="visible"> diff --git a/app/src/main/res/layout/activity_main_player.xml b/app/src/main/res/layout/activity_main_player.xml index 6bc259b88..39c3f4410 100644 --- a/app/src/main/res/layout/activity_main_player.xml +++ b/app/src/main/res/layout/activity_main_player.xml @@ -51,7 +51,7 @@ android:id="@+id/playQueuePanel" android:layout_width="match_parent" android:layout_height="match_parent" - android:visibility="invisible" + android:visibility="gone" android:background="?attr/queue_background_color" tools:visibility="visible">