From d018e9b577818036ebe2265001af1eed6193aa64 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 23 Apr 2018 05:32:19 +0100 Subject: [PATCH] Removed service foreground notification. Tapping on the download progress notification should open the app. --- .../java/io/lbry/browser/LbrynetService.java | 5 ++++ .../reactmodules/DownloadManagerModule.java | 26 +++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/lbry/browser/LbrynetService.java b/src/main/java/io/lbry/browser/LbrynetService.java index e089ac3..ce51b40 100644 --- a/src/main/java/io/lbry/browser/LbrynetService.java +++ b/src/main/java/io/lbry/browser/LbrynetService.java @@ -34,6 +34,11 @@ public class LbrynetService extends PythonService { public static LbrynetService serviceInstance; + @Override + public boolean canDisplayNotification() { + return false; + } + @Override public int startType() { return START_STICKY; diff --git a/src/main/java/io/lbry/browser/reactmodules/DownloadManagerModule.java b/src/main/java/io/lbry/browser/reactmodules/DownloadManagerModule.java index 8389f4b..ecd97c9 100644 --- a/src/main/java/io/lbry/browser/reactmodules/DownloadManagerModule.java +++ b/src/main/java/io/lbry/browser/reactmodules/DownloadManagerModule.java @@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import io.lbry.browser.MainActivity; import io.lbry.browser.R; import io.lbry.browser.receivers.NotificationDeletedReceiver; @@ -19,6 +20,7 @@ import java.util.HashMap; import java.util.Random; public class DownloadManagerModule extends ReactContextBaseJavaModule { + private Context context; private HashMap builders = new HashMap(); @@ -71,6 +73,13 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule { groupCreated = true; } } + + private PendingIntent getLaunchPendingIntent() { + Intent launchIntent = new Intent(context, MainActivity.class); + launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); + PendingIntent intent = PendingIntent.getActivity(context, 0, launchIntent, 0); + return intent; + } @ReactMethod public void startDownload(String id, String fileName) { @@ -78,12 +87,12 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); - builder.setContentTitle(String.format("Downloading %s...", fileName)) - .setSmallIcon(R.drawable.ic_file_download_black_24dp) + builder.setContentIntent(getLaunchPendingIntent()) + .setContentTitle(String.format("Downloading %s...", fileName)) + .setGroup(GROUP_DOWNLOADS) .setPriority(NotificationCompat.PRIORITY_LOW) - .setGroup(GROUP_DOWNLOADS); - - builder.setProgress(MAX_PROGRESS, 0, false); + .setProgress(MAX_PROGRESS, 0, false) + .setSmallIcon(R.drawable.ic_file_download_black_24dp); int notificationId = generateNotificationId(); downloadIdNotificationIdMap.put(id, notificationId); @@ -106,9 +115,10 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule { createNotificationGroup(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); NotificationCompat.Builder builder = builders.get(notificationId); - builder.setProgress(MAX_PROGRESS, new Double(progress).intValue(), false); - builder.setContentText(String.format("%.0f%% (%s / %s)", progress, formatBytes(writtenBytes), formatBytes(totalBytes))); - builder.setGroup(GROUP_DOWNLOADS); + builder.setContentIntent(getLaunchPendingIntent()) + .setContentText(String.format("%.0f%% (%s / %s)", progress, formatBytes(writtenBytes), formatBytes(totalBytes))) + .setGroup(GROUP_DOWNLOADS) + .setProgress(MAX_PROGRESS, new Double(progress).intValue(), false); notificationManager.notify(notificationId, builder.build()); if (progress == MAX_PROGRESS) {