From e1df4757e49610025a2d0695556a29d6853732a6 Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Sun, 3 Jun 2018 14:09:16 -0700 Subject: [PATCH] -Expanded minimize to exit to allow resuming on background player. -Modified minimize to exit toggle to selection dialog. --- .../newpipe/player/MainVideoPlayer.java | 21 ++++++++---- .../newpipe/player/helper/PlayerHelper.java | 34 ++++++++++++++++--- app/src/main/res/values/settings_keys.xml | 15 ++++++++ app/src/main/res/values/strings.xml | 9 +++-- app/src/main/res/xml/video_audio_settings.xml | 14 ++++---- 5 files changed, 75 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 8daa544ae..cbe269a7d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -213,12 +213,7 @@ public final class MainVideoPlayer extends AppCompatActivity isInMultiWindow = false; - if (playerImpl == null) return; - if (PlayerHelper.isMinimizeOnExitEnabled(this)) { - playerImpl.onFullScreenButtonClicked(); - } else { - playerImpl.destroy(); - } + if (playerImpl != null) playerImpl.terminate(); } /*////////////////////////////////////////////////////////////////////////// @@ -448,6 +443,20 @@ public final class MainVideoPlayer extends AppCompatActivity switchPopupButton.setOnClickListener(this); } + public void terminate() { + switch (PlayerHelper.getMinimizeOnExitAction(context)) { + case PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND: + onPlayBackgroundButtonClicked(); + break; + case PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP: + onFullScreenButtonClicked(); + break; + case PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE: + destroy(); + break; + } + } + /*////////////////////////////////////////////////////////////////////////// // ExoPlayer Video Listener //////////////////////////////////////////////////////////////////////////*/ 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 252a3f708..f8d594114 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 @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Build; import android.preference.PreferenceManager; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.accessibility.CaptioningManager; @@ -28,6 +29,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueueItem; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; +import java.lang.annotation.Retention; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; @@ -42,6 +44,8 @@ import java.util.concurrent.TimeUnit; import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FILL; import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FIT; import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM; +import static java.lang.annotation.RetentionPolicy.SOURCE; +import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.*; public class PlayerHelper { private PlayerHelper() {} @@ -51,6 +55,14 @@ public class PlayerHelper { private static final NumberFormat speedFormatter = new DecimalFormat("0.##x"); private static final NumberFormat pitchFormatter = new DecimalFormat("##%"); + @Retention(SOURCE) + @IntDef({MINIMIZE_ON_EXIT_MODE_NONE, MINIMIZE_ON_EXIT_MODE_BACKGROUND, + MINIMIZE_ON_EXIT_MODE_POPUP}) + public @interface MinimizeMode { + int MINIMIZE_ON_EXIT_MODE_NONE = 0; + int MINIMIZE_ON_EXIT_MODE_BACKGROUND = 1; + int MINIMIZE_ON_EXIT_MODE_POPUP = 2; + } //////////////////////////////////////////////////////////////////////////// // Exposed helpers //////////////////////////////////////////////////////////////////////////// @@ -173,8 +185,20 @@ public class PlayerHelper { return isAutoQueueEnabled(context, false); } - public static boolean isMinimizeOnExitEnabled(@NonNull final Context context) { - return isMinimizeOnExitEnabled(context, false); + @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 = getMinimizeOnExitAction(context, defaultAction); + if (action.equals(popupAction)) { + return MINIMIZE_ON_EXIT_MODE_POPUP; + } else if (action.equals(backgroundAction)) { + return MINIMIZE_ON_EXIT_MODE_BACKGROUND; + } else { + return MINIMIZE_ON_EXIT_MODE_NONE; + } } @NonNull @@ -326,7 +350,9 @@ public class PlayerHelper { } } - private static boolean isMinimizeOnExitEnabled(@NonNull final Context context, final boolean b) { - return getPreferences(context).getBoolean(context.getString(R.string.minimize_on_exit_key), b); + private static String getMinimizeOnExitAction(@NonNull final Context context, + final String key) { + return getPreferences(context).getString(context.getString(R.string.minimize_on_exit_key), + key); } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index e21697a62..2b505686b 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -24,7 +24,22 @@ auto_queue_key screen_brightness_key screen_brightness_timestamp_key + minimize_on_exit_key + @string/minimize_on_exit_none_key + minimize_on_exit_none_key + minimize_on_exit_background_key + minimize_on_exit_popup_key + + @string/minimize_on_exit_none_key + @string/minimize_on_exit_background_key + @string/minimize_on_exit_popup_key + + + @string/minimize_on_exit_none_description + @string/minimize_on_exit_background_description + @string/minimize_on_exit_popup_description + default_resolution 360p diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 747b80dcc..c1132ac65 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -74,8 +74,6 @@ Remember last size and position of popup Use fast inexact seek Inexact seek allows the player to seek to positions faster with reduced precision - Minimize on exit - Experimental. Switch to play on popup player when exiting main video player Load thumbnails Disable to stop all thumbnails from loading and save on data and memory usage. Changing this will clear both in-memory and on-disk image cache. Image cache wiped @@ -506,4 +504,11 @@ 144p + + Minimize on exit + Action when exiting main video player — %s + None + Minimize to background player + Minimize to popup player + diff --git a/app/src/main/res/xml/video_audio_settings.xml b/app/src/main/res/xml/video_audio_settings.xml index 440bce0f2..a547ffaf2 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -90,6 +90,14 @@ android:summary="@string/preferred_open_action_settings_summary" android:title="@string/preferred_open_action_settings_title"/> + + - -