From 8ef702fa075529feee099e3f496ea8aea4f67520 Mon Sep 17 00:00:00 2001 From: krtkush Date: Thu, 18 Oct 2018 22:59:33 +0530 Subject: [PATCH] Removed updates options from settings in case of non github apk. --- .../gen/org/schabi/newpipe/BuildConfig.java | 8 ++++++++ .../debug/gen/org/schabi/newpipe/Manifest.java | 7 +++++++ app/src/debug/gen/org/schabi/newpipe/R.java | 7 +++++++ .../gen/org/schabi/newpipe/BuildConfig.java | 8 ++++++++ .../main/gen/org/schabi/newpipe/Manifest.java | 7 +++++++ app/src/main/gen/org/schabi/newpipe/R.java | 7 +++++++ .../newpipe/CheckForNewAppVersionTask.java | 18 +++++++++++------- .../newpipe/settings/MainSettingsFragment.java | 8 ++++++++ .../settings/UpdateSettingsFragment.java | 1 + app/src/main/res/values/settings_keys.xml | 1 + app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/main_settings.xml | 3 ++- 12 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 app/src/debug/gen/org/schabi/newpipe/BuildConfig.java create mode 100644 app/src/debug/gen/org/schabi/newpipe/Manifest.java create mode 100644 app/src/debug/gen/org/schabi/newpipe/R.java create mode 100644 app/src/main/gen/org/schabi/newpipe/BuildConfig.java create mode 100644 app/src/main/gen/org/schabi/newpipe/Manifest.java create mode 100644 app/src/main/gen/org/schabi/newpipe/R.java diff --git a/app/src/debug/gen/org/schabi/newpipe/BuildConfig.java b/app/src/debug/gen/org/schabi/newpipe/BuildConfig.java new file mode 100644 index 000000000..575afb9cb --- /dev/null +++ b/app/src/debug/gen/org/schabi/newpipe/BuildConfig.java @@ -0,0 +1,8 @@ +/*___Generated_by_IDEA___*/ + +package org.schabi.newpipe; + +/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ +public final class BuildConfig { + public final static boolean DEBUG = Boolean.parseBoolean(null); +} \ No newline at end of file diff --git a/app/src/debug/gen/org/schabi/newpipe/Manifest.java b/app/src/debug/gen/org/schabi/newpipe/Manifest.java new file mode 100644 index 000000000..10e45a45a --- /dev/null +++ b/app/src/debug/gen/org/schabi/newpipe/Manifest.java @@ -0,0 +1,7 @@ +/*___Generated_by_IDEA___*/ + +package org.schabi.newpipe; + +/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ +public final class Manifest { +} \ No newline at end of file diff --git a/app/src/debug/gen/org/schabi/newpipe/R.java b/app/src/debug/gen/org/schabi/newpipe/R.java new file mode 100644 index 000000000..088bdfb0d --- /dev/null +++ b/app/src/debug/gen/org/schabi/newpipe/R.java @@ -0,0 +1,7 @@ +/*___Generated_by_IDEA___*/ + +package org.schabi.newpipe; + +/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ +public final class R { +} \ No newline at end of file diff --git a/app/src/main/gen/org/schabi/newpipe/BuildConfig.java b/app/src/main/gen/org/schabi/newpipe/BuildConfig.java new file mode 100644 index 000000000..575afb9cb --- /dev/null +++ b/app/src/main/gen/org/schabi/newpipe/BuildConfig.java @@ -0,0 +1,8 @@ +/*___Generated_by_IDEA___*/ + +package org.schabi.newpipe; + +/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ +public final class BuildConfig { + public final static boolean DEBUG = Boolean.parseBoolean(null); +} \ No newline at end of file diff --git a/app/src/main/gen/org/schabi/newpipe/Manifest.java b/app/src/main/gen/org/schabi/newpipe/Manifest.java new file mode 100644 index 000000000..10e45a45a --- /dev/null +++ b/app/src/main/gen/org/schabi/newpipe/Manifest.java @@ -0,0 +1,7 @@ +/*___Generated_by_IDEA___*/ + +package org.schabi.newpipe; + +/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ +public final class Manifest { +} \ No newline at end of file diff --git a/app/src/main/gen/org/schabi/newpipe/R.java b/app/src/main/gen/org/schabi/newpipe/R.java new file mode 100644 index 000000000..088bdfb0d --- /dev/null +++ b/app/src/main/gen/org/schabi/newpipe/R.java @@ -0,0 +1,7 @@ +/*___Generated_by_IDEA___*/ + +package org.schabi.newpipe; + +/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ +public final class R { +} \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java index fd94980c9..9ab0f5d36 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java @@ -38,11 +38,10 @@ import java.security.cert.X509Certificate; */ public class CheckForNewAppVersionTask extends AsyncTask { - private Application app = App.getContext(); - - private String GITHUB_APK_SHA1 = "B0:2E:90:7C:1C:D6:FC:57:C3:35:F0:88:D0:8F:50:5F:94:E4:D2:15"; - private String newPipeApiUrl = "https://newpipe.schabi.org/api/data.json"; - private int timeoutPeriod = 10000; + private static final Application app = App.getContext(); + private static final String GITHUB_APK_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 newPipeApiUrl = "https://newpipe.schabi.org/api/data.json"; + private static final int timeoutPeriod = 10000; private SharedPreferences mPrefs; @@ -54,7 +53,7 @@ public class CheckForNewAppVersionTask extends AsyncTask { // Check if user has enabled/ disabled update checking // and if the current apk is a github one or not. if (!mPrefs.getBoolean(app.getString(R.string.update_app_key), true) - || !getCertificateSHA1Fingerprint().equals(GITHUB_APK_SHA1)) { + || !isGithubApk()) { this.cancel(true); } } @@ -179,7 +178,7 @@ public class CheckForNewAppVersionTask extends AsyncTask { * Method to get the apk's SHA1 key. * https://stackoverflow.com/questions/9293019/get-certificate-fingerprint-from-android-app#22506133 */ - private String getCertificateSHA1Fingerprint() { + private static String getCertificateSHA1Fingerprint() { PackageManager pm = app.getPackageManager(); String packageName = app.getPackageName(); @@ -240,4 +239,9 @@ public class CheckForNewAppVersionTask extends AsyncTask { } return str.toString(); } + + public static boolean isGithubApk() { + + return getCertificateSHA1Fingerprint().equals(GITHUB_APK_SHA1); + } } 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 5e07e2b12..43270926e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.support.v7.preference.Preference; import org.schabi.newpipe.BuildConfig; +import org.schabi.newpipe.CheckForNewAppVersionTask; import org.schabi.newpipe.R; public class MainSettingsFragment extends BasePreferenceFragment { @@ -13,6 +14,13 @@ public class MainSettingsFragment extends BasePreferenceFragment { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.main_settings); + if (!CheckForNewAppVersionTask.isGithubApk()) { + 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(); + } + if (!DEBUG) { final Preference debug = findPreference(getString(R.string.debug_pref_screen_key)); getPreferenceScreen().removePreference(debug); 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 f6aab7cda..157f52a0e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.preference.Preference; +import org.schabi.newpipe.CheckForNewAppVersionTask; import org.schabi.newpipe.R; public class UpdateSettingsFragment extends BasePreferenceFragment { diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index e282a3bf5..9c6ae92b0 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -205,6 +205,7 @@ update_app_key + update_pref_screen_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f8c7932a7..f7e461829 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -529,7 +529,7 @@ Switch View - NewPipe Update Available + NewPipe Update Available! Tap to download diff --git a/app/src/main/res/xml/main_settings.xml b/app/src/main/res/xml/main_settings.xml index 3773460d6..74450f77b 100644 --- a/app/src/main/res/xml/main_settings.xml +++ b/app/src/main/res/xml/main_settings.xml @@ -32,7 +32,8 @@ + android:title="@string/settings_category_updates_title" + android:key="update_pref_screen_key"/>