Added custom LanguageTool URI option

pull/209/head
M66B 2 years ago
parent dee9f452aa
commit c998dede8e

@ -122,9 +122,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvFtsPro; private TextView tvFtsPro;
private Spinner spLanguage; private Spinner spLanguage;
private SwitchCompat swLanguageTool; private SwitchCompat swLanguageTool;
private TextView tvLanguageToolPrivacy;
private SwitchCompat swLanguageToolAuto; private SwitchCompat swLanguageToolAuto;
private SwitchCompat swLanguageToolPicky; private SwitchCompat swLanguageToolPicky;
private TextView tvLanguageToolPrivacy; private EditText etLanguageTool;
private ImageButton ibLanguageTool; private ImageButton ibLanguageTool;
private SwitchCompat swDeepL; private SwitchCompat swDeepL;
private TextView tvDeepLPrivacy; private TextView tvDeepLPrivacy;
@ -243,7 +244,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
"sort_answers", "shortcuts", "fts", "sort_answers", "shortcuts", "fts",
"classification", "class_min_probability", "class_min_difference", "classification", "class_min_probability", "class_min_difference",
"language", "lt_enabled", "lt_auto", "lt_picky", "deepl_enabled", "vt_enabled", "vt_apikey", "send_enabled", "send_host", "language",
"lt_enabled", "lt_auto", "lt_picky", "lt_uri",
"deepl_enabled",
"vt_enabled", "vt_apikey",
"send_enabled", "send_host",
"updates", "weekly", "show_changelog", "updates", "weekly", "show_changelog",
"crash_reports", "cleanup_attachments", "crash_reports", "cleanup_attachments",
"watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary", "watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary",
@ -328,9 +333,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvFtsPro = view.findViewById(R.id.tvFtsPro); tvFtsPro = view.findViewById(R.id.tvFtsPro);
spLanguage = view.findViewById(R.id.spLanguage); spLanguage = view.findViewById(R.id.spLanguage);
swLanguageTool = view.findViewById(R.id.swLanguageTool); swLanguageTool = view.findViewById(R.id.swLanguageTool);
tvLanguageToolPrivacy = view.findViewById(R.id.tvLanguageToolPrivacy);
swLanguageToolAuto = view.findViewById(R.id.swLanguageToolAuto); swLanguageToolAuto = view.findViewById(R.id.swLanguageToolAuto);
swLanguageToolPicky = view.findViewById(R.id.swLanguageToolPicky); swLanguageToolPicky = view.findViewById(R.id.swLanguageToolPicky);
tvLanguageToolPrivacy = view.findViewById(R.id.tvLanguageToolPrivacy); etLanguageTool = view.findViewById(R.id.etLanguageTool);
ibLanguageTool = view.findViewById(R.id.ibLanguageTool); ibLanguageTool = view.findViewById(R.id.ibLanguageTool);
swDeepL = view.findViewById(R.id.swDeepL); swDeepL = view.findViewById(R.id.swDeepL);
tvDeepLPrivacy = view.findViewById(R.id.tvDeepLPrivacy); tvDeepLPrivacy = view.findViewById(R.id.tvDeepLPrivacy);
@ -642,6 +648,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
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);
}
});
swLanguageToolAuto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swLanguageToolAuto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -656,11 +670,25 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
tvLanguageToolPrivacy.getPaint().setUnderlineText(true); etLanguageTool.setHint(LanguageTool.LT_URI);
tvLanguageToolPrivacy.setOnClickListener(new View.OnClickListener() { etLanguageTool.addTextChangedListener(new TextWatcher() {
@Override @Override
public void onClick(View v) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Helper.view(v.getContext(), Uri.parse(Helper.LT_PRIVACY_URI), true); // Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing
}
@Override
public void afterTextChanged(Editable s) {
String apikey = s.toString().trim();
if (TextUtils.isEmpty(apikey))
prefs.edit().remove("lt_uri").apply();
else
prefs.edit().putString("lt_uri", apikey).apply();
} }
}); });
@ -1869,7 +1897,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
if ("last_cleanup".equals(key)) if ("last_cleanup".equals(key))
setLastCleanup(prefs.getLong(key, -1)); setLastCleanup(prefs.getLong(key, -1));
if ("vt_apikey".equals(key) || "send_host".equals(key)) if ("lt_uri".equals(key) || "vt_apikey".equals(key) || "send_host".equals(key))
return; return;
if ("global_keywords".equals(key)) if ("global_keywords".equals(key))
@ -2020,6 +2048,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swLanguageToolAuto.setEnabled(swLanguageTool.isChecked()); swLanguageToolAuto.setEnabled(swLanguageTool.isChecked());
swLanguageToolPicky.setChecked(prefs.getBoolean("lt_picky", false)); swLanguageToolPicky.setChecked(prefs.getBoolean("lt_picky", false));
swLanguageToolPicky.setEnabled(swLanguageTool.isChecked()); swLanguageToolPicky.setEnabled(swLanguageTool.isChecked());
etLanguageTool.setText(prefs.getString("lt_uri", null));
swDeepL.setChecked(prefs.getBoolean("deepl_enabled", false)); swDeepL.setChecked(prefs.getBoolean("deepl_enabled", false));
swVirusTotal.setChecked(prefs.getBoolean("vt_enabled", false)); swVirusTotal.setChecked(prefs.getBoolean("vt_enabled", false));
etVirusTotal.setText(prefs.getString("vt_apikey", null)); etVirusTotal.setText(prefs.getString("vt_apikey", null));

@ -46,7 +46,7 @@ import java.util.Locale;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
public class LanguageTool { public class LanguageTool {
private static final String LT_URI = "https://api.languagetool.org/v2/"; static final String LT_URI = "https://api.languagetool.org/v2/";
private static final int LT_TIMEOUT = 20; // seconds private static final int LT_TIMEOUT = 20; // seconds
static boolean isEnabled(Context context) { static boolean isEnabled(Context context) {
@ -94,9 +94,13 @@ public class LanguageTool {
if (lt_picky) if (lt_picky)
request += "&level=picky"; request += "&level=picky";
Log.i("LT locale=" + locale + " request=" + request); String uri = prefs.getString("lt_uri", LT_URI);
if (!uri.endsWith("/"))
uri += '/';
URL url = new URL(LT_URI + "check"); Log.i("LT locale=" + locale + " uri=" + uri + " request=" + request);
URL url = new URL(uri + "check");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST"); connection.setRequestMethod("POST");
connection.setDoOutput(true); connection.setDoOutput(true);

@ -367,6 +367,18 @@
app:layout_constraintTop_toBottomOf="@id/swLanguageToolAuto" app:layout_constraintTop_toBottomOf="@id/swLanguageToolAuto"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<EditText
android:id="@+id/etLanguageTool"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:inputType="textUri"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swLanguageToolPicky" />
<ImageButton <ImageButton
android:id="@+id/ibLanguageTool" android:id="@+id/ibLanguageTool"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -375,7 +387,7 @@
android:contentDescription="@string/title_info" android:contentDescription="@string/title_info"
android:tooltipText="@string/title_info" android:tooltipText="@string/title_info"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swLanguageToolPicky" app:layout_constraintTop_toBottomOf="@id/etLanguageTool"
app:srcCompat="@drawable/twotone_info_24" /> app:srcCompat="@drawable/twotone_info_24" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

Loading…
Cancel
Save