mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 20:54:34 +00:00
Improved support for DeepL API Pro
This commit is contained in:
parent
3547a3570c
commit
e4b5e54193
2 changed files with 17 additions and 31 deletions
|
@ -256,7 +256,8 @@ public class DeepL {
|
|||
|
||||
private static String getBaseUri(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String domain = prefs.getString("deepl_domain", "api-free.deepl.com");
|
||||
String domain = (prefs.getBoolean("deepl_pro", false)
|
||||
? "api.deepl.com" : "api-free.deepl.com");
|
||||
return "https://" + domain + "/v2/";
|
||||
}
|
||||
|
||||
|
@ -278,14 +279,14 @@ public class DeepL {
|
|||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
final Context context = getContext();
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String domain = prefs.getString("deepl_domain", null);
|
||||
String key = prefs.getString("deepl_key", null);
|
||||
boolean pro = prefs.getBoolean("deepl_pro", false);
|
||||
boolean small = prefs.getBoolean("deepl_small", false);
|
||||
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_deepl, null);
|
||||
final ImageButton ibInfo = view.findViewById(R.id.ibInfo);
|
||||
final EditText etDomain = view.findViewById(R.id.etDomain);
|
||||
final EditText etKey = view.findViewById(R.id.etKey);
|
||||
final CheckBox cbPro = view.findViewById(R.id.cbPro);
|
||||
final CheckBox cbSmall = view.findViewById(R.id.cbSmall);
|
||||
final TextView tvUsage = view.findViewById(R.id.tvUsage);
|
||||
|
||||
|
@ -296,14 +297,13 @@ public class DeepL {
|
|||
}
|
||||
});
|
||||
|
||||
etDomain.setText(domain);
|
||||
etKey.setText(key);
|
||||
cbPro.setChecked(pro);
|
||||
cbSmall.setChecked(small);
|
||||
|
||||
tvUsage.setVisibility(View.GONE);
|
||||
|
||||
if (!TextUtils.isEmpty(key) &&
|
||||
(domain == null || domain.equals("api-free.deepl.com"))) {
|
||||
if (!TextUtils.isEmpty(key)) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString("key", key);
|
||||
|
||||
|
@ -335,20 +335,13 @@ public class DeepL {
|
|||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String domain = etDomain.getText().toString().trim();
|
||||
String key = etKey.getText().toString().trim();
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
if (TextUtils.isEmpty(key))
|
||||
editor
|
||||
.remove("deepl_key")
|
||||
.remove("deepl_domain");
|
||||
else {
|
||||
editor.remove("deepl_key");
|
||||
else
|
||||
editor.putString("deepl_key", key);
|
||||
if (TextUtils.isEmpty(domain))
|
||||
editor.remove("deepl_domain");
|
||||
else
|
||||
editor.putString("deepl_domain", domain);
|
||||
}
|
||||
editor.putBoolean("deepl_pro", cbPro.isChecked());
|
||||
editor.putBoolean("deepl_small", cbSmall.isChecked());
|
||||
editor.apply();
|
||||
}
|
||||
|
|
|
@ -36,11 +36,11 @@
|
|||
app:srcCompat="@drawable/twotone_info_24" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etDomain"
|
||||
android:id="@+id/etKey"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:hint="api-free.deepl.com"
|
||||
android:hint="@string/title_translate_key"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
|
@ -51,21 +51,14 @@
|
|||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etKey"
|
||||
android:layout_width="0dp"
|
||||
<CheckBox
|
||||
android:id="@+id/cbPro"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:hint="@string/title_translate_key"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:text="DeepL API Pro"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etDomain">
|
||||
|
||||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
app:layout_constraintTop_toBottomOf="@id/etKey" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbSmall"
|
||||
|
@ -74,7 +67,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_translate_small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etKey" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbPro" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvUsage"
|
||||
|
|
Loading…
Reference in a new issue