summaryrefslogtreecommitdiff
path: root/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadNotificationManager.java
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2020-12-28 00:47:19 +0100
committercyBerta <cyberta@riseup.net>2020-12-28 00:47:19 +0100
commitc008a935f92b79cb7b6f649fc876d398e20ebb22 (patch)
tree6aed01587d06016eaeaf023952580e37b6516e4f /app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadNotificationManager.java
parent8efd199a90e6d9388400b19e9fc6b68c81284f11 (diff)
download apk, request permission and install app update
Diffstat (limited to 'app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadNotificationManager.java')
-rw-r--r--app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadNotificationManager.java86
1 files changed, 59 insertions, 27 deletions
diff --git a/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadNotificationManager.java b/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadNotificationManager.java
index 4f7f2883..aaf487aa 100644
--- a/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadNotificationManager.java
+++ b/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadNotificationManager.java
@@ -42,18 +42,14 @@ public class DownloadNotificationManager {
}
public void buildDownloadFoundNotification() {
- NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ NotificationManager notificationManager = initNotificationManager();
if (notificationManager == null) {
return;
}
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- createNotificationChannel(notificationManager);
- }
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.context, DownloadService.NOTIFICATION_CHANNEL_NEWSTATUS_ID);
- notificationBuilder.setAutoCancel(true)
- .setDefaults(Notification.DEFAULT_ALL)
+ NotificationCompat.Builder notificationBuilder = initNotificationBuilderDefaults();
+ notificationBuilder
+ .setSmallIcon(R.drawable.ic_about_36)
.setWhen(System.currentTimeMillis())
- .setSmallIcon(R.mipmap.ic_launcher)
.setTicker(context.getString(R.string.version_update_title, context.getString(R.string.app_name)))
.setContentTitle(context.getString(R.string.version_update_title, context.getString(R.string.app_name)))
.setContentText(context.getString(R.string.version_update_found))
@@ -61,6 +57,51 @@ public class DownloadNotificationManager {
notificationManager.notify(DOWNLOAD_NOTIFICATION_ID, notificationBuilder.build());
}
+ public void buildDownloadSuccessfulNotification() {
+ NotificationManager notificationManager = initNotificationManager();
+ if (notificationManager == null) {
+ return;
+ }
+ NotificationCompat.Builder notificationBuilder = initNotificationBuilderDefaults();
+ notificationBuilder
+ .setSmallIcon(android.R.drawable.stat_sys_download_done)
+ .setWhen(System.currentTimeMillis())
+ .setTicker(context.getString(R.string.version_update_title, context.getString(R.string.app_name)))
+ .setContentTitle(context.getString(R.string.version_update_download_title, context.getString(R.string.app_name)))
+ .setContentText(context.getString(R.string.version_update_download_description))
+ .setContentIntent(getInstallIntent());
+ notificationManager.notify(DOWNLOAD_NOTIFICATION_ID, notificationBuilder.build());
+ }
+
+ public void buildDownloadUpdateProgress(int progress) {
+ NotificationManager notificationManager = initNotificationManager();
+ if (notificationManager == null) {
+ return;
+ }
+
+ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.context, DownloadService.NOTIFICATION_CHANNEL_NEWSTATUS_ID);
+ notificationBuilder
+ .setDefaults(Notification.DEFAULT_ALL)
+ .setAutoCancel(false)
+ .setOngoing(true)
+ .setSmallIcon(android.R.drawable.stat_sys_download)
+ .setContentTitle(context.getString(R.string.version_update_apk_description, context.getString(R.string.app_name)))
+ .setProgress(100, progress, false)
+ .setContentIntent(getDownloadIntent());
+ notificationManager.notify(DOWNLOAD_NOTIFICATION_ID, notificationBuilder.build());
+ }
+
+ private NotificationManager initNotificationManager() {
+ NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ if (notificationManager == null) {
+ return null;
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ createNotificationChannel(notificationManager);
+ }
+ return notificationManager;
+ }
+
@TargetApi(26)
private void createNotificationChannel(NotificationManager notificationManager) {
CharSequence name = "Bitmask Updates";
@@ -75,7 +116,13 @@ public class DownloadNotificationManager {
notificationManager.createNotificationChannel(channel);
}
-
+ private NotificationCompat.Builder initNotificationBuilderDefaults() {
+ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.context, DownloadService.NOTIFICATION_CHANNEL_NEWSTATUS_ID);
+ notificationBuilder.
+ setDefaults(Notification.DEFAULT_ALL).
+ setAutoCancel(true);
+ return notificationBuilder;
+ }
private PendingIntent getDownloadIntent() {
Intent downloadIntent = new Intent(context, DownloadBroadcastReceiver.class);
@@ -83,24 +130,9 @@ public class DownloadNotificationManager {
return PendingIntent.getBroadcast(context, 0, downloadIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}
- public void buildDownloadUpdateProgress(int progress) {
- NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- if (notificationManager == null) {
- return;
- }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- createNotificationChannel(notificationManager);
- }
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.context, DownloadService.NOTIFICATION_CHANNEL_NEWSTATUS_ID);
- notificationBuilder.setAutoCancel(true)
- .setDefaults(Notification.DEFAULT_ALL)
- .setAutoCancel(false)
- .setOngoing(true)
- .setSmallIcon(R.mipmap.ic_launcher)
- .setContentTitle(context.getString(R.string.version_update_apk_description, context.getString(R.string.app_name)))
- .setProgress(100, progress, false)
- .setContentIntent(getDownloadIntent());
- notificationManager.notify(DOWNLOAD_NOTIFICATION_ID, notificationBuilder.build());
+ private PendingIntent getInstallIntent() {
+ Intent installIntent = new Intent(context, InstallActivity.class);
+ return PendingIntent.getActivity(context, 0, installIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}
public void cancelNotifications() {