From 0d147e1b3570883edc769e4bca8033da2f717ee6 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 17 Oct 2018 06:20:24 +0000 Subject: [PATCH] Allow swiping summary notification away --- .../java/eu/faircode/email/DaoMessage.java | 5 ++++ .../eu/faircode/email/ServiceSynchronize.java | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 09d27a6e..0c8e6c02 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -211,6 +211,11 @@ public interface DaoMessage { @Query("UPDATE message SET headers = :headers WHERE id = :id") int setMessageHeaders(long id, String headers); + @Query("UPDATE message SET ui_ignored = 1" + + " WHERE NOT ui_ignored" + + " AND folder IN (SELECT id FROM folder WHERE type = '" + EntityFolder.INBOX + "')") + int ignoreAll(); + @Query("DELETE FROM message WHERE id = :id") int deleteMessage(long id); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index fc964157..e0ed9a4e 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -136,9 +136,10 @@ public class ServiceSynchronize extends LifecycleService { private static final int ATTACHMENT_AUTO_DOWNLOAD_SIZE = 32 * 1024; // bytes private static final long RECONNECT_BACKOFF = 90 * 1000L; // milliseconds - static final int PI_SEEN = 1; - static final int PI_TRASH = 2; - static final int PI_IGNORED = 3; + static final int PI_CLEAR = 1; + static final int PI_SEEN = 2; + static final int PI_TRASH = 3; + static final int PI_IGNORED = 4; static final String ACTION_SYNCHRONIZE_FOLDER = BuildConfig.APPLICATION_ID + ".SYNCHRONIZE_FOLDER"; static final String ACTION_PROCESS_OPERATIONS = BuildConfig.APPLICATION_ID + ".PROCESS_OPERATIONS"; @@ -238,7 +239,15 @@ public class ServiceSynchronize extends LifecycleService { serviceManager.queue_stop(); else if ("reload".equals(action)) serviceManager.queue_reload(); - else if (action.startsWith("seen:") || action.startsWith("trash:") || action.startsWith("ignored:")) { + else if ("clear".equals(action)) { + new SimpleTask() { + @Override + protected Void onLoad(Context context, Bundle args) throws Throwable { + DB.getInstance(context).message().ignoreAll(); + return null; + } + }.load(this, new Bundle()); + } else if (action.startsWith("seen:") || action.startsWith("trash:") || action.startsWith("ignored:")) { Bundle args = new Bundle(); args.putLong("id", Long.parseLong(action.split(":")[1])); args.putString("action", action.split(":")[0]); @@ -341,6 +350,10 @@ public class ServiceSynchronize extends LifecycleService { PendingIntent piView = PendingIntent.getActivity( this, ActivityView.REQUEST_UNIFIED, view, PendingIntent.FLAG_UPDATE_CURRENT); + Intent clear = new Intent(this, ServiceSynchronize.class); + clear.setAction("clear"); + PendingIntent piClear = PendingIntent.getService(this, PI_CLEAR, clear, PendingIntent.FLAG_UPDATE_CURRENT); + // Build notification Notification.Builder builder; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) @@ -355,7 +368,7 @@ public class ServiceSynchronize extends LifecycleService { .setContentIntent(piView) .setNumber(messages.size()) .setShowWhen(false) - .setOngoing(true) + .setDeleteIntent(piClear) .setPriority(Notification.PRIORITY_DEFAULT) .setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_PRIVATE)