From a59fccb25d10dec0858bcb748b6887470533dfa5 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 5 Nov 2023 14:30:44 +0100 Subject: [PATCH] Added notify ASCI only --- app/src/main/java/eu/faircode/email/Core.java | 6 +++--- .../email/FragmentOptionsNotifications.java | 12 +++++++++++- .../main/java/eu/faircode/email/TextHelper.java | 16 ++++++++++++---- .../layout/fragment_options_notifications.xml | 13 ++++++++++++- app/src/main/res/values/strings.xml | 3 ++- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 355e35ddf2..b7329e3aa6 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -6360,11 +6360,11 @@ class Core { // Wearables StringBuilder sb = new StringBuilder(); if (!TextUtils.isEmpty(message.subject)) - sb.append(TextHelper.transliterateNotification(context, message.subject)); + sb.append(TextHelper.normalizeNotification(context, message.subject)); if (wearable_preview && !TextUtils.isEmpty(preview)) { if (sb.length() > 0) sb.append(" - "); - sb.append(TextHelper.transliterateNotification(context, preview)); + sb.append(TextHelper.normalizeNotification(context, preview)); } if (sb.length() > 0) mbuilder.setContentText(sb.toString()); @@ -6395,7 +6395,7 @@ class Core { } } else { if (!TextUtils.isEmpty(message.subject)) - mbuilder.setContentText(TextHelper.transliterateNotification(context, message.subject)); + mbuilder.setContentText(TextHelper.normalizeNotification(context, message.subject)); } if (info[0].hasPhoto()) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index 399407007a..e3e327327f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -111,6 +111,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared private SwitchCompat swNotifyPreviewAll; private SwitchCompat swNotifyPreviewOnly; private SwitchCompat swNotifyTransliterate; + private SwitchCompat swNotifyAscii; private ImageButton ibLight; private SwitchCompat swWearablePreview; private ImageButton ibWearable; @@ -140,7 +141,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared "badge", "unseen_ignored", "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_subtext", "notify_preview", "notify_preview_all", "notify_preview_only", "notify_transliterate", "notify_ascii", "wearable_preview", "notify_messaging", "biometrics_notify", "notify_open_folder", "background_service", "alert_once" @@ -201,6 +202,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swNotifyPreviewAll = view.findViewById(R.id.swNotifyPreviewAll); swNotifyPreviewOnly = view.findViewById(R.id.swNotifyPreviewOnly); swNotifyTransliterate = view.findViewById(R.id.swNotifyTransliterate); + swNotifyAscii = view.findViewById(R.id.swNotifyAscii); ibLight = view.findViewById(R.id.ibLight); swWearablePreview = view.findViewById(R.id.swWearablePreview); ibWearable = view.findViewById(R.id.ibWearable); @@ -654,6 +656,13 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared } }); + swNotifyAscii.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("notify_ascii", checked).apply(); + } + }); + ibLight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -858,6 +867,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared swNotifyPreviewAll.setChecked(prefs.getBoolean("notify_preview_all", false)); swNotifyPreviewOnly.setChecked(prefs.getBoolean("notify_preview_only", false)); swNotifyTransliterate.setChecked(prefs.getBoolean("notify_transliterate", false)); + swNotifyAscii.setChecked(prefs.getBoolean("notify_ascii", false)); swWearablePreview.setChecked(prefs.getBoolean("wearable_preview", false)); swMessagingStyle.setChecked(prefs.getBoolean("notify_messaging", false)); swBiometricsNotify.setChecked(prefs.getBoolean("biometrics_notify", true)); diff --git a/app/src/main/java/eu/faircode/email/TextHelper.java b/app/src/main/java/eu/faircode/email/TextHelper.java index 6318b0b631..fbf377ccac 100644 --- a/app/src/main/java/eu/faircode/email/TextHelper.java +++ b/app/src/main/java/eu/faircode/email/TextHelper.java @@ -36,6 +36,7 @@ import androidx.preference.PreferenceManager; import java.io.StringReader; import java.io.StringWriter; +import java.text.Normalizer; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.ArrayList; @@ -127,13 +128,20 @@ public class TextHelper { } } - static String transliterateNotification(Context context, String text) { + static String normalizeNotification(Context context, String text) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean notify_transliterate = prefs.getBoolean("notify_transliterate", false); - if (!notify_transliterate) - return text; + boolean notify_ascii = prefs.getBoolean("notify_ascii", false); - return transliterate(context, text); + if (notify_transliterate) + text = transliterate(context, text); + + if (notify_ascii) { + text = Normalizer.normalize(text, Normalizer.Form.NFKD) + .replaceAll("[^\\p{ASCII}]", ""); + } + + return text; } static String transliterate(Context context, String text) { diff --git a/app/src/main/res/layout/fragment_options_notifications.xml b/app/src/main/res/layout/fragment_options_notifications.xml index 6bf4e67653..49f68af0cc 100644 --- a/app/src/main/res/layout/fragment_options_notifications.xml +++ b/app/src/main/res/layout/fragment_options_notifications.xml @@ -754,6 +754,17 @@ app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewOnlyHint" app:switchPadding="12dp" /> + + Show message preview in notifications Preview all text Show notifications with a preview text only - Transliterate + Transliterate text + ASCII text only Notification actions Trash Delete