Added LanguageTool option

This commit is contained in:
M66B
2022-07-09 07:47:29 +02:00
parent 1346eb08e4
commit fb9b15065b
8 changed files with 100 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 =