From defe6c3f641996cd66a962182467b3c87ce57d77 Mon Sep 17 00:00:00 2001 From: Tobias_Groza <304016-Tobias_Groza@noreply.gitlab.com> Date: Thu, 12 Oct 2023 18:00:54 +0200 Subject: [PATCH] Use different messages when copying URLs, permissions and version names --- .../main/java/org/fdroid/fdroid/Utils.java | 20 ++++++++++++++++--- .../views/AppSecurityPermissions.java | 3 ++- .../views/AppDetailsRecyclerViewAdapter.java | 2 +- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/Utils.java b/app/src/main/java/org/fdroid/fdroid/Utils.java index 838c2aa52..5442b8bac 100644 --- a/app/src/main/java/org/fdroid/fdroid/Utils.java +++ b/app/src/main/java/org/fdroid/fdroid/Utils.java @@ -49,6 +49,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.StringRes; import androidx.appcompat.app.AppCompatActivity; import androidx.core.util.Consumer; import androidx.core.util.Supplier; @@ -889,12 +890,25 @@ public final class Utils { } /** - * Copy text to the clipboard and show a toast informing the user that the text has been copied. + * Copy text to the clipboard and show a toast informing the user that something has been copied. * @param context the context to use * @param label the label used in the clipboard * @param text the text to copy */ - public static void copyToClipboard(@NonNull Context context, @Nullable String label, @NonNull String text) { + public static void copyToClipboard(@NonNull Context context, @Nullable String label, + @NonNull String text) { + copyToClipboard(context, label, text, R.string.copied_to_clipboard); + } + + /** + * Copy text to the clipboard and show a toast informing the user that the text has been copied. + * @param context the context to use + * @param label the label used in the clipboard + * @param text the text to copy + * @param message the message to show in the toast + */ + public static void copyToClipboard(@NonNull Context context, @Nullable String label, + @NonNull String text, @StringRes int message) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard == null) { // permission denied @@ -905,7 +919,7 @@ public final class Utils { if (Build.VERSION.SDK_INT < 33) { // Starting with Android 13 (SDK 33) there is a system dialog with more clipboard actions // shown automatically so there is no need to inform the user about the copy action. - Toast.makeText(context, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show(); + Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // should not happen, something went wrong internally diff --git a/app/src/main/java/org/fdroid/fdroid/privileged/views/AppSecurityPermissions.java b/app/src/main/java/org/fdroid/fdroid/privileged/views/AppSecurityPermissions.java index 3d7ba3c30..5aa3b1ffe 100644 --- a/app/src/main/java/org/fdroid/fdroid/privileged/views/AppSecurityPermissions.java +++ b/app/src/main/java/org/fdroid/fdroid/privileged/views/AppSecurityPermissions.java @@ -231,7 +231,8 @@ public class AppSecurityPermissions { @Override public boolean onLongClick(View v) { - Utils.copyToClipboard(getContext(), String.valueOf(perm.label), perm.name); + Utils.copyToClipboard(getContext(), String.valueOf(perm.label), + perm.name, R.string.copied_permission_to_clipboard); return true; } diff --git a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java index 57935f348..04959c11a 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java +++ b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java @@ -1308,7 +1308,7 @@ public class AppDetailsRecyclerViewAdapter parent.addView(view); view.setOnClickListener(v -> onLinkClicked(url)); view.setOnLongClickListener(v -> { - Utils.copyToClipboard(context, text, url); + Utils.copyToClipboard(context, text, url, R.string.copied_url_to_clipboard); return true; }); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a95804b05..9dfaecc7c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -741,4 +741,6 @@ This often occurs with apps installed via Google Play or other sources, if they Updated %1$d years ago Copied to clipboard + Copied URL to clipboard + Copied permission name to clipboard