DeepL: auto select plan

pull/210/head
M66B 2 years ago
parent c5c016fcab
commit 9627e235a9

@ -209,7 +209,7 @@ public class DeepL {
}
}
URL url = new URL(getBaseUri(context) + "translate?auth_key=" + key);
URL url = new URL(getBaseUri(key) + "translate?auth_key=" + key);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
@ -272,7 +272,7 @@ public class DeepL {
String key = prefs.getString("deepl_key", null);
// https://www.deepl.com/docs-api/other-functions/monitoring-usage/
URL url = new URL(getBaseUri(context) + "usage?auth_key=" + key);
URL url = new URL(getBaseUri(key) + "usage?auth_key=" + key);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setReadTimeout(DEEPL_TIMEOUT * 1000);
connection.setConnectTimeout(DEEPL_TIMEOUT * 1000);
@ -304,10 +304,8 @@ public class DeepL {
}
}
private static String getBaseUri(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String domain = (prefs.getBoolean("deepl_pro", false)
? "api.deepl.com" : "api-free.deepl.com");
private static String getBaseUri(String key) {
String domain = (key.endsWith(":fx") ? "api-free.deepl.com" : "api.deepl.com");
return "https://" + domain + "/v2/";
}
@ -347,7 +345,6 @@ public class DeepL {
final Context context = getContext();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String key = prefs.getString("deepl_key", null);
boolean pro = prefs.getBoolean("deepl_pro", false);
boolean formal = prefs.getBoolean("deepl_formal", true);
boolean small = prefs.getBoolean("deepl_small", false);
boolean html = prefs.getBoolean("deepl_html", false);
@ -356,7 +353,6 @@ public class DeepL {
View view = LayoutInflater.from(context).inflate(R.layout.dialog_deepl, null);
final ImageButton ibInfo = view.findViewById(R.id.ibInfo);
final TextInputLayout tilKey = view.findViewById(R.id.tilKey);
final CheckBox cbPro = view.findViewById(R.id.cbPro);
final CheckBox cbFormal = view.findViewById(R.id.cbFormal);
final TextView tvFormal = view.findViewById(R.id.tvFormal);
final CheckBox cbSmall = view.findViewById(R.id.cbSmall);
@ -387,7 +383,6 @@ public class DeepL {
});
tilKey.getEditText().setText(key);
cbPro.setChecked(pro);
cbFormal.setChecked(formal);
try {
@ -462,7 +457,6 @@ public class DeepL {
editor.remove("deepl_key");
else
editor.putString("deepl_key", key);
editor.putBoolean("deepl_pro", cbPro.isChecked());
editor.putBoolean("deepl_formal", cbFormal.isChecked());
editor.putBoolean("deepl_small", cbSmall.isChecked());
editor.putBoolean("deepl_html", cbHtml.isChecked());

@ -60,15 +60,6 @@
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:id="@+id/cbPro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="DeepL API Pro"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilKey" />
<CheckBox
android:id="@+id/cbFormal"
android:layout_width="wrap_content"
@ -76,7 +67,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_translate_formal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPro" />
app:layout_constraintTop_toBottomOf="@id/tilKey" />
<TextView
android:id="@+id/tvFormal"

Loading…
Cancel
Save