Skip to content

Commit

Permalink
Fix permanent notification, fixes #800 (#801)
Browse files Browse the repository at this point in the history
This sets a "notification cancelled" intent which removes the persisted entry when the notification is swiped away.
  • Loading branch information
dmfs authored Jun 7, 2019
1 parent dcbef26 commit e870f6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions opentasks/src/main/java/org/dmfs/tasks/actions/NotifyAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import android.net.Uri;
import android.os.Build;
import android.os.RemoteException;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import android.text.format.DateUtils;

import org.dmfs.android.bolts.color.colors.ResourceColor;
Expand All @@ -52,6 +50,9 @@
import org.dmfs.tasks.notification.signals.Conditional;
import org.dmfs.tasks.utils.DateFormatter;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;


/**
* Post a notification.
Expand Down Expand Up @@ -128,6 +129,11 @@ public void execute(Context context, ContentProviderClient contentProviderClient
.setData(taskUri),
PendingIntent.FLAG_UPDATE_CURRENT));

// make sure we un-persist the notification when its cancelled
builder.setDeleteIntent(PendingIntent.getBroadcast(context, notificationId,
new Intent(context, ActionReceiver.class).setAction(ActionService.ACTION_REMOVE_NOTIFICATION).setData(taskUri),
PendingIntent.FLAG_UPDATE_CURRENT));

if (!new TaskIsClosed(data).value())
{
builder.addAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import android.content.OperationApplicationException;
import android.net.Uri;
import android.os.RemoteException;
import androidx.annotation.NonNull;
import androidx.core.app.JobIntentService;
import android.util.Log;

import org.dmfs.android.contentpal.Projection;
Expand Down Expand Up @@ -54,10 +52,14 @@
import org.dmfs.tasks.actions.OpenAction;
import org.dmfs.tasks.actions.PinAction;
import org.dmfs.tasks.actions.PostUndoAction;
import org.dmfs.tasks.actions.RemoveNotificationAction;
import org.dmfs.tasks.actions.TaskAction;
import org.dmfs.tasks.actions.WipeNotificationAction;
import org.dmfs.tasks.contract.TaskContract;

import androidx.annotation.NonNull;
import androidx.core.app.JobIntentService;


/**
* A {@link JobIntentService} which handles notification actions.
Expand All @@ -76,6 +78,7 @@ public final class ActionService extends JobIntentService
public static final String ACTION_UNPIN = "org.dmfs.tasks.intent.UNPIN";
public static final String ACTION_OPEN_TASK = "org.dmfs.tasks.intent.OPEN_TASK";
public static final String ACTION_OPEN_TASK_CANCEL_NOTIFICATION = "org.dmfs.tasks.intent.OPEN_CANCEL_TASK";
public static final String ACTION_REMOVE_NOTIFICATION = "org.dmfs.tasks.intent.CANCEL_NOTIFICATION";
public static final String ACTION_NEXT_DAY = "org.dmfs.tasks.intent.ACTION_DAY_CHANGED";
public static final String ACTION_RENOTIFY = "org.dmfs.tasks.intent.NOTIFY";
public static final String ACTION_DEFER_1D = "org.dmfs.tasks.action.notification.DELAY_1D";
Expand Down Expand Up @@ -164,6 +167,10 @@ private TaskAction resolveAction(String action)
// just open the task and cancel the notification
return new Composite(new OpenAction(), new WipeNotificationAction());

case ACTION_REMOVE_NOTIFICATION:
// remove the notification
return new RemoveNotificationAction();

case ACTION_DEFER_1D:
// defer the due date and remove notification if not pinned and due date is in the future
return new Composite(
Expand Down

0 comments on commit e870f6f

Please sign in to comment.