From 0394b14a620dc39a680afd62869be269d6eea38d Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 5 Sep 2023 08:45:25 +0200 Subject: [PATCH] Added option to disable highlighting translated text --- app/src/main/java/eu/faircode/email/DeepL.java | 4 ++++ .../main/java/eu/faircode/email/FragmentCompose.java | 12 ++++++++---- app/src/main/res/layout/dialog_deepl.xml | 12 +++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DeepL.java b/app/src/main/java/eu/faircode/email/DeepL.java index 5fd73cb633..385aed67fa 100644 --- a/app/src/main/java/eu/faircode/email/DeepL.java +++ b/app/src/main/java/eu/faircode/email/DeepL.java @@ -379,6 +379,7 @@ public class DeepL { boolean formal = prefs.getBoolean("deepl_formal", true); boolean small = prefs.getBoolean("deepl_small", false); boolean replace = prefs.getBoolean("deepl_replace", false); + boolean highlight = prefs.getBoolean("deepl_highlight", true); boolean html = prefs.getBoolean("deepl_html", false); int subscription = prefs.getInt("deepl_subscription", BuildConfig.DEBUG ? 17 : 0); @@ -389,6 +390,7 @@ public class DeepL { final TextView tvFormal = view.findViewById(R.id.tvFormal); final CheckBox cbSmall = view.findViewById(R.id.cbSmall); final CheckBox cbReplace = view.findViewById(R.id.cbReplace); + final CheckBox cbHighlight = view.findViewById(R.id.cbHighlight); final CheckBox cbHtml = view.findViewById(R.id.cbHtml); final TextView tvUsage = view.findViewById(R.id.tvUsage); final TextView tvPrivacy = view.findViewById(R.id.tvPrivacy); @@ -439,6 +441,7 @@ public class DeepL { cbSmall.setChecked(small); cbReplace.setChecked(replace); cbReplace.setEnabled(!small); + cbHighlight.setChecked(highlight); cbHtml.setChecked(html); tvUsage.setVisibility(View.GONE); @@ -502,6 +505,7 @@ public class DeepL { editor.putBoolean("deepl_formal", cbFormal.isChecked()); editor.putBoolean("deepl_small", cbSmall.isChecked()); editor.putBoolean("deepl_replace", cbReplace.isChecked()); + editor.putBoolean("deepl_highlight", cbHighlight.isChecked()); editor.putBoolean("deepl_html", cbHtml.isChecked()); editor.apply(); } diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 4ae42bdcb0..b9f0e6f120 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2783,10 +2783,14 @@ public class FragmentCompose extends FragmentBase { @Override protected void onPreExecute(Bundle args) { - int textColorHighlight = Helper.resolveColor(getContext(), android.R.attr.textColorHighlight); - highlightSpan = new BackgroundColorSpan(textColorHighlight); - etBody.getText().setSpan(highlightSpan, paragraph.first, paragraph.second, - Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + boolean deepl_highlight = prefs.getBoolean("deepl_highlight", true); + if (deepl_highlight) { + int textColorHighlight = Helper.resolveColor(getContext(), android.R.attr.textColorHighlight); + highlightSpan = new BackgroundColorSpan(textColorHighlight); + etBody.getText().setSpan(highlightSpan, paragraph.first, paragraph.second, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING); + } toast = ToastEx.makeText(context, R.string.title_translating, Toast.LENGTH_SHORT); toast.show(); } diff --git a/app/src/main/res/layout/dialog_deepl.xml b/app/src/main/res/layout/dialog_deepl.xml index fb868467ad..f256c1487a 100644 --- a/app/src/main/res/layout/dialog_deepl.xml +++ b/app/src/main/res/layout/dialog_deepl.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" + android:fadeScrollbars="false" android:padding="24dp" android:scrollbarStyle="outsideOverlay"> @@ -99,6 +100,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cbSmall" /> + + + app:layout_constraintTop_toBottomOf="@id/cbHighlight" /> Use formal form Use a small font for the source text Replace source text by translated text + Highlight the text being translated Preserve formatting This will consume more characters Usage: %1$s / %2$s (%3$d %%)