2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Cleanup ReceiveNotification

This commit is contained in:
Nicolas Fella
2019-06-04 12:51:24 +00:00
parent 4aa365e4ff
commit 22e7b91bb3
2 changed files with 6 additions and 13 deletions

View File

@@ -66,8 +66,7 @@ public class CompositeReceiveFileJob extends BackgroundJob<Device, Void> {
lock = new Object(); lock = new Object();
networkPacketList = new ArrayList<>(); networkPacketList = new ArrayList<>();
receiveNotification = new ReceiveNotification(device); receiveNotification = new ReceiveNotification(device, getId());
receiveNotification.addCancelAction(getId());
currentFileNum = 0; currentFileNum = 0;
totalNumFiles = 0; totalNumFiles = 0;
totalPayloadSize = 0; totalPayloadSize = 0;

View File

@@ -48,15 +48,16 @@ class ReceiveNotification {
private final int notificationId; private final int notificationId;
private NotificationCompat.Builder builder; private NotificationCompat.Builder builder;
private final Device device; private final Device device;
private long currentJobId; private long jobId;
//https://documentation.onesignal.com/docs/android-customizations#section-big-picture //https://documentation.onesignal.com/docs/android-customizations#section-big-picture
private static final int bigImageWidth = 1440; private static final int bigImageWidth = 1440;
private static final int bigImageHeight = 720; private static final int bigImageHeight = 720;
public ReceiveNotification(Device device) { public ReceiveNotification(Device device, long jobId) {
this.device = device; this.device = device;
this.jobId = jobId;
notificationId = (int) System.currentTimeMillis(); notificationId = (int) System.currentTimeMillis();
notificationManager = (NotificationManager) device.getContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager = (NotificationManager) device.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER) builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER)
@@ -64,6 +65,7 @@ class ReceiveNotification {
.setAutoCancel(true) .setAutoCancel(true)
.setOngoing(true) .setOngoing(true)
.setProgress(100, 0, true); .setProgress(100, 0, true);
addCancelAction();
} }
public void show() { public void show() {
@@ -74,10 +76,8 @@ class ReceiveNotification {
notificationManager.cancel(notificationId); notificationManager.cancel(notificationId);
} }
public void addCancelAction(long jobId) { public void addCancelAction() {
builder.mActions.clear();
currentJobId = jobId;
Intent cancelIntent = new Intent(device.getContext(), ShareBroadcastReceiver.class); Intent cancelIntent = new Intent(device.getContext(), ShareBroadcastReceiver.class);
cancelIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); cancelIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE); 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); 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) { public void setTitle(String title) {
builder.setContentTitle(title); builder.setContentTitle(title);
builder.setTicker(title); builder.setTicker(title);