Added option to auto check with LanguageTool

This commit is contained in:
M66B
2022-10-01 10:18:15 +02:00
parent ee8e26725e
commit dee9f452aa
8 changed files with 82 additions and 19 deletions

View File

@@ -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)) {