From 718ba0b318030670b0dc24d86920e0ac2a568401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20W=C3=BCnsch?= Date: Mon, 14 Dec 2020 21:06:41 +0100 Subject: [PATCH] Prevent unnecessary clipboard popups (#281) --- .../java/zapsolutions/zap/ScanActivity.java | 2 +- .../ScanNodePubKeyActivity.java | 2 +- .../zap/setup/ConnectRemoteNodeActivity.java | 2 +- .../zapsolutions/zap/util/ClipBoardUtil.java | 18 +++++++++++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/zapsolutions/zap/ScanActivity.java b/app/src/main/java/zapsolutions/zap/ScanActivity.java index b10b652e..2ec86a6a 100644 --- a/app/src/main/java/zapsolutions/zap/ScanActivity.java +++ b/app/src/main/java/zapsolutions/zap/ScanActivity.java @@ -46,7 +46,7 @@ public void onButtonPasteClick() { super.onButtonPasteClick(); try { - readData(ClipBoardUtil.getPrimaryContent(getApplicationContext())); + readData(ClipBoardUtil.getPrimaryContent(getApplicationContext(), true)); } catch (NullPointerException e) { showError(getResources().getString(R.string.error_emptyClipboardPayment), RefConstants.ERROR_DURATION_SHORT); } diff --git a/app/src/main/java/zapsolutions/zap/channelManagement/ScanNodePubKeyActivity.java b/app/src/main/java/zapsolutions/zap/channelManagement/ScanNodePubKeyActivity.java index 3a17b639..5bea9824 100644 --- a/app/src/main/java/zapsolutions/zap/channelManagement/ScanNodePubKeyActivity.java +++ b/app/src/main/java/zapsolutions/zap/channelManagement/ScanNodePubKeyActivity.java @@ -129,7 +129,7 @@ public void onButtonPasteClick() { super.onButtonPasteClick(); try { - String clipboardContent = ClipBoardUtil.getPrimaryContent(getApplicationContext()); + String clipboardContent = ClipBoardUtil.getPrimaryContent(getApplicationContext(),true); processUserData(clipboardContent); } catch (NullPointerException e) { showError(getResources().getString(R.string.error_emptyClipboardConnect), RefConstants.ERROR_DURATION_SHORT); diff --git a/app/src/main/java/zapsolutions/zap/setup/ConnectRemoteNodeActivity.java b/app/src/main/java/zapsolutions/zap/setup/ConnectRemoteNodeActivity.java index a294cc2a..3a7d6b4e 100644 --- a/app/src/main/java/zapsolutions/zap/setup/ConnectRemoteNodeActivity.java +++ b/app/src/main/java/zapsolutions/zap/setup/ConnectRemoteNodeActivity.java @@ -55,7 +55,7 @@ public void onButtonPasteClick() { String clipboardContent = ""; boolean isClipboardContentValid = false; try { - clipboardContent = ClipBoardUtil.getPrimaryContent(getApplicationContext()); + clipboardContent = ClipBoardUtil.getPrimaryContent(getApplicationContext(), true); isClipboardContentValid = true; } catch (NullPointerException e) { showError(getResources().getString(R.string.error_emptyClipboardConnect), RefConstants.ERROR_DURATION_SHORT); diff --git a/app/src/main/java/zapsolutions/zap/util/ClipBoardUtil.java b/app/src/main/java/zapsolutions/zap/util/ClipBoardUtil.java index 78f69cfa..083a0dde 100644 --- a/app/src/main/java/zapsolutions/zap/util/ClipBoardUtil.java +++ b/app/src/main/java/zapsolutions/zap/util/ClipBoardUtil.java @@ -39,9 +39,17 @@ public static void copyToClipboard(Context context, String label, CharSequence d } } - public static String getPrimaryContent(Context context) throws NullPointerException { + public static String getPrimaryContent(Context context, boolean addToScanHistory) throws NullPointerException { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); - return clipboard.getPrimaryClip().getItemAt(0).getText().toString(); + String data = clipboard.getPrimaryClip().getItemAt(0).getText().toString(); + + if (addToScanHistory) { + // Make sure the data just pasted from the clipboard does not trigger a clipboard scan popup. + // This prevents a popup directly after a new wallet was setup using paste. + String clipboardContentHash = UtilFunctions.sha256Hash(data); + PrefsUtil.edit().putString(PrefsUtil.LAST_CLIPBOARD_SCAN, clipboardContentHash).apply(); + } + return data; } @@ -52,12 +60,12 @@ public static void performClipboardScan(Context context, CompositeDisposable com } try { - getPrimaryContent(context); + getPrimaryContent(context, false); } catch (NullPointerException e) { return; } - String clipboardContent = getPrimaryContent(context); + String clipboardContent = getPrimaryContent(context, false); String clipboardContentHash = UtilFunctions.sha256Hash(clipboardContent); if (PrefsUtil.getPrefs().getString(PrefsUtil.LAST_CLIPBOARD_SCAN, "").equals(clipboardContentHash)) { @@ -146,7 +154,7 @@ private static void showProceedQuestion(int question, Context context, OnClipboa AlertDialog.Builder adb = new AlertDialog.Builder(context) .setMessage(question) .setCancelable(true) - .setPositiveButton(R.string.continue_string, (dialog, whichButton) -> listener.onProceed(getPrimaryContent(context))) + .setPositiveButton(R.string.continue_string, (dialog, whichButton) -> listener.onProceed(getPrimaryContent(context, false))) .setNegativeButton(R.string.no, (dialog, which) -> { });