diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 28a281306c..29894228b5 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -4109,6 +4109,7 @@ class Core { boolean notify_reply_direct = (prefs.getBoolean("notify_reply_direct", false) && pro); boolean notify_flag = (prefs.getBoolean("notify_flag", false) && flags && pro); boolean notify_seen = (prefs.getBoolean("notify_seen", true) || !pro); + boolean notify_hide = (prefs.getBoolean("notify_hide", false) && pro); boolean notify_snooze = (prefs.getBoolean("notify_snooze", false) && pro); boolean notify_remove = prefs.getBoolean("notify_remove", true); boolean light = prefs.getBoolean("light", false); @@ -4548,6 +4549,23 @@ class Core { wactions.add(actionSeen.build()); } + if (notify_hide) { + Intent hide = new Intent(context, ServiceUI.class) + .setAction("hide:" + message.id) + .putExtra("group", group); + PendingIntent piHide = PendingIntentCompat.getService( + context, ServiceUI.PI_HIDE, hide, PendingIntent.FLAG_UPDATE_CURRENT); + NotificationCompat.Action.Builder actionHide = new NotificationCompat.Action.Builder( + R.drawable.twotone_visibility_off_24, + context.getString(R.string.title_advanced_notify_action_hide), + piHide) + .setShowsUserInterface(false) + .setAllowGeneratedReplies(false); + mbuilder.addAction(actionHide.build()); + + wactions.add(actionHide.build()); + } + if (notify_snooze) { Intent snooze = new Intent(context, ServiceUI.class) .setAction("snooze:" + message.id) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index a04fba3a55..c6fe67fe90 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -71,6 +71,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared private CheckBox cbNotifyActionReplyDirect; private CheckBox cbNotifyActionFlag; private CheckBox cbNotifyActionSeen; + private CheckBox cbNotifyActionHide; private CheckBox cbNotifyActionSnooze; private TextView tvNotifyActionsPro; private SwitchCompat swLight; @@ -105,7 +106,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared "background_service", "notify_trash", "notify_junk", "notify_block_sender", "notify_archive", "notify_move", "notify_reply", "notify_reply_direct", - "notify_flag", "notify_seen", "notify_snooze", + "notify_flag", "notify_seen", "notify_hide", "notify_snooze", "light", "sound", "badge", "unseen_ignored", "notify_background_only", "notify_known", "notify_summary", "notify_remove", "notify_clear", @@ -143,6 +144,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared cbNotifyActionReplyDirect = view.findViewById(R.id.cbNotifyActionReplyDirect); cbNotifyActionFlag = view.findViewById(R.id.cbNotifyActionFlag); cbNotifyActionSeen = view.findViewById(R.id.cbNotifyActionSeen); + cbNotifyActionHide = view.findViewById(R.id.cbNotifyActionHide); cbNotifyActionSnooze = view.findViewById(R.id.cbNotifyActionSnooze); tvNotifyActionsPro = view.findViewById(R.id.tvNotifyActionsPro); swLight = view.findViewById(R.id.swLight); @@ -306,6 +308,13 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared } }); + cbNotifyActionHide.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean checked) { + prefs.edit().putBoolean("notify_hide", checked).apply(); + } + }); + cbNotifyActionSnooze.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean checked) { @@ -544,6 +553,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared cbNotifyActionReplyDirect.setChecked(prefs.getBoolean("notify_reply_direct", false) && pro); cbNotifyActionFlag.setChecked(prefs.getBoolean("notify_flag", false) && pro); cbNotifyActionSeen.setChecked(prefs.getBoolean("notify_seen", true) || !pro); + cbNotifyActionHide.setChecked(prefs.getBoolean("notify_hide", false) && pro); cbNotifyActionSnooze.setChecked(prefs.getBoolean("notify_snooze", false) && pro); swLight.setChecked(prefs.getBoolean("light", false)); @@ -578,6 +588,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared cbNotifyActionReplyDirect.setEnabled(pro && !summary); cbNotifyActionFlag.setEnabled(pro && !summary); cbNotifyActionSeen.setEnabled(pro && !summary); + cbNotifyActionHide.setEnabled(pro && !summary); cbNotifyActionSnooze.setEnabled(pro && !summary); swNotifyPreviewAll.setEnabled(!summary && swNotifyPreview.isChecked()); swNotifyPreviewOnly.setEnabled(!summary && swNotifyPreview.isChecked()); diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index bfd73fb45d..01687ba4fe 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -54,9 +54,10 @@ public class ServiceUI extends IntentService { static final int PI_REPLY_DIRECT = 6; static final int PI_FLAG = 7; static final int PI_SEEN = 8; - static final int PI_SNOOZE = 9; - static final int PI_IGNORED = 10; - static final int PI_THREAD = 11; + static final int PI_HIDE = 9; + static final int PI_SNOOZE = 10; + static final int PI_IGNORED = 11; + static final int PI_THREAD = 12; public ServiceUI() { this(ServiceUI.class.getName()); @@ -139,6 +140,11 @@ public class ServiceUI extends IntentService { onSeen(id); break; + case "hide": + cancel(group, id); + onHide(id); + break; + case "snooze": cancel(group, id); onSnooze(id); @@ -379,6 +385,25 @@ public class ServiceUI extends IntentService { } } + private void onHide(long id) { + DB db = DB.getInstance(this); + try { + db.beginTransaction(); + + EntityMessage message = db.message().getMessage(id); + if (message == null) + return; + + db.message().setMessageSnoozed(message.id, Long.MAX_VALUE); + db.message().setMessageUiIgnored(message.id, true); + + db.setTransactionSuccessful(); + + } finally { + db.endTransaction(); + } + } + private void onSnooze(long id) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); int notify_snooze_duration = prefs.getInt("default_snooze", 1); diff --git a/app/src/main/res/layout/fragment_options_notifications.xml b/app/src/main/res/layout/fragment_options_notifications.xml index dc579811c0..20d3e4816b 100644 --- a/app/src/main/res/layout/fragment_options_notifications.xml +++ b/app/src/main/res/layout/fragment_options_notifications.xml @@ -282,6 +282,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cbNotifyActionFlag" /> + + + app:layout_constraintTop_toBottomOf="@id/cbNotifyActionHide" /> Direct reply Star Read + Hide Snooze Remove new message notification on tapping on notification Remove new message notifications on viewing message list