Refactoring

This commit is contained in:
M66B 2022-04-29 07:42:20 +02:00
parent 77438c13f9
commit bf3104a969
4 changed files with 12 additions and 9 deletions

View File

@ -157,6 +157,7 @@ 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", "\"\"")
@ -172,6 +173,7 @@ 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", "\"\""
@ -188,6 +190,7 @@ 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", "\"\""
@ -204,6 +207,7 @@ 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", "\"\""

View File

@ -2402,7 +2402,7 @@ public class FragmentCompose extends FragmentBase {
Bundle args = new Bundle();
args.putCharSequence("text", etBody.getText());
new SimpleTask<List<LanguageTool.Suggestion>>() {
new SimpleTask<List<LT.Suggestion>>() {
private Toast toast = null;
@Override
@ -2420,13 +2420,13 @@ public class FragmentCompose extends FragmentBase {
}
@Override
protected List<LanguageTool.Suggestion> onExecute(Context context, Bundle args) throws Throwable {
protected List<LT.Suggestion> onExecute(Context context, Bundle args) throws Throwable {
CharSequence text = args.getCharSequence("text").toString();
return LanguageTool.getSuggestions(context, text);
return LT.getSuggestions(context, text);
}
@Override
protected void onExecuted(Bundle args, List<LanguageTool.Suggestion> suggestions) {
protected void onExecuted(Bundle args, List<LT.Suggestion> suggestions) {
if (suggestions == null || suggestions.size() == 0) {
ToastEx.makeText(getContext(), R.string.title_suggestions_none, Toast.LENGTH_LONG).show();
return;
@ -2442,7 +2442,7 @@ public class FragmentCompose extends FragmentBase {
edit.removeSpan(span);
}
for (LanguageTool.Suggestion suggestion : suggestions) {
for (LT.Suggestion suggestion : suggestions) {
Log.i("LT adding=" + suggestion);
SuggestionSpan span = new SuggestionSpanEx(getContext(),
suggestion.replacements.toArray(new String[0]),

View File

@ -37,9 +37,8 @@ import java.util.Locale;
import javax.net.ssl.HttpsURLConnection;
public class LanguageTool {
public class LT {
private static final int LT_TIMEOUT = 20; // seconds
private static final String LT_URI = "https://api.languagetool.org/v2/";
static List<Suggestion> getSuggestions(Context context, CharSequence text) throws IOException, JSONException {
// https://languagetool.org/http-api/swagger-ui/#!/default/post_check
@ -51,7 +50,7 @@ public class LanguageTool {
String code = null;
JSONArray jlanguages;
Locale locale = Locale.getDefault();
try (InputStream is = context.getAssets().open("languagetool.json")) {
try (InputStream is = context.getAssets().open("lt.json")) {
String json = Helper.readStream(is);
jlanguages = new JSONArray(json);
}
@ -69,7 +68,7 @@ public class LanguageTool {
Log.i("LT locale=" + locale + " request=" + request);
URL url = new URL(LT_URI + "check");
URL url = new URL(BuildConfig.LT_URI + "check");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);