From 0770952e9102516560bb73885e9162e8810260c7 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 24 May 2022 19:28:24 +0200 Subject: [PATCH] Enabled LanguageTool for Play store --- app/build.gradle | 4 ---- .../main/java/eu/faircode/email/FragmentCompose.java | 10 +++++----- .../eu/faircode/email/{LT.java => LanguageTool.java} | 5 +++-- 3 files changed, 8 insertions(+), 11 deletions(-) rename app/src/main/java/eu/faircode/email/{LT.java => LanguageTool.java} (97%) diff --git a/app/build.gradle b/app/build.gradle index 44341704b5..a7b5306b75 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -158,7 +158,6 @@ android { buildConfigField "String", "CHANGELOG", "\"https://github.com/M66B/FairEmail/releases/\"" buildConfigField "String", "GITHUB_LATEST_API", "\"https://api.github.com/repos/M66B/FairEmail/releases/latest\"" buildConfigField "String", "GITHUB_LATEST_URI", "\"https://github.com/M66B/FairEmail/releases\"" - buildConfigField "String", "LT_URI", "\"https://api.languagetool.org/v2/\"" buildConfigField "String", "TX_URI", localProperties.getProperty("paypal.uri", "\"\"") buildConfigField "String", "GPA_URI", localProperties.getProperty("gpa.uri", "\"\"") buildConfigField "String", "INFO_URI", localProperties.getProperty("info.uri", "\"\"") @@ -175,7 +174,6 @@ android { buildConfigField "String", "CHANGELOG", "\"https://github.com/M66B/FairEmail/releases/\"" buildConfigField "String", "GITHUB_LATEST_API", "\"https://api.github.com/repos/M66B/FairEmail/releases/latest\"" buildConfigField "String", "GITHUB_LATEST_URI", "\"https://github.com/M66B/FairEmail/releases\"" - buildConfigField "String", "LT_URI", "\"https://api.languagetool.org/v2/\"" buildConfigField "String", "TX_URI", "\"\"" buildConfigField "String", "GPA_URI", "\"\"" buildConfigField "String", "INFO_URI", "\"\"" @@ -193,7 +191,6 @@ android { buildConfigField "String", "CHANGELOG", "\"\"" buildConfigField "String", "GITHUB_LATEST_API", "\"\"" buildConfigField "String", "GITHUB_LATEST_URI", "\"\"" - buildConfigField "String", "LT_URI", "\"\"" buildConfigField "String", "TX_URI", "\"\"" buildConfigField "String", "GPA_URI", "\"\"" buildConfigField "String", "INFO_URI", "\"\"" @@ -211,7 +208,6 @@ android { buildConfigField "String", "CHANGELOG", "\"\"" buildConfigField "String", "GITHUB_LATEST_API", "\"\"" buildConfigField "String", "GITHUB_LATEST_URI", "\"\"" - buildConfigField "String", "LT_URI", "\"\"" buildConfigField "String", "TX_URI", "\"\"" buildConfigField "String", "GPA_URI", "\"\"" buildConfigField "String", "INFO_URI", "\"\"" diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 62fc687ddf..2535002f05 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2422,7 +2422,7 @@ public class FragmentCompose extends FragmentBase { Bundle args = new Bundle(); args.putCharSequence("text", etBody.getText()); - new SimpleTask>() { + new SimpleTask>() { private Toast toast = null; @Override @@ -2440,13 +2440,13 @@ public class FragmentCompose extends FragmentBase { } @Override - protected List onExecute(Context context, Bundle args) throws Throwable { + protected List onExecute(Context context, Bundle args) throws Throwable { CharSequence text = args.getCharSequence("text").toString(); - return LT.getSuggestions(context, text); + return LanguageTool.getSuggestions(context, text); } @Override - protected void onExecuted(Bundle args, List suggestions) { + protected void onExecuted(Bundle args, List suggestions) { if (suggestions == null || suggestions.size() == 0) { ToastEx.makeText(getContext(), R.string.title_suggestions_none, Toast.LENGTH_LONG).show(); return; @@ -2462,7 +2462,7 @@ public class FragmentCompose extends FragmentBase { edit.removeSpan(span); } - for (LT.Suggestion suggestion : suggestions) { + for (LanguageTool.Suggestion suggestion : suggestions) { Log.i("LT adding=" + suggestion); SuggestionSpan span = new SuggestionSpanEx(getContext(), suggestion.replacements.toArray(new String[0]), diff --git a/app/src/main/java/eu/faircode/email/LT.java b/app/src/main/java/eu/faircode/email/LanguageTool.java similarity index 97% rename from app/src/main/java/eu/faircode/email/LT.java rename to app/src/main/java/eu/faircode/email/LanguageTool.java index 68c00cf74c..8414f8c129 100644 --- a/app/src/main/java/eu/faircode/email/LT.java +++ b/app/src/main/java/eu/faircode/email/LanguageTool.java @@ -37,7 +37,8 @@ import java.util.Locale; import javax.net.ssl.HttpsURLConnection; -public class LT { +public class LanguageTool { + private static final String LT_URI = "https://api.languagetool.org/v2/"; private static final int LT_TIMEOUT = 20; // seconds static List getSuggestions(Context context, CharSequence text) throws IOException, JSONException { @@ -68,7 +69,7 @@ public class LT { Log.i("LT locale=" + locale + " request=" + request); - URL url = new URL(BuildConfig.LT_URI + "check"); + URL url = new URL(LT_URI + "check"); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true);