From 4f828fbe005be89a9f34c3a81b239fd90756339e Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 28 Jan 2021 14:33:12 +0100 Subject: [PATCH 1/4] Fix always minimizing to popup player --- .../org/schabi/newpipe/player/Player.java | 6 ++++- .../newpipe/player/helper/PlayerHelper.java | 26 ++++--------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 9d239e781..aa82c0a72 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -2012,7 +2012,8 @@ public final class Player implements changePopupWindowFlags(IDLE_WINDOW_FLAGS); // Remove running notification when user does not want minimization to background or popup - if (PlayerHelper.isMinimizeOnExitDisabled(context) && videoPlayerSelected()) { + if (PlayerHelper.getMinimizeOnExitAction(context) == MINIMIZE_ON_EXIT_MODE_NONE + && videoPlayerSelected()) { NotificationUtil.getInstance().cancelNotificationAndStopForeground(service); } else { NotificationUtil.getInstance().createNotificationIfNeededAndUpdate(this, false); @@ -3822,11 +3823,14 @@ public final class Player implements switch (getMinimizeOnExitAction(context)) { case MINIMIZE_ON_EXIT_MODE_BACKGROUND: useVideoSource(false); + break; case MINIMIZE_ON_EXIT_MODE_POPUP: setRecovery(); NavigationHelper.playOnPopupPlayer(getParentActivity(), playQueue, true); + break; case MINIMIZE_ON_EXIT_MODE_NONE: default: pause(); + break; } } } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 54021b616..8169f99e5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -251,33 +251,17 @@ public final class PlayerHelper { @MinimizeMode public static int getMinimizeOnExitAction(@NonNull final Context context) { - final String defaultAction = context.getString(R.string.minimize_on_exit_none_key); - final String popupAction = context.getString(R.string.minimize_on_exit_popup_key); - final String backgroundAction = context.getString(R.string.minimize_on_exit_background_key); - final String action = getPreferences(context) - .getString(context.getString(R.string.minimize_on_exit_key), defaultAction); - if (action.equals(popupAction)) { + .getString(context.getString(R.string.minimize_on_exit_key), ""); + if (action.equals(context.getString(R.string.minimize_on_exit_popup_key))) { return MINIMIZE_ON_EXIT_MODE_POPUP; - } else if (action.equals(backgroundAction)) { - return MINIMIZE_ON_EXIT_MODE_BACKGROUND; - } else { + } else if (action.equals(context.getString(R.string.minimize_on_exit_none_key))) { return MINIMIZE_ON_EXIT_MODE_NONE; + } else { + return MINIMIZE_ON_EXIT_MODE_BACKGROUND; // default } } - public static boolean isMinimizeOnExitToPopup(@NonNull final Context context) { - return getMinimizeOnExitAction(context) == MINIMIZE_ON_EXIT_MODE_POPUP; - } - - public static boolean isMinimizeOnExitToBackground(@NonNull final Context context) { - return getMinimizeOnExitAction(context) == MINIMIZE_ON_EXIT_MODE_BACKGROUND; - } - - public static boolean isMinimizeOnExitDisabled(@NonNull final Context context) { - return getMinimizeOnExitAction(context) == MINIMIZE_ON_EXIT_MODE_NONE; - } - @AutoplayType public static int getAutoplayType(@NonNull final Context context) { final String type = getPreferences(context).getString( From cade272501a1fcd261e615be4477f65d24c96ba6 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 28 Jan 2021 14:33:50 +0100 Subject: [PATCH 2/4] Use PlayerHelper.retrieveResizeModeFromPrefs in Player --- app/src/main/java/org/schabi/newpipe/player/Player.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index aa82c0a72..ba8e856df 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -855,8 +855,7 @@ public final class Player implements private void initVideoPlayer() { // restore last resize mode - setResizeMode(prefs.getInt(context.getString(R.string.last_resize_mode), - AspectRatioFrameLayout.RESIZE_MODE_FIT)); + setResizeMode(PlayerHelper.retrieveResizeModeFromPrefs(this)); binding.getRoot().setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); } From 376cba696e3b33e307e65abfa73b813e70dca716 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 28 Jan 2021 14:35:00 +0100 Subject: [PATCH 3/4] Remove useless getString for default setting value --- .../java/org/schabi/newpipe/player/helper/PlayerHelper.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 8169f99e5..f56909844 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -265,14 +265,13 @@ public final class PlayerHelper { @AutoplayType public static int getAutoplayType(@NonNull final Context context) { final String type = getPreferences(context).getString( - context.getString(R.string.autoplay_key), - context.getString(R.string.autoplay_wifi_key)); + context.getString(R.string.autoplay_key), ""); if (type.equals(context.getString(R.string.autoplay_always_key))) { return AUTOPLAY_TYPE_ALWAYS; } else if (type.equals(context.getString(R.string.autoplay_never_key))) { return AUTOPLAY_TYPE_NEVER; } else { - return AUTOPLAY_TYPE_WIFI; + return AUTOPLAY_TYPE_WIFI; // default } } From fdb0f01b38821003bd6e9f145adc3d5181f75386 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 28 Jan 2021 14:35:47 +0100 Subject: [PATCH 4/4] Add Objects.requireNotNull to warning which is surely not null --- .../java/org/schabi/newpipe/player/helper/PlayerHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index f56909844..ccc73e81f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -426,7 +426,7 @@ public final class PlayerHelper { private static SinglePlayQueue getAutoQueuedSinglePlayQueue( final StreamInfoItem streamInfoItem) { final SinglePlayQueue singlePlayQueue = new SinglePlayQueue(streamInfoItem); - singlePlayQueue.getItem().setAutoQueued(true); + Objects.requireNonNull(singlePlayQueue.getItem()).setAutoQueued(true); return singlePlayQueue; }