diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
index 9c392be1e..9e43394ac 100644
--- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
+++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
@@ -7,7 +7,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
-import android.net.ConnectivityManager;
import android.net.Uri;
import android.util.Log;
@@ -15,7 +14,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
-import androidx.core.content.ContextCompat;
import androidx.core.content.pm.PackageInfoCompat;
import androidx.preference.PreferenceManager;
@@ -48,7 +46,8 @@ public final class CheckForNewAppVersion extends IntentService {
private static final boolean DEBUG = MainActivity.DEBUG;
private static final String TAG = CheckForNewAppVersion.class.getSimpleName();
- private static final String GITHUB_APK_SHA1
+ // Public key of the certificate that is used in NewPipe release versions
+ private static final String RELEASE_CERT_PUBLIC_KEY_SHA1
= "B0:2E:90:7C:1C:D6:FC:57:C3:35:F0:88:D0:8F:50:5F:94:E4:D2:15";
private static final String NEWPIPE_API_URL = "https://newpipe.net/api/data.json";
@@ -129,44 +128,37 @@ public final class CheckForNewAppVersion extends IntentService {
final String versionName,
final String apkLocationUrl,
final int versionCode) {
- final int notificationId = 2000;
-
- if (BuildConfig.VERSION_CODE < versionCode) {
- // A pending intent to open the apk location url in the browser.
- final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl));
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- final PendingIntent pendingIntent
- = PendingIntent.getActivity(application, 0, intent, 0);
-
- final String channelId = application
- .getString(R.string.app_update_notification_channel_id);
- final NotificationCompat.Builder notificationBuilder
- = new NotificationCompat.Builder(application, channelId)
- .setSmallIcon(R.drawable.ic_newpipe_update)
- .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
- .setContentIntent(pendingIntent)
- .setAutoCancel(true)
- .setContentTitle(application
- .getString(R.string.app_update_notification_content_title))
- .setContentText(application
- .getString(R.string.app_update_notification_content_text)
- + " " + versionName);
-
- final NotificationManagerCompat notificationManager
- = NotificationManagerCompat.from(application);
- notificationManager.notify(notificationId, notificationBuilder.build());
+ if (BuildConfig.VERSION_CODE >= versionCode) {
+ return;
}
+
+ // A pending intent to open the apk location url in the browser.
+ final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl));
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ final PendingIntent pendingIntent
+ = PendingIntent.getActivity(application, 0, intent, 0);
+
+ final String channelId = application
+ .getString(R.string.app_update_notification_channel_id);
+ final NotificationCompat.Builder notificationBuilder
+ = new NotificationCompat.Builder(application, channelId)
+ .setSmallIcon(R.drawable.ic_newpipe_update)
+ .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
+ .setContentIntent(pendingIntent)
+ .setAutoCancel(true)
+ .setContentTitle(application
+ .getString(R.string.app_update_notification_content_title))
+ .setContentText(application
+ .getString(R.string.app_update_notification_content_text)
+ + " " + versionName);
+
+ final NotificationManagerCompat notificationManager
+ = NotificationManagerCompat.from(application);
+ notificationManager.notify(2000, notificationBuilder.build());
}
- private static boolean isConnected(@NonNull final App app) {
- final ConnectivityManager connectivityManager =
- ContextCompat.getSystemService(app, ConnectivityManager.class);
- return connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null
- && connectivityManager.getActiveNetworkInfo().isConnected();
- }
-
- public static boolean isGithubApk(@NonNull final App app) {
- return getCertificateSHA1Fingerprint(app).equals(GITHUB_APK_SHA1);
+ public static boolean isReleaseApk(@NonNull final App app) {
+ return getCertificateSHA1Fingerprint(app).equals(RELEASE_CERT_PUBLIC_KEY_SHA1);
}
private void checkNewVersion() throws IOException, ReCaptchaException {
@@ -175,9 +167,8 @@ public final class CheckForNewAppVersion extends IntentService {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
final NewVersionManager manager = new NewVersionManager();
- // Check if user has enabled/disabled update checking
- // and if the current apk is a github one or not.
- if (!prefs.getBoolean(app.getString(R.string.update_app_key), true) || !isGithubApk(app)) {
+ // Check if the current apk is a github one or not.
+ if (!isReleaseApk(app)) {
return;
}
@@ -213,6 +204,7 @@ public final class CheckForNewAppVersion extends IntentService {
// Parse the json from the response.
try {
+
final JsonObject githubStableObject = JsonParser.object()
.from(response.responseBody()).getObject("flavors")
.getObject("github").getObject("stable");
diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java
index 1855d45cd..0a49e00e4 100644
--- a/app/src/main/java/org/schabi/newpipe/MainActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java
@@ -169,10 +169,16 @@ public class MainActivity extends AppCompatActivity {
@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();
+
+ final App app = App.getApp();
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
+
+ if (prefs.getBoolean(app.getString(R.string.update_app_key), true)) {
+ // 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 ExtractionException {
diff --git a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java
index 2f65af4d6..12599b828 100644
--- a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java
@@ -16,8 +16,9 @@ public class MainSettingsFragment extends BasePreferenceFragment {
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResource(R.xml.main_settings);
- if (!CheckForNewAppVersion.isGithubApk(App.getApp())) {
- final Preference update = findPreference(getString(R.string.update_pref_screen_key));
+ if (!CheckForNewAppVersion.isReleaseApk(App.getApp())) {
+ final Preference update
+ = findPreference(getString(R.string.update_pref_screen_key));
getPreferenceScreen().removePreference(update);
defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply();
diff --git a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java
index d2f56b487..bc183d08a 100644
--- a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java
@@ -1,34 +1,48 @@
package org.schabi.newpipe.settings;
+import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService;
+
import android.os.Bundle;
+import android.widget.Toast;
import androidx.preference.Preference;
import org.schabi.newpipe.R;
-import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService;
-
public class UpdateSettingsFragment extends BasePreferenceFragment {
private final Preference.OnPreferenceChangeListener updatePreferenceChange
= (preference, checkForUpdates) -> {
defaultPreferences.edit()
.putBoolean(getString(R.string.update_app_key), (boolean) checkForUpdates).apply();
- if ((boolean) checkForUpdates) {
- // Search for updates immediately when update checks are enabled.
- // Reset the expire time. This is necessary to check for an update immediately.
- defaultPreferences.edit()
- .putLong(getString(R.string.update_expiry_key), 0).apply();
- startNewVersionCheckService();
- }
+ if ((boolean) checkForUpdates) {
+ checkNewVersionNow();
+ }
return true;
};
+ private final Preference.OnPreferenceClickListener manualUpdateClick
+ = preference -> {
+ Toast.makeText(getContext(), R.string.checking_updates_toast, Toast.LENGTH_SHORT).show();
+ checkNewVersionNow();
+ return true;
+ };
+
+ private void checkNewVersionNow() {
+ // Search for updates immediately when update checks are enabled.
+ // Reset the expire time. This is necessary to check for an update immediately.
+ defaultPreferences.edit()
+ .putLong(getString(R.string.update_expiry_key), 0).apply();
+ startNewVersionCheckService();
+ }
+
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResource(R.xml.update_settings);
- final String updateToggleKey = getString(R.string.update_app_key);
- findPreference(updateToggleKey).setOnPreferenceChangeListener(updatePreferenceChange);
+ findPreference(getString(R.string.update_app_key))
+ .setOnPreferenceChangeListener(updatePreferenceChange);
+ findPreference(getString(R.string.manual_update_key))
+ .setOnPreferenceClickListener(manualUpdateClick);
}
}
diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml
index 9489ef543..1c57178b4 100644
--- a/app/src/main/res/values/settings_keys.xml
+++ b/app/src/main/res/values/settings_keys.xml
@@ -383,6 +383,7 @@
update_app_key
+ manual_update_key
update_pref_screen_key
update_expiry_key
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 897ec0af8..2ad07b4c5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -517,6 +517,8 @@
Updates
Show a notification to prompt app update when a new version is available
+ Check for updates
+ Manually check for new versions
Minimize on app switch
Action when switching to other app from main video player — %s
@@ -547,6 +549,7 @@
recovering
Queue
Action denied by the system
+ Checking for updates…
Download failed
diff --git a/app/src/main/res/xml/update_settings.xml b/app/src/main/res/xml/update_settings.xml
index adaa47352..ef121ec4e 100644
--- a/app/src/main/res/xml/update_settings.xml
+++ b/app/src/main/res/xml/update_settings.xml
@@ -12,4 +12,11 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />
+
+