From bfe383594c8ae976cb20e5fb4321c07a62fe9639 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 26 Sep 2019 21:28:05 +0200 Subject: [PATCH] Added notify action junk --- app/src/main/java/eu/faircode/email/Core.java | 14 ++++++ .../email/FragmentOptionsNotifications.java | 14 +++++- .../java/eu/faircode/email/ServiceUI.java | 49 +++++++------------ .../layout/fragment_options_notifications.xml | 11 ++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 55 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 3a65fb7ad8..92f281375e 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -2475,6 +2475,7 @@ class Core { boolean flags = prefs.getBoolean("flags", true); boolean notify_preview = prefs.getBoolean("notify_preview", true); boolean notify_trash = (prefs.getBoolean("notify_trash", true) || !pro); + boolean notify_junk = (prefs.getBoolean("notify_junk", true) && pro); boolean notify_archive = (prefs.getBoolean("notify_archive", true) || !pro); boolean notify_reply = (prefs.getBoolean("notify_reply", false) && pro); boolean notify_reply_direct = (prefs.getBoolean("notify_reply_direct", false) && pro); @@ -2671,6 +2672,19 @@ class Core { mbuilder.addAction(actionTrash.build()); } + if (notify_junk && + db.folder().getFolderByType(message.account, EntityFolder.JUNK) != null) { + Intent junk = new Intent(context, ServiceUI.class) + .setAction("junk:" + message.id) + .putExtra("group", group); + PendingIntent piJunk = PendingIntent.getService(context, ServiceUI.PI_JUNK, junk, PendingIntent.FLAG_UPDATE_CURRENT); + NotificationCompat.Action.Builder actionJunk = new NotificationCompat.Action.Builder( + R.drawable.baseline_flag_24, + context.getString(R.string.title_advanced_notify_action_junk), + piJunk); + mbuilder.addAction(actionJunk.build()); + } + if (notify_archive && db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE) != null) { Intent archive = new Intent(context, ServiceUI.class) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index daf3d00d06..7726ab449b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -58,6 +58,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared private SwitchCompat swUnseenIgnored; private SwitchCompat swNotifyPreview; private CheckBox cbNotifyActionTrash; + private CheckBox cbNotifyActionJunk; private CheckBox cbNotifyActionArchive; private CheckBox cbNotifyActionReply; private CheckBox cbNotifyActionReplyDirect; @@ -79,7 +80,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared private final static String[] RESET_OPTIONS = new String[]{ "badge", "unseen_ignored", - "notify_preview", "notify_trash", "notify_archive", "notify_reply", "notify_reply_direct", "notify_flag", + "notify_preview", "notify_trash", "notify_junk", "notify_archive", "notify_reply", "notify_reply_direct", "notify_flag", "notify_seen", "notify_snooze", "notify_snooze_duration", "notify_remove", "biometrics_notify", "light", "sound", "alert_once" @@ -99,6 +100,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swUnseenIgnored = view.findViewById(R.id.swUnseenIgnored); swNotifyPreview = view.findViewById(R.id.swNotifyPreview); cbNotifyActionTrash = view.findViewById(R.id.cbNotifyActionTrash); + cbNotifyActionJunk = view.findViewById(R.id.cbNotifyActionJunk); cbNotifyActionArchive = view.findViewById(R.id.cbNotifyActionArchive); cbNotifyActionReply = view.findViewById(R.id.cbNotifyActionReply); cbNotifyActionReplyDirect = view.findViewById(R.id.cbNotifyActionReplyDirect); @@ -155,6 +157,13 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared } }); + cbNotifyActionJunk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean checked) { + prefs.edit().putBoolean("notify_junk", checked).apply(); + } + }); + cbNotifyActionArchive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean checked) { @@ -338,6 +347,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true)); cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true) || !pro); + cbNotifyActionJunk.setChecked(prefs.getBoolean("notify_junk", false) && pro); cbNotifyActionArchive.setChecked(prefs.getBoolean("notify_archive", true) || !pro); cbNotifyActionReply.setChecked(prefs.getBoolean("notify_reply", false) && pro); cbNotifyActionReplyDirect.setChecked(prefs.getBoolean("notify_reply_direct", false) && pro); @@ -347,8 +357,10 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared etNotifyActionSnooze.setText(Integer.toString(prefs.getInt("notify_snooze_duration", 60))); cbNotifyActionTrash.setEnabled(pro); + cbNotifyActionJunk.setEnabled(pro); cbNotifyActionArchive.setEnabled(pro); cbNotifyActionReply.setEnabled(pro); + cbNotifyActionReplyDirect.setEnabled(pro); cbNotifyActionFlag.setEnabled(pro); cbNotifyActionSeen.setEnabled(pro); cbNotifyActionSnooze.setEnabled(pro); diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index 65dc83883a..7e01ea80b9 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -42,13 +42,14 @@ import javax.mail.internet.InternetAddress; public class ServiceUI extends IntentService { static final int PI_CLEAR = 1; static final int PI_TRASH = 2; - static final int PI_ARCHIVE = 3; - static final int PI_REPLY_DIRECT = 4; - static final int PI_FLAG = 5; - static final int PI_SEEN = 6; - static final int PI_SNOOZE = 7; - static final int PI_IGNORED = 8; - static final int PI_WAKEUP = 9; + static final int PI_JUNK = 3; + static final int PI_ARCHIVE = 4; + static final int PI_REPLY_DIRECT = 5; + static final int PI_FLAG = 6; + static final int PI_SEEN = 7; + static final int PI_SNOOZE = 8; + static final int PI_IGNORED = 9; + static final int PI_WAKEUP = 10; public ServiceUI() { this(ServiceUI.class.getName()); @@ -97,12 +98,17 @@ public class ServiceUI extends IntentService { case "trash": cancel(group, id); - onTrash(id); + onMove(id, EntityFolder.TRASH); + break; + + case "junk": + cancel(group, id); + onMove(id, EntityFolder.JUNK); break; case "archive": cancel(group, id); - onArchive(id); + onMove(id, EntityFolder.ARCHIVE); break; case "reply": @@ -158,7 +164,7 @@ public class ServiceUI extends IntentService { nm.cancel(tag, 1); } - private void onTrash(long id) { + private void onMove(long id, String folderType) { DB db = DB.getInstance(this); try { db.beginTransaction(); @@ -167,7 +173,7 @@ public class ServiceUI extends IntentService { if (message == null) return; - EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH); + EntityFolder trash = db.folder().getFolderByType(message.account, folderType); if (trash != null) EntityOperation.queue(this, message, EntityOperation.MOVE, trash.id); @@ -177,27 +183,6 @@ public class ServiceUI extends IntentService { } } - private void onArchive(long id) { - DB db = DB.getInstance(this); - try { - db.beginTransaction(); - - EntityMessage message = db.message().getMessage(id); - if (message == null) - return; - - EntityFolder archive = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE); - if (archive == null) - archive = db.folder().getFolderByType(message.account, EntityFolder.TRASH); - if (archive != null) - EntityOperation.queue(this, message, EntityOperation.MOVE, archive.id); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } - private void onReplyDirect(long id, Intent intent) throws IOException { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean prefix_once = prefs.getBoolean("prefix_once", true); diff --git a/app/src/main/res/layout/fragment_options_notifications.xml b/app/src/main/res/layout/fragment_options_notifications.xml index 2cb56fbab8..9a37fc60dd 100644 --- a/app/src/main/res/layout/fragment_options_notifications.xml +++ b/app/src/main/res/layout/fragment_options_notifications.xml @@ -92,6 +92,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvNotifyActions" /> + + + app:layout_constraintTop_toBottomOf="@id/cbNotifyActionJunk" /> Show message preview in notifications Notification actions Trash + Spam Archive Reply Direct reply