diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index f436a26b8..77c6b6cb0 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -63,6 +63,7 @@ import io.reactivex.plugins.RxJavaPlugins; public class App extends Application { protected static final String TAG = App.class.toString(); private RefWatcher refWatcher; + private static App context; @SuppressWarnings("unchecked") private static final Class[] reportSenderFactoryClasses = new Class[]{AcraReportSenderFactory.class}; @@ -85,6 +86,8 @@ public class App extends Application { } refWatcher = installLeakCanary(); + context = this; + // Initialize settings first because others inits can use its values SettingsActivity.initSettings(this); @@ -202,6 +205,22 @@ 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); + + NotificationChannel appUpdateChannel + = new NotificationChannel(appUpdateId, appUpdateName, importance); + appUpdateChannel.setDescription(appUpdateDescription); + + NotificationManager appUpdateNotificationManager + = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + appUpdateNotificationManager.createNotificationChannel(appUpdateChannel); } @Nullable @@ -217,4 +236,8 @@ public class App extends Application { protected boolean isDisposedRxExceptionsReported() { return false; } + + public static App getContext() { + return context; + } } diff --git a/app/src/main/java/org/schabi/newpipe/FetchAppVersionTask.java b/app/src/main/java/org/schabi/newpipe/FetchAppVersionTask.java index 2f98fe1ad..75da96096 100644 --- a/app/src/main/java/org/schabi/newpipe/FetchAppVersionTask.java +++ b/app/src/main/java/org/schabi/newpipe/FetchAppVersionTask.java @@ -1,7 +1,12 @@ package org.schabi.newpipe; +import android.app.Application; +import android.app.PendingIntent; +import android.content.Intent; +import android.net.Uri; import android.os.AsyncTask; -import android.util.Log; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.NotificationManagerCompat; import org.json.JSONException; import org.json.JSONObject; @@ -88,8 +93,6 @@ public class FetchAppVersionTask extends AsyncTask { if (output != null) { - Log.i("output---", output); - try { JSONObject mainObject = new JSONObject(output); JSONObject flavoursObject = mainObject.getJSONObject("flavors"); @@ -108,11 +111,37 @@ public class FetchAppVersionTask extends AsyncTask { } } + /** + * Method to compare + * @param versionName + * @param apkLocationUrl + */ private void compareAppVersionAndShowNotification(String versionName, String apkLocationUrl) { - if (!BuildConfig.VERSION_NAME.equals(versionName)) { + int NOTIFICATION_ID = 2000; + if (!BuildConfig.VERSION_NAME.equals(versionName.replace("v", ""))) { + Application app = App.getContext(); + + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl)); + PendingIntent pendingIntent + = PendingIntent.getActivity(app, 0, intent, 0); + + NotificationCompat.Builder notificationBuilder = new NotificationCompat + .Builder(app, app.getString(R.string.app_update_notification_channel_id)) + .setSmallIcon(R.drawable.ic_newpipe_triangle_white) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setContentIntent(pendingIntent) + .setAutoCancel(true) + .setContentTitle(app.getString(R.string.app_update_notification_content_title)) + .setContentText(app.getString(R.string.app_update_notification_content_text) + + " " + versionName); + + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(app); + + // notificationId is a unique int for each notification that you must define + notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ee80536f..6ad772494 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -144,6 +144,10 @@ NewPipe Notification Notifications for NewPipe Background and Popup Players + newpipeAppUpdate + App Update Notification + Notifications for new NewPipe version + [Unknown] Toggle Orientation @@ -504,4 +508,8 @@ 144p + + NewPipe Update Available + Tap to download +