Skip to content

Conversation

@LucasVermersch
Copy link

  • Feature : Copy the barcode value when long pressing the barcode image
  • Feature : Copy the barcode value when long pressing the barcode description
  • Test : Add test for the previous features

@LucasVermersch
Copy link
Author

#2400

@TheLastProject
Copy link
Member

As I stated in the issue, long-pressing the main image already had existing functionality. We should try to minimize breaking existing functionality, so please do not change that behaviour.

As written in the issue, please

  • Copy it when the barcode text is long-pressed
  • Add a "Copy" button to the dialog that shows up when short tapping the barcode to copy the whole barcode (for easier discoverability)

I'm also not sure if we should show a toast on modern Android versions, as Android already shows its own UI element to show it copied the content (though not sure which version added that), but I guess it's fine to figure that out later and just always show it for now.

Copy link
Member

@TheLastProject TheLastProject left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Mostly looks good, just some small notes.

Also, I noticed another bug during review, so we may as well clean that up (but GitHub sadly doesn't let me comment on unchanged lines):

In this part:

        binding.mainImageDescription.setOnClickListener(v -> {
            if (mainImageIndex != 0) {
                // Don't show cardId dialog, we're displaying something else
                return;
            }

we should probably just remove the if statement:

            if (mainImageIndex != 0) {
                // Don't show cardId dialog, we're displaying something else
                return;
            }

}

private boolean copyBarcodeToClipBoard(){
if (imageTypes.get(mainImageIndex) == ImageType.BARCODE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to crash if the card has "Barcode Type" set to "No barcode" and has no photo too.

I was about to suggest using the mainImageIndex != 0 check from binding.mainImageDescription.setOnClickListener but I just realized that that check is wrong too (it fails if there is no barcode but an image).

Maybe, given that field does not currently do anything, and copying the text "Front image" or "Back image" is useless... maybe just remove this check altogether and always copy the barcode on long-press?

});

binding.mainImage.setOnClickListener(view -> onMainImageTap());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm weird, but I quite like the setOnClickListener and setOnLongClickListener of the same object being directly below each other :)

Suggested change

return true;
});

binding.mainImageDescription.setOnLongClickListener(view -> copyBarcodeToClipBoard());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better to move directly below binding.mainImageDescription.setOnClickListener so everything of binding.mainImageDescription is in one place.

checkAllFields(activity, ViewMode.ADD_CARD, "Example Store", "", context.getString(R.string.anyDate), context.getString(R.string.never), "0", context.getString(R.string.points), "123456", context.getString(R.string.sameAsCardId), "Aztec", null, null);
assertEquals(-416706, ((ColorDrawable) activity.findViewById(R.id.thumbnail).getBackground()).getColor());
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change



@Test
public void longPressOnBarcodeShouldCopyTheBarcodeValue() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test name isn't completely accurate as it tests both the long and short click flows :)

Suggested change
public void longPressOnBarcodeShouldCopyTheBarcodeValue() {
public void testCopyBarcodeValue() {

Comment on lines +152 to +155
String barcodeString = barcodeIdString != null ? barcodeIdString : cardIdString;
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (clipboard != null) {
android.content.ClipData clip = android.content.ClipData.newPlainText("Barcode", barcodeString);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most users want to copy the cardId, not the barcodeId.

CardID = the value written on the physical card (mostly the customer number)
BarcodeID = whatever is in the barcode itself (which may contain random gibberish)

The cardId is also what's written in the dialog window.

Suggested change
String barcodeString = barcodeIdString != null ? barcodeIdString : cardIdString;
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (clipboard != null) {
android.content.ClipData clip = android.content.ClipData.newPlainText("Barcode", barcodeString);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (clipboard != null) {
android.content.ClipData clip = android.content.ClipData.newPlainText("Card ID", loyaltyCard.cardId);

@TheLastProject TheLastProject linked an issue Apr 17, 2025 that may be closed by this pull request
@TheLastProject TheLastProject marked this pull request as draft July 26, 2025 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy the value of the barcode by pressing on it

2 participants