Added LanguageTool option

pull/209/head
M66B 3 years ago
parent 1346eb08e4
commit fb9b15065b

@ -4843,6 +4843,8 @@ Templates can have the following options:
<a name="faq180"></a>
**(180) How do I use LanguageTool?**
LanguageTool need to be enabled in the miscellaneous settings.
After writing some text, you can long press on the save draft button to perform a grammar, style, and spell check via [LanguageTool](https://languagetool.org/).
Texts with suggestions will be marked and if you tap on a marked suggestion,
it will be shown by the keyboard if the keyboard supports this,

@ -636,6 +636,8 @@ public class ApplicationEx extends Application
editor.putBoolean("auto_identity", true);
} else if (version < 1931)
editor.remove("button_force_light").remove("fake_dark");
else if (version < 1933)
editor.putBoolean("lt_enabled", true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG)
editor.remove("background_service");

@ -1871,9 +1871,12 @@ public class FragmentCompose extends FragmentBase {
bottom_navigation.findViewById(R.id.action_save).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
onLanguageTool();
return true;
public boolean onLongClick(View v) {
if (LanguageTool.isEnabled(v.getContext())) {
onLanguageTool();
return true;
} else
return false;
}
});

@ -37,6 +37,7 @@ import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.fonts.Font;
import android.graphics.fonts.SystemFonts;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Debug;
@ -111,6 +112,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvFtsIndexed;
private TextView tvFtsPro;
private Spinner spLanguage;
private SwitchCompat swLanguageTool;
private TextView tvLanguageToolPrivacy;
private ImageButton ibLanguageTool;
private SwitchCompat swDeepL;
private ImageButton ibDeepL;
private TextView tvSdcard;
@ -212,7 +216,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", "deepl_enabled",
"language", "lt_enabled", "deepl_enabled",
"updates", "weekly", "show_changelog",
"crash_reports", "cleanup_attachments",
"watchdog", "experiments", "main_log", "protocol", "log_level", "debug", "leak_canary", "test1",
@ -293,6 +297,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvFtsIndexed = view.findViewById(R.id.tvFtsIndexed);
tvFtsPro = view.findViewById(R.id.tvFtsPro);
spLanguage = view.findViewById(R.id.spLanguage);
swLanguageTool = view.findViewById(R.id.swLanguageTool);
tvLanguageToolPrivacy = view.findViewById(R.id.tvLanguageToolPrivacy);
ibLanguageTool = view.findViewById(R.id.ibLanguageTool);
swDeepL = view.findViewById(R.id.swDeepL);
ibDeepL = view.findViewById(R.id.ibDeepL);
tvSdcard = view.findViewById(R.id.tvSdcard);
@ -579,6 +586,28 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swLanguageTool.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("lt_enabled", checked).apply();
}
});
tvLanguageToolPrivacy.getPaint().setUnderlineText(true);
tvLanguageToolPrivacy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.view(v.getContext(), Uri.parse(Helper.LT_PRIVACY_URI), true);
}
});
ibLanguageTool.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.viewFAQ(v.getContext(), 180);
}
});
swDeepL.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -1750,6 +1779,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
if (selected >= 0)
spLanguage.setSelection(selected);
swLanguageTool.setChecked(prefs.getBoolean("lt_enabled", false));
swDeepL.setChecked(prefs.getBoolean("deepl_enabled", false));
swUpdates.setChecked(prefs.getBoolean("updates", true));
swCheckWeekly.setChecked(prefs.getBoolean("weekly", Helper.hasPlayStore(getContext())));

@ -193,6 +193,7 @@ public class Helper {
static final String SUPPORT_URI = "https://contact.faircode.eu/";
static final String TEST_URI = "https://play.google.com/apps/testing/" + BuildConfig.APPLICATION_ID;
static final String BIMI_PRIVACY_URI = "https://datatracker.ietf.org/doc/html/draft-brotman-ietf-bimi-guidance-03#section-7.4";
static final String LT_PRIVACY_URI = "https://languagetool.org/legal/privacy";
static final String ID_COMMAND_URI = "https://datatracker.ietf.org/doc/html/rfc2971#section-3.1";
static final String AUTH_RESULTS_URI = "https://datatracker.ietf.org/doc/html/rfc7601";
static final String FAVICON_PRIVACY_URI = "https://en.wikipedia.org/wiki/Favicon";

@ -20,6 +20,9 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import org.json.JSONArray;
import org.json.JSONException;
@ -41,6 +44,11 @@ public class LanguageTool {
private static final String LT_URI = "https://api.languagetool.org/v2/";
private static final int LT_TIMEOUT = 20; // seconds
static boolean isEnabled(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("lt_enabled", false);
}
static List<Suggestion> getSuggestions(Context context, CharSequence text) throws IOException, JSONException {
// https://languagetool.org/http-api/swagger-ui/#!/default/post_check
String request =

@ -306,6 +306,54 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spLanguage" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swLanguageTool"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_lt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLanguageHint"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvLanguageToolHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:drawableTint="?attr/colorWarning"
android:text="@string/title_advanced_privacy_risk"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swLanguageTool" />
<TextView
android:id="@+id/tvLanguageToolPrivacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_open_in_new_12"
android:drawablePadding="6dp"
android:drawableTint="?android:attr/textColorLink"
android:text="@string/title_privacy_policy"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLanguageToolHint" />
<ImageButton
android:id="@+id/ibLanguageTool"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:contentDescription="@string/title_info"
android:tooltipText="@string/title_info"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvLanguageToolPrivacy"
app:srcCompat="@drawable/twotone_info_24" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDeepL"
android:layout_width="0dp"
@ -315,7 +363,7 @@
android:text="@string/title_advanced_deepl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLanguageHint"
app:layout_constraintTop_toBottomOf="@id/ibLanguageTool"
app:switchPadding="12dp" />
<ImageButton

@ -726,6 +726,7 @@
<string name="title_advanced_class_min_difference">Minimum class difference: %1$s %%</string>
<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_deepl">DeepL integration</string>
<string name="title_advanced_sdcard">I want to use an sdcard</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>

Loading…
Cancel
Save