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

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

Loading…
Cancel
Save