From 22e7b91bb35f90b30ca18214691240b6f92ff324 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Tue, 4 Jun 2019 12:51:24 +0000 Subject: [PATCH] Cleanup ReceiveNotification --- .../SharePlugin/CompositeReceiveFileJob.java | 3 +-- .../Plugins/SharePlugin/ReceiveNotification.java | 16 +++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileJob.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileJob.java index 98517eca..b94fff72 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileJob.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileJob.java @@ -66,8 +66,7 @@ public class CompositeReceiveFileJob extends BackgroundJob { lock = new Object(); networkPacketList = new ArrayList<>(); - receiveNotification = new ReceiveNotification(device); - receiveNotification.addCancelAction(getId()); + receiveNotification = new ReceiveNotification(device, getId()); currentFileNum = 0; totalNumFiles = 0; totalPayloadSize = 0; diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ReceiveNotification.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ReceiveNotification.java index 848ec315..19588f34 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ReceiveNotification.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ReceiveNotification.java @@ -48,15 +48,16 @@ class ReceiveNotification { private final int notificationId; private NotificationCompat.Builder builder; private final Device device; - private long currentJobId; + private long jobId; //https://documentation.onesignal.com/docs/android-customizations#section-big-picture private static final int bigImageWidth = 1440; private static final int bigImageHeight = 720; - public ReceiveNotification(Device device) { + public ReceiveNotification(Device device, long jobId) { this.device = device; + this.jobId = jobId; notificationId = (int) System.currentTimeMillis(); notificationManager = (NotificationManager) device.getContext().getSystemService(Context.NOTIFICATION_SERVICE); builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER) @@ -64,6 +65,7 @@ class ReceiveNotification { .setAutoCancel(true) .setOngoing(true) .setProgress(100, 0, true); + addCancelAction(); } public void show() { @@ -74,10 +76,8 @@ class ReceiveNotification { notificationManager.cancel(notificationId); } - public void addCancelAction(long jobId) { - builder.mActions.clear(); + public void addCancelAction() { - currentJobId = jobId; Intent cancelIntent = new Intent(device.getContext(), ShareBroadcastReceiver.class); cancelIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE); @@ -88,12 +88,6 @@ class ReceiveNotification { builder.addAction(R.drawable.ic_reject_pairing, device.getContext().getString(R.string.cancel), cancelPendingIntent); } - public long getCurrentJobId() { return currentJobId; } - - public int getNotificationId() { - return notificationId; - } - public void setTitle(String title) { builder.setContentTitle(title); builder.setTicker(title);