From 88bf6840ce1952c7d0804fab845525f8018202fc Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 17 May 2021 21:34:26 +0200 Subject: [PATCH] DeepL: enter auth key --- .../eu/faircode/email/FragmentCompose.java | 33 +++++++++++++++++-- app/src/main/res/layout/dialog_deepl.xml | 33 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 +- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/layout/dialog_deepl.xml diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 16ca5295aa..c8246ad035 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1939,8 +1939,8 @@ public class FragmentCompose extends FragmentBase { } private void onMenuTranslateKey() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - prefs.edit().putString("deepl", "").apply(); + FragmentDialogDeepL fragment = new FragmentDialogDeepL(); + fragment.show(getParentFragmentManager(), "deepl"); } private void onMenuTranslate(String target) { @@ -6683,6 +6683,35 @@ public class FragmentCompose extends FragmentBase { } } + public static class FragmentDialogDeepL extends FragmentDialogBase { + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + + final Context context = getContext(); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + View view = LayoutInflater.from(context).inflate(R.layout.dialog_deepl, null); + final EditText etKey = view.findViewById(R.id.etKey); + etKey.setText(prefs.getString("deepl", null)); + + return new AlertDialog.Builder(context) + .setView(view) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String key = etKey.getText().toString().trim(); + if (TextUtils.isEmpty(key)) + prefs.edit().remove("deepl").apply(); + else + prefs.edit().putString("deepl", key).apply(); + } + }) + .setNegativeButton(android.R.string.cancel, null) + .create(); + } + } + private static UriInfo getInfo(Uri uri, Context context) { UriInfo result = new UriInfo(); try { diff --git a/app/src/main/res/layout/dialog_deepl.xml b/app/src/main/res/layout/dialog_deepl.xml new file mode 100644 index 0000000000..eac45ac20b --- /dev/null +++ b/app/src/main/res/layout/dialog_deepl.xml @@ -0,0 +1,33 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dfdf8076e2..ee67b05558 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1108,7 +1108,7 @@ Insert template Create template Translate - Set key + Enter auth key English French German