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