mirror of https://github.com/M66B/FairEmail.git
Added option to auto check with LanguageTool
This commit is contained in:
parent
ee8e26725e
commit
dee9f452aa
|
@ -4,6 +4,10 @@
|
|||
|
||||
### [Mei long](https://en.wikipedia.org/wiki/Mei_long)
|
||||
|
||||
### Next version
|
||||
|
||||
* Added option to auto check with LanguageTool after each new line
|
||||
|
||||
### 1.1973 - 2022-10-01
|
||||
|
||||
* Added Ukrainian to DeepL languages
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
### [Mei long](https://en.wikipedia.org/wiki/Mei_long)
|
||||
|
||||
### Next version
|
||||
|
||||
* Added option to auto check with LanguageTool after each new line
|
||||
|
||||
### 1.1973 - 2022-10-01
|
||||
|
||||
* Added Ukrainian to DeepL languages
|
||||
|
|
|
@ -291,6 +291,8 @@ public class FragmentCompose extends FragmentBase {
|
|||
private boolean media = true;
|
||||
private boolean compact = false;
|
||||
private int zoom = 0;
|
||||
private boolean lt_enabled;
|
||||
private boolean lt_auto;
|
||||
|
||||
private long working = -1;
|
||||
private State state = State.NONE;
|
||||
|
@ -343,7 +345,8 @@ public class FragmentCompose extends FragmentBase {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
final Context context = getContext();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean experiments = prefs.getBoolean("experiments", false);
|
||||
|
||||
compose_font = prefs.getString("compose_font", "");
|
||||
|
@ -353,6 +356,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
compact = prefs.getBoolean("compose_compact", false);
|
||||
zoom = prefs.getInt("compose_zoom", compact ? 0 : 1);
|
||||
|
||||
lt_enabled = LanguageTool.isEnabled(context);
|
||||
lt_auto = LanguageTool.isAuto(context);
|
||||
|
||||
setTitle(R.string.page_compose);
|
||||
setSubtitle(getResources().getQuantityString(R.plurals.page_message, 1));
|
||||
}
|
||||
|
@ -792,6 +798,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
if (renum)
|
||||
StyleHelper.renumber(text, false, etBody.getContext());
|
||||
|
||||
if (lt_auto)
|
||||
onLanguageTool(true);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
} finally {
|
||||
|
@ -1958,8 +1967,8 @@ public class FragmentCompose extends FragmentBase {
|
|||
bottom_navigation.findViewById(R.id.action_save).setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (LanguageTool.isEnabled(v.getContext())) {
|
||||
onLanguageTool();
|
||||
if (lt_enabled) {
|
||||
onLanguageTool(false);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
|
@ -2559,7 +2568,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
popupMenu.showWithIcons(context, anchor);
|
||||
}
|
||||
|
||||
private void onLanguageTool() {
|
||||
private void onLanguageTool(boolean silent) {
|
||||
etBody.clearComposingText();
|
||||
|
||||
Log.i("LT running enabled=" + etBody.isSuggestionsEnabled());
|
||||
|
@ -2572,16 +2581,20 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
@Override
|
||||
protected void onPreExecute(Bundle args) {
|
||||
toast = ToastEx.makeText(getContext(), R.string.title_suggestions_check, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
setBusy(true);
|
||||
if (!silent) {
|
||||
toast = ToastEx.makeText(getContext(), R.string.title_suggestions_check, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
setBusy(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Bundle args) {
|
||||
if (toast != null)
|
||||
toast.cancel();
|
||||
setBusy(false);
|
||||
if (!silent) {
|
||||
if (toast != null)
|
||||
toast.cancel();
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2592,12 +2605,11 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, List<LanguageTool.Suggestion> suggestions) {
|
||||
if (suggestions == null || suggestions.size() == 0) {
|
||||
ToastEx.makeText(getContext(), R.string.title_suggestions_none, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
LanguageTool.applySuggestions(etBody, suggestions);
|
||||
|
||||
if (!silent &&
|
||||
(suggestions == null || suggestions.size() == 0))
|
||||
ToastEx.makeText(getContext(), R.string.title_suggestions_none, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2610,8 +2622,10 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Throwable exex = new Throwable("LanguageTool", ex);
|
||||
Log.unexpectedError(getParentFragmentManager(), exex, false);
|
||||
if (!silent) {
|
||||
Throwable exex = new Throwable("LanguageTool", ex);
|
||||
Log.unexpectedError(getParentFragmentManager(), exex, false);
|
||||
}
|
||||
}
|
||||
}.execute(this, args, "compose:lt");
|
||||
}
|
||||
|
@ -6883,6 +6897,9 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
grpBody.setVisibility(View.VISIBLE);
|
||||
|
||||
if (lt_auto)
|
||||
onLanguageTool(true);
|
||||
|
||||
cbSignature.setChecked(draft.signature);
|
||||
tvSignature.setAlpha(draft.signature ? 1.0f : Helper.LOW_LIGHT);
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
private TextView tvFtsPro;
|
||||
private Spinner spLanguage;
|
||||
private SwitchCompat swLanguageTool;
|
||||
private SwitchCompat swLanguageToolAuto;
|
||||
private SwitchCompat swLanguageToolPicky;
|
||||
private TextView tvLanguageToolPrivacy;
|
||||
private ImageButton ibLanguageTool;
|
||||
|
@ -242,7 +243,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"sort_answers", "shortcuts", "fts",
|
||||
"classification", "class_min_probability", "class_min_difference",
|
||||
"language", "lt_enabled", "lt_picky", "deepl_enabled", "vt_enabled", "vt_apikey", "send_enabled", "send_host",
|
||||
"language", "lt_enabled", "lt_auto", "lt_picky", "deepl_enabled", "vt_enabled", "vt_apikey", "send_enabled", "send_host",
|
||||
"updates", "weekly", "show_changelog",
|
||||
"crash_reports", "cleanup_attachments",
|
||||
"watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary",
|
||||
|
@ -327,6 +328,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
tvFtsPro = view.findViewById(R.id.tvFtsPro);
|
||||
spLanguage = view.findViewById(R.id.spLanguage);
|
||||
swLanguageTool = view.findViewById(R.id.swLanguageTool);
|
||||
swLanguageToolAuto = view.findViewById(R.id.swLanguageToolAuto);
|
||||
swLanguageToolPicky = view.findViewById(R.id.swLanguageToolPicky);
|
||||
tvLanguageToolPrivacy = view.findViewById(R.id.tvLanguageToolPrivacy);
|
||||
ibLanguageTool = view.findViewById(R.id.ibLanguageTool);
|
||||
|
@ -635,10 +637,18 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("lt_enabled", checked).apply();
|
||||
swLanguageToolAuto.setEnabled(checked);
|
||||
swLanguageToolPicky.setEnabled(checked);
|
||||
}
|
||||
});
|
||||
|
||||
swLanguageToolAuto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("lt_auto", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
swLanguageToolPicky.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
|
@ -2006,6 +2016,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
spLanguage.setSelection(selected);
|
||||
|
||||
swLanguageTool.setChecked(prefs.getBoolean("lt_enabled", false));
|
||||
swLanguageToolAuto.setChecked(prefs.getBoolean("lt_auto", false));
|
||||
swLanguageToolAuto.setEnabled(swLanguageTool.isChecked());
|
||||
swLanguageToolPicky.setChecked(prefs.getBoolean("lt_picky", false));
|
||||
swLanguageToolPicky.setEnabled(swLanguageTool.isChecked());
|
||||
swDeepL.setChecked(prefs.getBoolean("deepl_enabled", false));
|
||||
|
|
|
@ -54,6 +54,13 @@ public class LanguageTool {
|
|||
return prefs.getBoolean("lt_enabled", false);
|
||||
}
|
||||
|
||||
static boolean isAuto(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean lt_enabled = prefs.getBoolean("lt_enabled", false);
|
||||
boolean lt_auto = prefs.getBoolean("lt_auto", false);
|
||||
return (lt_enabled && lt_auto);
|
||||
}
|
||||
|
||||
static List<Suggestion> getSuggestions(Context context, CharSequence text) throws IOException, JSONException {
|
||||
// https://languagetool.org/http-api/swagger-ui/#!/default/post_check
|
||||
String request =
|
||||
|
@ -155,6 +162,8 @@ public class LanguageTool {
|
|||
Editable edit = etBody.getText();
|
||||
if (edit == null)
|
||||
return;
|
||||
if (suggestions == null)
|
||||
return;
|
||||
|
||||
// https://developer.android.com/reference/android/text/style/SuggestionSpan
|
||||
for (SuggestionSpanEx span : edit.getSpans(0, edit.length(), SuggestionSpanEx.class)) {
|
||||
|
|
|
@ -343,6 +343,18 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvLanguageToolHint" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swLanguageToolAuto"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_advanced_lt_auto"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvLanguageToolPrivacy"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swLanguageToolPicky"
|
||||
android:layout_width="0dp"
|
||||
|
@ -352,7 +364,7 @@
|
|||
android:text="@string/title_translate_formal"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvLanguageToolPrivacy"
|
||||
app:layout_constraintTop_toBottomOf="@id/swLanguageToolAuto"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<ImageButton
|
||||
|
|
|
@ -751,6 +751,7 @@
|
|||
<string name="title_advanced_language">Language</string>
|
||||
<string name="title_advanced_language_system">System</string>
|
||||
<string name="title_advanced_lt">LanguageTool integration</string>
|
||||
<string name="title_advanced_lt_auto">Check message automatically after each new line</string>
|
||||
<string name="title_advanced_deepl">DeepL integration</string>
|
||||
<string name="title_advanced_virus_total">VirusTotal integration</string>
|
||||
<string name="title_advanced_send" translatable="false">Send integration</string>
|
||||
|
|
|
@ -4,6 +4,10 @@ Changelog
|
|||
|
||||
Mei long
|
||||
|
||||
Next version
|
||||
|
||||
* Added option to auto check with LanguageTool after each new line
|
||||
|
||||
1.1973 - 2022-10-01
|
||||
|
||||
* Added Ukrainian to DeepL languages
|
||||
|
|
Loading…
Reference in New Issue