Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Prevent unnecessary clipboard popups (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelWuensch authored Dec 14, 2020
1 parent 419fda6 commit 718ba0b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/zapsolutions/zap/ScanActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions app/src/main/java/zapsolutions/zap/util/ClipBoardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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)) {
Expand Down Expand Up @@ -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) -> {
});

Expand Down

0 comments on commit 718ba0b

Please sign in to comment.