Added notify ASCI only

pull/214/head
M66B 1 year ago
parent 4179c2dd6c
commit a59fccb25d

@ -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())

@ -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));

@ -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);
if (notify_transliterate)
text = transliterate(context, text);
return 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) {

@ -754,6 +754,17 @@
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewOnlyHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNotifyAscii"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_notify_ascii"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNotifyTransliterate"
app:switchPadding="12dp" />
<ImageButton
android:id="@+id/ibLight"
android:layout_width="wrap_content"
@ -762,7 +773,7 @@
android:contentDescription="@string/title_info"
android:tooltipText="@string/title_info"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNotifyTransliterate"
app:layout_constraintTop_toBottomOf="@id/swNotifyAscii"
app:srcCompat="@drawable/baseline_wb_incandescent_24" />
<androidx.appcompat.widget.SwitchCompat

@ -717,7 +717,8 @@
<string name="title_advanced_notify_preview">Show message preview in notifications</string>
<string name="title_advanced_notify_preview_all">Preview all text</string>
<string name="title_advanced_notify_preview_only">Show notifications with a preview text only</string>
<string name="title_advanced_notify_transliterate" translatable="false">Transliterate</string>
<string name="title_advanced_notify_transliterate">Transliterate text</string>
<string name="title_advanced_notify_ascii">ASCII text only</string>
<string name="title_advanced_notify_actions">Notification actions</string>
<string name="title_advanced_notify_action_trash">Trash</string>
<string name="title_advanced_notify_action_delete">Delete</string>

Loading…
Cancel
Save