From 768bb0bbcd11b7af894fd0c9d61dcaf3be1e5328 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Wed, 20 Oct 2021 23:55:14 +0200 Subject: [PATCH] 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: + * + * 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