mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 14:41:08 +00:00
Experimental support for transliteration
This commit is contained in:
parent
27a7c4e86b
commit
f48a41128b
6 changed files with 81 additions and 5 deletions
|
@ -4582,11 +4582,11 @@ class Core {
|
|||
// Wearables
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!TextUtils.isEmpty(message.subject))
|
||||
sb.append(message.subject);
|
||||
sb.append(TextHelper.transliterate(context, message.subject));
|
||||
if (wearable_preview && !TextUtils.isEmpty(preview)) {
|
||||
if (sb.length() > 0)
|
||||
sb.append(" - ");
|
||||
sb.append(preview);
|
||||
sb.append(TextHelper.transliterate(context, preview));
|
||||
}
|
||||
if (sb.length() > 0)
|
||||
mbuilder.setContentText(sb.toString());
|
||||
|
@ -4611,7 +4611,7 @@ class Core {
|
|||
}
|
||||
} else {
|
||||
if (!TextUtils.isEmpty(message.subject))
|
||||
mbuilder.setContentText(message.subject);
|
||||
mbuilder.setContentText(TextHelper.transliterate(context, message.subject));
|
||||
}
|
||||
|
||||
if (info[0].hasPhoto())
|
||||
|
|
|
@ -91,6 +91,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
private SwitchCompat swNotifyPreview;
|
||||
private SwitchCompat swNotifyPreviewAll;
|
||||
private SwitchCompat swNotifyPreviewOnly;
|
||||
private SwitchCompat swNotifyTransliterate;
|
||||
private ImageButton ibLight;
|
||||
private SwitchCompat swWearablePreview;
|
||||
private ImageButton ibWearable;
|
||||
|
@ -112,7 +113,8 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
"light", "sound",
|
||||
"badge", "unseen_ignored",
|
||||
"notify_background_only", "notify_known", "notify_summary", "notify_remove", "notify_clear",
|
||||
"notify_subtext", "notify_preview", "notify_preview_all", "notify_preview_only", "wearable_preview",
|
||||
"notify_subtext", "notify_preview", "notify_preview_all", "notify_preview_only", "notify_transliterate",
|
||||
"wearable_preview",
|
||||
"notify_messaging",
|
||||
"biometrics_notify",
|
||||
"alert_once"
|
||||
|
@ -165,6 +167,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
swNotifyPreview = view.findViewById(R.id.swNotifyPreview);
|
||||
swNotifyPreviewAll = view.findViewById(R.id.swNotifyPreviewAll);
|
||||
swNotifyPreviewOnly = view.findViewById(R.id.swNotifyPreviewOnly);
|
||||
swNotifyTransliterate = view.findViewById(R.id.swNotifyTransliterate);
|
||||
ibLight = view.findViewById(R.id.ibLight);
|
||||
swWearablePreview = view.findViewById(R.id.swWearablePreview);
|
||||
ibWearable = view.findViewById(R.id.ibWearable);
|
||||
|
@ -439,6 +442,13 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
}
|
||||
});
|
||||
|
||||
swNotifyTransliterate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("notify_transliterate", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
ibLight.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -489,6 +499,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
: R.color.lightColorBackground_cards));
|
||||
}
|
||||
|
||||
swNotifyTransliterate.setVisibility(TextHelper.canTransliterate() ? View.VISIBLE : View.GONE);
|
||||
swUnseenIgnored.setVisibility(Helper.isXiaomi() ? View.GONE : View.VISIBLE);
|
||||
swAlertOnce.setVisibility(Helper.isXiaomi() || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
|
||||
|
||||
|
@ -587,6 +598,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true));
|
||||
swNotifyPreviewAll.setChecked(prefs.getBoolean("notify_preview_all", false));
|
||||
swNotifyPreviewOnly.setChecked(prefs.getBoolean("notify_preview_only", false));
|
||||
swNotifyTransliterate.setChecked(prefs.getBoolean("notify_transliterate", false));
|
||||
swWearablePreview.setChecked(prefs.getBoolean("wearable_preview", false));
|
||||
swMessagingStyle.setChecked(prefs.getBoolean("notify_messaging", false));
|
||||
swBiometricsNotify.setChecked(prefs.getBoolean("biometrics_notify", true));
|
||||
|
|
|
@ -35,6 +35,7 @@ import android.content.res.Configuration;
|
|||
import android.content.res.Resources;
|
||||
import android.database.sqlite.SQLiteFullException;
|
||||
import android.graphics.Point;
|
||||
import android.icu.text.Transliterator;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
|
@ -99,6 +100,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -1692,6 +1694,15 @@ public class Log {
|
|||
.append(" yes=").append((uiMode & Configuration.UI_MODE_NIGHT_YES) != 0)
|
||||
.append("\r\n");
|
||||
|
||||
if (BuildConfig.DEBUG &&
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
sb.append("Transliterators:");
|
||||
Enumeration<String> ids = Transliterator.getAvailableIDs();
|
||||
while (ids.hasMoreElements())
|
||||
sb.append(' ').append(ids.nextElement());
|
||||
sb.append("\r\n");
|
||||
}
|
||||
|
||||
try {
|
||||
int maxKeySize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES");
|
||||
sb.append(context.getString(R.string.title_advanced_aes_key_size, maxKeySize)).append("\r\n");
|
||||
|
|
|
@ -21,6 +21,8 @@ package eu.faircode.email;
|
|||
|
||||
import android.app.Person;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.icu.text.Transliterator;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.view.textclassifier.ConversationAction;
|
||||
|
@ -28,6 +30,9 @@ import android.view.textclassifier.ConversationActions;
|
|||
import android.view.textclassifier.TextClassificationManager;
|
||||
import android.view.textclassifier.TextClassifier;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.text.Normalizer;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
@ -82,6 +87,42 @@ public class TextHelper {
|
|||
}
|
||||
}
|
||||
|
||||
static boolean canTransliterate() {
|
||||
if (!BuildConfig.DEBUG)
|
||||
return false;
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||
return false;
|
||||
|
||||
try {
|
||||
Transliterator.getInstance("Any-Latin");
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static String transliterate(Context context, String text) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||
return text;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean notify_transliterate = prefs.getBoolean("notify_transliterate", false);
|
||||
if (!notify_transliterate)
|
||||
return text;
|
||||
|
||||
try {
|
||||
Transliterator t = Transliterator.getInstance("Any-Latin");
|
||||
text = t.transliterate(text);
|
||||
String normalized = Normalizer.normalize(text, Normalizer.Form.NFD);
|
||||
text = normalized.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
static ConversationActions getConversationActions(
|
||||
Context context, String[] texts, boolean replies, boolean outgoing, long time) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||
|
|
|
@ -619,6 +619,17 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swNotifyPreviewOnly" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swNotifyTransliterate"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_notify_transliterate"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewOnlyHint"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibLight"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -627,7 +638,7 @@
|
|||
android:contentDescription="@string/title_info"
|
||||
android:tooltipText="@string/title_info"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewOnlyHint"
|
||||
app:layout_constraintTop_toBottomOf="@id/swNotifyTransliterate"
|
||||
app:srcCompat="@drawable/baseline_wb_incandescent_24" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
|
|
|
@ -474,6 +474,7 @@
|
|||
<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_actions">Notification actions</string>
|
||||
<string name="title_advanced_notify_action_trash">Trash</string>
|
||||
<string name="title_advanced_notify_action_junk">Spam</string>
|
||||
|
|
Loading…
Reference in a new issue