From be8bc359a2d98202e0d2b5932b475b04e6ef65d7 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 7 Jun 2020 09:59:25 +0200 Subject: [PATCH] Added option to show notifications for contacts only --- app/src/main/java/eu/faircode/email/Core.java | 7 +++++++ .../email/FragmentOptionsNotifications.java | 14 +++++++++++++- .../res/layout/fragment_options_notifications.xml | 13 ++++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 35e824456c..febc6b03d5 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1501,6 +1501,8 @@ class Core { EntityAccount account, final EntityFolder folder, POP3Folder ifolder, POP3Store istore, State state) throws MessagingException { DB db = DB.getInstance(context); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean notify_known = prefs.getBoolean("notify_known", false); Log.i(folder.name + " POP sync type=" + folder.type + " connected=" + (ifolder != null)); @@ -1641,6 +1643,8 @@ class Core { message.sender = MessageHelper.getSortKey(message.from); Uri lookupUri = ContactInfo.getLookupUri(message.from); message.avatar = (lookupUri == null ? null : lookupUri.toString()); + if (message.avatar == null && notify_known) + message.ui_ignored = true; // No MX check @@ -2142,6 +2146,7 @@ class Core { DB db = DB.getInstance(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean notify_known = prefs.getBoolean("notify_known", false); // Find message by uid (fast, no headers required) EntityMessage message = db.message().getMessageByUid(folder.id, uid); @@ -2276,6 +2281,8 @@ class Core { message.sender = MessageHelper.getSortKey(message.from); Uri lookupUri = ContactInfo.getLookupUri(message.from); message.avatar = (lookupUri == null ? null : lookupUri.toString()); + if (message.avatar == null && notify_known) + message.ui_ignored = true; boolean check_mx = prefs.getBoolean("check_mx", false); if (check_mx) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index 8f42c88404..a20d55d351 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -70,6 +70,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared private SwitchCompat swBadge; private SwitchCompat swUnseenIgnored; + private SwitchCompat swNotifyKnown; private SwitchCompat swNotifySummary; private SwitchCompat swNotifyRemove; private SwitchCompat swNotifyClear; @@ -90,7 +91,8 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared "notify_flag", "notify_seen", "notify_snooze", "light", "sound", "badge", "unseen_ignored", - "notify_summary", "notify_remove", "notify_clear", "notify_preview", "notify_preview_all", "wearable_preview", + "notify_known", "notify_summary", "notify_remove", "notify_clear", + "notify_preview", "notify_preview_all", "wearable_preview", "biometrics_notify", "alert_once" }; @@ -126,6 +128,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swBadge = view.findViewById(R.id.swBadge); swUnseenIgnored = view.findViewById(R.id.swUnseenIgnored); + swNotifyKnown = view.findViewById(R.id.swNotifyKnown); swNotifySummary = view.findViewById(R.id.swNotifySummary); swNotifyRemove = view.findViewById(R.id.swNotifyRemove); swNotifyClear = view.findViewById(R.id.swNotifyClear); @@ -300,6 +303,14 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared } }); + swNotifyKnown.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("notify_known", checked).apply(); + enableOptions(); + } + }); + swNotifySummary.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -434,6 +445,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swBadge.setChecked(prefs.getBoolean("badge", true)); swUnseenIgnored.setChecked(prefs.getBoolean("unseen_ignored", false)); + swNotifyKnown.setChecked(prefs.getBoolean("notify_known", false)); swNotifySummary.setChecked(prefs.getBoolean("notify_summary", false)); swNotifyRemove.setChecked(prefs.getBoolean("notify_remove", true)); swNotifyClear.setChecked(prefs.getBoolean("notify_clear", false)); diff --git a/app/src/main/res/layout/fragment_options_notifications.xml b/app/src/main/res/layout/fragment_options_notifications.xml index 0b391901f0..b0e19bf228 100644 --- a/app/src/main/res/layout/fragment_options_notifications.xml +++ b/app/src/main/res/layout/fragment_options_notifications.xml @@ -327,6 +327,17 @@ app:layout_constraintTop_toBottomOf="@id/tvBadgeHint" app:switchPadding="12dp" /> + + Show launcher icon with number of new messages Let the number of new messages match the number of notifications + Show notifications for contacts only Show summary notification only Show message preview in notifications Preview all text