From e7abeb5ad91afb700f0d914ea1906a5c05f18b89 Mon Sep 17 00:00:00 2001 From: Kartikey Kushwaha Date: Fri, 17 Aug 2018 00:53:42 +0530 Subject: [PATCH] Added version code check. --- app/src/main/java/org/schabi/newpipe/App.java | 30 +++++++++++-------- .../newpipe/CheckForNewAppVersionTask.java | 10 ++++--- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index fe64d95fb..a9002fda2 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -209,21 +209,25 @@ public class App extends Application { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.createNotificationChannel(mChannel); - // Set up notification channel for app update - final String appUpdateId - = getString(R.string.app_update_notification_channel_id); - final CharSequence appUpdateName - = getString(R.string.app_update_notification_channel_name); - final String appUpdateDescription - = getString(R.string.app_update_notification_channel_description); + // Set up notification channel for app update only if it's a github apk. - NotificationChannel appUpdateChannel - = new NotificationChannel(appUpdateId, appUpdateName, importance); - appUpdateChannel.setDescription(appUpdateDescription); + if (!BuildConfig.FLAVOR.equals(getString(R.string.app_flavor_github))) { - NotificationManager appUpdateNotificationManager - = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - appUpdateNotificationManager.createNotificationChannel(appUpdateChannel); + final String appUpdateId + = getString(R.string.app_update_notification_channel_id); + final CharSequence appUpdateName + = getString(R.string.app_update_notification_channel_name); + final String appUpdateDescription + = getString(R.string.app_update_notification_channel_description); + + NotificationChannel appUpdateChannel + = new NotificationChannel(appUpdateId, appUpdateName, importance); + appUpdateChannel.setDescription(appUpdateDescription); + + NotificationManager appUpdateNotificationManager + = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + appUpdateNotificationManager.createNotificationChannel(appUpdateChannel); + } } @Nullable diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java index 134fb3406..b6b269bb5 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java @@ -112,10 +112,10 @@ public class CheckForNewAppVersionTask extends AsyncTask { JSONObject githubStableObject = githubObject.getJSONObject("stable"); String versionName = githubStableObject.getString("version"); - // String versionCode = githubStableObject.getString("version_code"); + String versionCode = githubStableObject.getString("version_code"); String apkLocationUrl = githubStableObject.getString("apk"); - compareAppVersionAndShowNotification(versionName, apkLocationUrl); + compareAppVersionAndShowNotification(versionName, apkLocationUrl, versionCode); } catch (JSONException ex) { ex.printStackTrace(); @@ -129,11 +129,13 @@ public class CheckForNewAppVersionTask extends AsyncTask { * @param versionName * @param apkLocationUrl */ - private void compareAppVersionAndShowNotification(String versionName, String apkLocationUrl) { + private void compareAppVersionAndShowNotification(String versionName, + String apkLocationUrl, + String versionCode) { int NOTIFICATION_ID = 2000; - if (!BuildConfig.VERSION_NAME.equals(versionName.replace("v", ""))) { + if (BuildConfig.VERSION_CODE < Integer.valueOf(versionCode)) { // A pending intent to open the apk location url in the browser. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl));