diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index ce94200fab..e3e327327f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -99,7 +99,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared private SwitchCompat swUnseenIgnored; private SwitchCompat swNotifyGrouping; private SwitchCompat swNotifyPrivate; - private SwitchCompat swNotifyPublicActions; private SwitchCompat swNotifyBackgroundOnly; private SwitchCompat swNotifyKnownOnly; private SwitchCompat swNotifySuppressInCall; @@ -140,7 +139,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared "notify_flag", "notify_seen", "notify_hide", "notify_snooze", "light", "sound", "notify_screen_on", "badge", "unseen_ignored", - "notify_grouping", "notify_private", "notify_public_actions", "notify_background_only", "notify_known", "notify_suppress_in_call", "notify_suppress_in_car", + "notify_grouping", "notify_private", "notify_background_only", "notify_known", "notify_suppress_in_call", "notify_suppress_in_car", "notify_remove", "notify_clear", "notify_subtext", "notify_preview", "notify_preview_all", "notify_preview_only", "notify_transliterate", "notify_ascii", "wearable_preview", @@ -191,7 +190,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swUnseenIgnored = view.findViewById(R.id.swUnseenIgnored); swNotifyGrouping = view.findViewById(R.id.swNotifyGrouping); swNotifyPrivate = view.findViewById(R.id.swNotifyPrivate); - swNotifyPublicActions = view.findViewById(R.id.swNotifyPublicActions); swNotifyBackgroundOnly = view.findViewById(R.id.swNotifyBackgroundOnly); swNotifyKnownOnly = view.findViewById(R.id.swNotifyKnownOnly); swNotifySuppressInCall = view.findViewById(R.id.swNotifySuppressInCall); @@ -567,14 +565,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("notify_private", checked).apply(); - swNotifyPublicActions.setEnabled(!checked); - } - }); - - swNotifyPublicActions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("notify_public_actions", checked).apply(); } }); @@ -866,8 +856,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swUnseenIgnored.setChecked(prefs.getBoolean("unseen_ignored", false)); swNotifyGrouping.setChecked(prefs.getBoolean("notify_grouping", true)); swNotifyPrivate.setChecked(prefs.getBoolean("notify_private", true)); - swNotifyPublicActions.setChecked(prefs.getBoolean("notify_public_actions", true)); - swNotifyPublicActions.setEnabled(!swNotifyPrivate.isChecked()); swNotifyBackgroundOnly.setChecked(prefs.getBoolean("notify_background_only", false)); swNotifyKnownOnly.setChecked(prefs.getBoolean("notify_known", false)); swNotifySuppressInCall.setChecked(prefs.getBoolean("notify_suppress_in_call", false)); diff --git a/app/src/main/java/eu/faircode/email/NotificationHelper.java b/app/src/main/java/eu/faircode/email/NotificationHelper.java index ab07ca0a2d..63560f1ac4 100644 --- a/app/src/main/java/eu/faircode/email/NotificationHelper.java +++ b/app/src/main/java/eu/faircode/email/NotificationHelper.java @@ -652,7 +652,6 @@ class NotificationHelper { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean notify_grouping = prefs.getBoolean("notify_grouping", true); boolean notify_private = prefs.getBoolean("notify_private", true); - boolean notify_public_actions = prefs.getBoolean("notify_public_actions", true); boolean notify_newest_first = prefs.getBoolean("notify_newest_first", false); MessageHelper.AddressFormat email_format = MessageHelper.getAddressFormat(context); boolean prefer_contact = prefs.getBoolean("prefer_contact", false); @@ -969,84 +968,6 @@ class NotificationHelper { DB db = DB.getInstance(context); - if (message.content && notify_preview) { - // Android will truncate the text - String preview = message.preview; - if (notify_preview_all) - try { - File file = message.getFile(context); - preview = HtmlHelper.getFullText(file); - if (preview != null && preview.length() > MAX_PREVIEW) - preview = preview.substring(0, MAX_PREVIEW); - } catch (Throwable ex) { - Log.e(ex); - } - - // Wearables - StringBuilder sb = new StringBuilder(); - if (!TextUtils.isEmpty(message.subject)) - sb.append(TextHelper.normalizeNotification(context, message.subject)); - if (wearable_preview && !TextUtils.isEmpty(preview)) { - if (sb.length() > 0) - sb.append(" - "); - sb.append(TextHelper.normalizeNotification(context, preview)); - } - if (sb.length() > 0) - mbuilder.setContentText(sb.toString()); - - // Device - if (!notify_messaging) { - StringBuilder sbm = new StringBuilder(); - - if (message.keywords != null && BuildConfig.DEBUG) - for (String keyword : message.keywords) - if (keyword.startsWith("!")) - sbm.append(Html.escapeHtml(keyword)).append(": "); - - if (!TextUtils.isEmpty(message.subject)) - sbm.append("").append(Html.escapeHtml(message.subject)).append("").append("
"); - - if (!TextUtils.isEmpty(preview)) - sbm.append(Html.escapeHtml(preview)); - - if (sbm.length() > 0) { - NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle() - .bigText(HtmlHelper.fromHtml(sbm.toString(), context)); - if (!TextUtils.isEmpty(message.subject)) - bigText.setSummaryText(message.subject); - - mbuilder.setStyle(bigText); - } - } - } else { - if (!TextUtils.isEmpty(message.subject)) - mbuilder.setContentText(TextHelper.normalizeNotification(context, message.subject)); - } - - if (info[0].hasPhoto()) - mbuilder.setLargeIcon(info[0].getPhotoBitmap()); - - if (info[0].hasLookupUri()) { - Person.Builder you = new Person.Builder() - .setUri(info[0].getLookupUri().toString()); - mbuilder.addPerson(you.build()); - } - - if (pro) { - Integer color = getColor(message); - if (color != null) { - mbuilder.setColor(color); - mbuilder.setColorized(true); - } - } - - if (!notify_private && !notify_public_actions) { - Notification pub = mbuilder.build(); - mbuilder - .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) - .setPublicVersion(pub); - } - List wactions = new ArrayList<>(); if (notify_trash && @@ -1281,6 +1202,77 @@ class NotificationHelper { wactions.add(actionSnooze.build()); } + if (message.content && notify_preview) { + // Android will truncate the text + String preview = message.preview; + if (notify_preview_all) + try { + File file = message.getFile(context); + preview = HtmlHelper.getFullText(file); + if (preview != null && preview.length() > MAX_PREVIEW) + preview = preview.substring(0, MAX_PREVIEW); + } catch (Throwable ex) { + Log.e(ex); + } + + // Wearables + StringBuilder sb = new StringBuilder(); + if (!TextUtils.isEmpty(message.subject)) + sb.append(TextHelper.normalizeNotification(context, message.subject)); + if (wearable_preview && !TextUtils.isEmpty(preview)) { + if (sb.length() > 0) + sb.append(" - "); + sb.append(TextHelper.normalizeNotification(context, preview)); + } + if (sb.length() > 0) + mbuilder.setContentText(sb.toString()); + + // Device + if (!notify_messaging) { + StringBuilder sbm = new StringBuilder(); + + if (message.keywords != null && BuildConfig.DEBUG) + for (String keyword : message.keywords) + if (keyword.startsWith("!")) + sbm.append(Html.escapeHtml(keyword)).append(": "); + + if (!TextUtils.isEmpty(message.subject)) + sbm.append("").append(Html.escapeHtml(message.subject)).append("").append("
"); + + if (!TextUtils.isEmpty(preview)) + sbm.append(Html.escapeHtml(preview)); + + if (sbm.length() > 0) { + NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle() + .bigText(HtmlHelper.fromHtml(sbm.toString(), context)); + if (!TextUtils.isEmpty(message.subject)) + bigText.setSummaryText(message.subject); + + mbuilder.setStyle(bigText); + } + } + } else { + if (!TextUtils.isEmpty(message.subject)) + mbuilder.setContentText(TextHelper.normalizeNotification(context, message.subject)); + } + + if (info[0].hasPhoto()) + mbuilder.setLargeIcon(info[0].getPhotoBitmap()); + + if (info[0].hasLookupUri()) { + Person.Builder you = new Person.Builder() + .setUri(info[0].getLookupUri().toString()); + mbuilder.addPerson(you.build()); + } + + if (pro) { + Integer color = getColor(message); + if (color != null) { + mbuilder.setColor(color); + mbuilder.setColorized(true); + } + } + // https://developer.android.com/training/wearables/notifications // https://developer.android.com/reference/androidx/core/app/NotificationCompat.Action.WearableExtender mbuilder.extend(new NotificationCompat.WearableExtender() diff --git a/app/src/main/res/layout/fragment_options_notifications.xml b/app/src/main/res/layout/fragment_options_notifications.xml index 712cf05096..49f68af0cc 100644 --- a/app/src/main/res/layout/fragment_options_notifications.xml +++ b/app/src/main/res/layout/fragment_options_notifications.xml @@ -556,19 +556,6 @@ app:layout_constraintTop_toBottomOf="@id/swNotifyGrouping" app:switchPadding="12dp" /> - - Let the number of new messages match the number of notifications Group notifications Keep notifications private when the device is locked - Show notification actions when the device is locked Show notifications when in the background only Show notifications for contacts only Delay notifications while on a call