From 9627e235a939bf45d166af318ff6a65bd43ac245 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 12 Dec 2022 19:40:29 +0100 Subject: [PATCH] DeepL: auto select plan --- app/src/main/java/eu/faircode/email/DeepL.java | 14 ++++---------- app/src/main/res/layout/dialog_deepl.xml | 11 +---------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DeepL.java b/app/src/main/java/eu/faircode/email/DeepL.java index 8d4f4bf189..3989fdf801 100644 --- a/app/src/main/java/eu/faircode/email/DeepL.java +++ b/app/src/main/java/eu/faircode/email/DeepL.java @@ -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()); diff --git a/app/src/main/res/layout/dialog_deepl.xml b/app/src/main/res/layout/dialog_deepl.xml index 2906820fb4..67ee1b8147 100644 --- a/app/src/main/res/layout/dialog_deepl.xml +++ b/app/src/main/res/layout/dialog_deepl.xml @@ -60,15 +60,6 @@ - - + app:layout_constraintTop_toBottomOf="@id/tilKey" />