From 5fcc3b4dab84c5741a81747059d23a0d033694ea Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 17 Oct 2021 12:07:13 +0200 Subject: [PATCH 1/6] [Player] Fix resuming playback This was caused by #6872 --- app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index afa826677..1f2aa98ae 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -87,6 +87,7 @@ public final class NavigationHelper { } } intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal()); + intent.putExtra(Player.RESUME_PLAYBACK, true); return intent; } From 28c72e7f630013c93c599bf9350583c8dbb1f71c Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 17 Oct 2021 12:54:56 +0200 Subject: [PATCH 2/6] Fix new version check still occassionally started in background --- app/src/main/java/org/schabi/newpipe/App.java | 9 +++++++++ .../java/org/schabi/newpipe/MainActivity.java | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index b44f7517d..7562c2a21 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -65,6 +65,7 @@ public class App extends MultiDexApplication { public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID; private static final String TAG = App.class.toString(); private static App app; + private static boolean wasAppInForeground = false; @NonNull public static App getApp() { @@ -254,4 +255,12 @@ public class App extends MultiDexApplication { protected boolean isDisposedRxExceptionsReported() { return false; } + + public static boolean wasAppInForeground() { + return wasAppInForeground; + } + + public static void setWasAppInForeground(final boolean wasAppInForeground) { + App.wasAppInForeground = wasAppInForeground; + } } diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 18ab69b7b..ed3826946 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -21,6 +21,7 @@ package org.schabi.newpipe; import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import android.content.BroadcastReceiver; import android.content.Context; @@ -93,8 +94,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; - public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @SuppressWarnings("ConstantConditions") @@ -165,9 +164,6 @@ public class MainActivity extends AppCompatActivity { FocusOverlayView.setupFocusObserver(this); } openMiniPlayerUponPlayerStarted(); - - // Check for new version - startNewVersionCheckService(); } private void setupDrawer() throws Exception { @@ -520,6 +516,19 @@ public class MainActivity extends AppCompatActivity { getString(R.string.enable_watch_history_key), true); drawerLayoutBinding.navigation.getMenu().findItem(ITEM_ID_HISTORY) .setVisible(isHistoryEnabled); + + if (!App.wasAppInForeground()) { + // Check for new app version + // The service searching for a new NewPipe version must not be started in background + // and therefore needs to be placed in onResume(). + // Only start the service once when app is started + // and not everytime onResume() is called. + if (DEBUG) { + Log.d(TAG, "App is in foreground for the first time"); + } + App.setWasAppInForeground(true); + startNewVersionCheckService(); + } } @Override From b79ea7b51b6451fc0133eb09602239753ee662d2 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 17 Oct 2021 12:10:24 +0200 Subject: [PATCH 3/6] NewPipe 0.21.13 (979) --- app/build.gradle | 4 ++-- fastlane/metadata/android/en-US/changelogs/979.txt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/979.txt diff --git a/app/build.gradle b/app/build.gradle index e09395cff..468006578 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { resValue "string", "app_name", "NewPipe" minSdkVersion 19 targetSdkVersion 29 - versionCode 978 - versionName "0.21.12" + versionCode 979 + versionName "0.21.13" multiDexEnabled true diff --git a/fastlane/metadata/android/en-US/changelogs/979.txt b/fastlane/metadata/android/en-US/changelogs/979.txt new file mode 100644 index 000000000..4ba2a9f5a --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/979.txt @@ -0,0 +1 @@ +Fixed resuming playback. \ No newline at end of file From ac071b383f5fa63fed87f0d884ecac1a14d6ef49 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 20 Oct 2021 22:11:46 +0200 Subject: [PATCH 4/6] Revert part of #6872 and fix playback resuming --- .../fragments/detail/VideoDetailFragment.java | 2 +- .../schabi/newpipe/util/NavigationHelper.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 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 5a30ea0f3..437cb2fdb 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 @@ -1181,7 +1181,7 @@ public final class VideoDetailFragment addVideoPlayerView(); final Intent playerIntent = NavigationHelper.getPlayerIntent(requireContext(), - MainPlayer.class, queue, autoPlayEnabled); + MainPlayer.class, queue, true, autoPlayEnabled); ContextCompat.startForegroundService(activity, playerIntent); } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 1f2aa98ae..cb796a7a6 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -77,7 +77,8 @@ public final class NavigationHelper { @NonNull public static Intent getPlayerIntent(@NonNull final Context context, @NonNull final Class targetClazz, - @Nullable final PlayQueue playQueue) { + @Nullable final PlayQueue playQueue, + final boolean resumePlayback) { final Intent intent = new Intent(context, targetClazz); if (playQueue != null) { @@ -87,7 +88,7 @@ public final class NavigationHelper { } } intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal()); - intent.putExtra(Player.RESUME_PLAYBACK, true); + intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback); return intent; } @@ -96,8 +97,9 @@ public final class NavigationHelper { public static Intent getPlayerIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue, + final boolean resumePlayback, final boolean playWhenReady) { - return getPlayerIntent(context, targetClazz, playQueue) + return getPlayerIntent(context, targetClazz, playQueue, resumePlayback) .putExtra(Player.PLAY_WHEN_READY, playWhenReady); } @@ -105,7 +107,14 @@ public final class NavigationHelper { public static Intent getPlayerEnqueueIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue) { - return getPlayerIntent(context, targetClazz, playQueue) + // when enqueueing `resumePlayback` is always `false` since: + // - if there is a video already playing, the value of `resumePlayback` just doesn't make + // any difference. + // - if there is nothing already playing, it is useful for the enqueue action to have a + // slightly different behaviour than the normal play action: the latter resumes playback, + // the former doesn't. (note that enqueue can be triggered when nothing is playing only + // by long pressing the video detail fragment, playlist or channel controls + return getPlayerIntent(context, targetClazz, playQueue, false) .putExtra(Player.ENQUEUE, true); } @@ -113,7 +122,8 @@ public final class NavigationHelper { public static Intent getPlayerEnqueueNextIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue) { - return getPlayerIntent(context, targetClazz, playQueue) + // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false + return getPlayerIntent(context, targetClazz, playQueue, false) .putExtra(Player.ENQUEUE_NEXT, true); } From 768bb0bbcd11b7af894fd0c9d61dcaf3be1e5328 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Wed, 20 Oct 2021 23:55:14 +0200 Subject: [PATCH 5/6] Start service for update checks in onPastCreate() --- app/src/main/java/org/schabi/newpipe/App.java | 8 ------- .../schabi/newpipe/CheckForNewAppVersion.java | 17 ++++++++++++++ .../java/org/schabi/newpipe/MainActivity.java | 22 ++++++++----------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 7562c2a21..3785249b4 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -65,7 +65,6 @@ public class App extends MultiDexApplication { public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID; private static final String TAG = App.class.toString(); private static App app; - private static boolean wasAppInForeground = false; @NonNull public static App getApp() { @@ -256,11 +255,4 @@ public class App extends MultiDexApplication { return false; } - public static boolean wasAppInForeground() { - return wasAppInForeground; - } - - public static void setWasAppInForeground(final boolean wasAppInForeground) { - App.wasAppInForeground = wasAppInForeground; - } } diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java index 64874cd93..9c392be1e 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java @@ -235,6 +235,23 @@ public final class CheckForNewAppVersion extends IntentService { } } + /** + * Start a new service which + * checks if all conditions for performing a version check are met, + * fetches the API endpoint {@link #NEWPIPE_API_URL} containing info + * about the latest NewPipe version + * and displays a notification about ana available update. + *
+ * Following conditions need to be met, before data is request from the server: + *
    + *
  • The app is signed with the correct signing key (by TeamNewPipe / schabi). + * If the signing key differs from the one used upstream, the update cannot be installed.
  • + *
  • The user enabled searching for and notifying about updates in the settings.
  • + *
  • The app did not recently check for updates. + * We do not want to make unnecessary connections and DOS our servers.
  • + *
+ * Must not be executed when the app is in background. + */ public static void startNewVersionCheckService() { final Intent intent = new Intent(App.getApp().getApplicationContext(), CheckForNewAppVersion.class); diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index ed3826946..2a8872e26 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -166,6 +166,15 @@ public class MainActivity extends AppCompatActivity { openMiniPlayerUponPlayerStarted(); } + @Override + protected void onPostCreate(final Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + // Start the service which is checking all conditions + // and eventually searching for a new version. + // The service searching for a new NewPipe version must not be started in background. + startNewVersionCheckService(); + } + private void setupDrawer() throws Exception { //Tabs final int currentServiceId = ServiceHelper.getSelectedServiceId(this); @@ -516,19 +525,6 @@ public class MainActivity extends AppCompatActivity { getString(R.string.enable_watch_history_key), true); drawerLayoutBinding.navigation.getMenu().findItem(ITEM_ID_HISTORY) .setVisible(isHistoryEnabled); - - if (!App.wasAppInForeground()) { - // Check for new app version - // The service searching for a new NewPipe version must not be started in background - // and therefore needs to be placed in onResume(). - // Only start the service once when app is started - // and not everytime onResume() is called. - if (DEBUG) { - Log.d(TAG, "App is in foreground for the first time"); - } - App.setWasAppInForeground(true); - startNewVersionCheckService(); - } } @Override From 5d59025b3c0fefe555393318a3fd147e536ed6d6 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Thu, 21 Oct 2021 20:30:10 +0200 Subject: [PATCH 6/6] Update changelog --- fastlane/metadata/android/en-US/changelogs/979.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastlane/metadata/android/en-US/changelogs/979.txt b/fastlane/metadata/android/en-US/changelogs/979.txt index 4ba2a9f5a..520d92993 100644 --- a/fastlane/metadata/android/en-US/changelogs/979.txt +++ b/fastlane/metadata/android/en-US/changelogs/979.txt @@ -1 +1,2 @@ -Fixed resuming playback. \ No newline at end of file +- Fixed resuming playback +- Improvements to ensure that the service which determines if NewPipe should check for a new version checks is not started in background \ No newline at end of file