From ef35b36ebac12850f3c2da43a4c73da9142a24f3 Mon Sep 17 00:00:00 2001 From: dhruvpatidar359 Date: Sun, 11 Sep 2022 23:04:26 +0530 Subject: [PATCH 1/2] Remove the redundant/overlapping toast "Copied to clipboard" for Android 13+ Signed-off-by: dhruv Co-authored-by: Tobi Co-authored-by: AudricV <74829229+AudricV@users.noreply.github.com> --- .../newpipe/util/external_communication/ShareUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java b/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java index debeb902c..9829ddd2e 100644 --- a/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java @@ -314,7 +314,10 @@ public final class ShareUtils { } clipboardManager.setPrimaryClip(ClipData.newPlainText(null, text)); - Toast.makeText(context, R.string.msg_copied, Toast.LENGTH_SHORT).show(); + if (Build.VERSION.SDK_INT < 33) { + // Android 13 has its own "copied to clipboard" dialog + Toast.makeText(context, R.string.msg_copied, Toast.LENGTH_SHORT).show(); + } } /** From 7b7ab3f4199ed649914b80234c8adfc97212bd1e Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Tue, 8 Nov 2022 20:40:09 +0100 Subject: [PATCH 2/2] Remove Utility.copyToClipboard and use ShareUtils.copyToClipboard instead This method is not needed anymore, as ShareUtils.copyToClipboard does almost the same thing (no label is set on the ClipData used to copy text, contrary to what Utility did, but using "text" as a ClipData label doesn't seem useful). It was used in MissionAdapter.handlePopupItem to copy the SHA1 or the MD5 of a file. --- .../us/shandian/giga/ui/adapter/MissionAdapter.java | 2 +- app/src/main/java/us/shandian/giga/util/Utility.java | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index 808928370..26eb2f3b0 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -693,7 +693,7 @@ public class MissionAdapter extends Adapter implements Handler.Callb .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { - Utility.copyToClipboard(mContext, result); + ShareUtils.copyToClipboard(mContext, result); notificationManager.cancel(HASH_NOTIFICATION_ID); }) ); diff --git a/app/src/main/java/us/shandian/giga/util/Utility.java b/app/src/main/java/us/shandian/giga/util/Utility.java index 4cd424ab9..f34d070dc 100644 --- a/app/src/main/java/us/shandian/giga/util/Utility.java +++ b/app/src/main/java/us/shandian/giga/util/Utility.java @@ -192,18 +192,6 @@ public class Utility { } } - public static void copyToClipboard(Context context, String str) { - ClipboardManager cm = ContextCompat.getSystemService(context, ClipboardManager.class); - - if (cm == null) { - Toast.makeText(context, R.string.permission_denied, Toast.LENGTH_LONG).show(); - return; - } - - cm.setPrimaryClip(ClipData.newPlainText("text", str)); - Toast.makeText(context, R.string.msg_copied, Toast.LENGTH_SHORT).show(); - } - public static String checksum(final StoredFileHelper source, final int algorithmId) throws IOException { ByteString byteString;