Skip to content

Commit

Permalink
Merge pull request TeamNewPipe/NewPipe#5502 from Stypox/fix-minimize
Browse files Browse the repository at this point in the history
Fix minimize on app switch always opens popup
  • Loading branch information
Stypox authored and tossj committed Apr 21, 2021
1 parent e30f599 commit d96f136
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
9 changes: 6 additions & 3 deletions app/src/main/java/org/schabi/newpipelegacy/player/Player.java
Original file line number Diff line number Diff line change
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;
case MINIMIZE_ON_EXIT_MODE_POPUP:
setRecovery();
NavigationHelper.playOnPopupPlayer(getParentActivity(), playQueue, true);
break;
case MINIMIZE_ON_EXIT_MODE_NONE: default:
pause();
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
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 @@ -451,7 +434,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

0 comments on commit d96f136

Please sign in to comment.