Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minimize on app switch always opens popup #5502

Merged
merged 4 commits into from Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Expand Up @@ -855,8 +855,7 @@ public void smoothStopPlayer() {

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));
}
Expand Down Expand Up @@ -2012,7 +2011,8 @@ private void onPaused() {
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);
Expand Down Expand Up @@ -3822,11 +3822,14 @@ private void onFragmentStopped() {
switch (getMinimizeOnExitAction(context)) {
case MINIMIZE_ON_EXIT_MODE_BACKGROUND:
useVideoSource(false);
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow.

case MINIMIZE_ON_EXIT_MODE_POPUP:
setRecovery();
NavigationHelper.playOnPopupPlayer(getParentActivity(), playQueue, true);
break;
case MINIMIZE_ON_EXIT_MODE_NONE: default:
pause();
break;
}
}
}
Expand Down
Expand Up @@ -251,44 +251,27 @@ public static boolean isClearingQueueConfirmationRequired(@NonNull final Context

@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(
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
}
}

Expand Down Expand Up @@ -443,7 +426,7 @@ private static boolean isUsingInexactSeek(@NonNull final Context context) {
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;
}

Expand Down