From 50f7dac45630562e82e1d6425b58f265251855a6 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 21 May 2021 07:38:56 +0200 Subject: [PATCH] DeepL: format usage --- app/src/main/java/eu/faircode/email/DeepL.java | 1 - .../main/java/eu/faircode/email/FragmentCompose.java | 11 ++++++----- app/src/main/res/values/strings.xml | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DeepL.java b/app/src/main/java/eu/faircode/email/DeepL.java index 1836f708b1..5a087be277 100644 --- a/app/src/main/java/eu/faircode/email/DeepL.java +++ b/app/src/main/java/eu/faircode/email/DeepL.java @@ -127,7 +127,6 @@ public class DeepL { } } - private static String getBaseUri(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String domain = prefs.getString("deepl_domain", "api-free.deepl.com"); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 7776a6763a..06847acb52 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -100,7 +100,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.view.menu.MenuBuilder; import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.SwitchCompat; import androidx.constraintlayout.widget.Group; @@ -6784,7 +6783,8 @@ public class FragmentCompose extends FragmentBase { tvUsage.setVisibility(View.GONE); - if (!TextUtils.isEmpty(key)) { + if (!TextUtils.isEmpty(key) && + (domain == null || domain.equals("api-free.deepl.com"))) { Bundle args = new Bundle(); args.putString("key", key); @@ -6796,9 +6796,10 @@ public class FragmentCompose extends FragmentBase { @Override protected void onExecuted(Bundle args, Integer[] usage) { - tvUsage.setText( - Helper.humanReadableByteCount(usage[0]) + "/" + - Helper.humanReadableByteCount(usage[1])); + tvUsage.setText(getString(R.string.title_translate_usage, + Helper.humanReadableByteCount(usage[0]), + Helper.humanReadableByteCount(usage[1]), + Math.round(100f * usage[0] / usage[1]))); tvUsage.setVisibility(View.VISIBLE); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e68d498544..c838432a3d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1112,6 +1112,7 @@ Enter key Translating … Use a small font for the source text + Usage: %1$s / %2$s (%3$d %%) Edit as plain text Edit as reformatted text Select public key