Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
import protect.card_locker.databinding.LoyaltyCardViewLayoutBinding;
import protect.card_locker.preferences.Settings;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.widget.Toast;

public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements BarcodeImageWriterResultCallback {
private LoyaltyCardViewLayoutBinding binding;
private static final String TAG = "Catima";
Expand Down Expand Up @@ -704,7 +708,13 @@ protected void onResume() {
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(LoyaltyCardViewActivity.this);
builder.setTitle(R.string.cardId);
builder.setView(cardIdView);
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> dialogInterface.dismiss());
builder.setPositiveButton(R.string.copy_value, (dialog, which) -> {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this makes sense as the positive button, the default action probably shouldn't be to copy to clipboard.

ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
cm.setPrimaryClip(ClipData.newPlainText("QR value", loyaltyCard.cardId));
Copy link
Member

Choose a reason for hiding this comment

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

"QR value" should be translatable. I think it makes more sense to use the cardId translatable

// Optional app toast; comment out if you rely on Android's privacy toast only
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
});
builder.setNegativeButton(android.R.string.ok, (dialog, which) -> dialog.dismiss());
AlertDialog dialog = builder.create();
dialog.show();
});
Expand Down Expand Up @@ -914,6 +924,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
AlertDialog dialog = builder.create();
dialog.show();

return true;
} else if (id == R.id.action_copy_value) {
copyValueToClipboard(); // <— helper you added earlier
Comment on lines +927 to +929
Copy link
Member

Choose a reason for hiding this comment

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

As discussed: not in the 3 dots menu please.

return true;
}

Expand Down Expand Up @@ -1247,4 +1260,21 @@ private void setFullscreenModeSdkLessThan30() {
);
}
}

private void copyValueToClipboard() {
// Take the value that’s already displayed to the user
String value = loyaltyCard.cardId;

if (value == null || value.isEmpty()) {
Toast.makeText(this, R.string.nothing_to_copy, Toast.LENGTH_SHORT).show();
return;
}

ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Card value", value);
Copy link
Member

Choose a reason for hiding this comment

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

Let's also use the cardId translatable here.

cm.setPrimaryClip(clip);

Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}

}
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/baseline_content_copy_24.xml
Copy link
Member

Choose a reason for hiding this comment

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

Not needed because we don't want this in the menu

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:height="24dp"
android:viewportWidth="24" android:viewportHeight="24">
<path android:fillColor="?attr/colorOnSurface"
android:pathData="M16,1H4c-1.1,0 -2,0.9 -2,2v14h2V3h12V1zM19,5H8
c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2V7
c0,-1.1 -0.9,-2 -2,-2zm0,16H8V7h11v14z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/card_view_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
android:title="@string/duplicateCard"
app:showAsAction="never" />

<item
android:id="@+id/action_copy_value"
android:title="@string/copy_value"
app:showAsAction="ifRoom" />

Comment on lines +30 to +34
Copy link
Member

Choose a reason for hiding this comment

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

Also should be removed because we don't want it in the menu

<item
android:id="@+id/action_archive"
android:title="@string/archive"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,7 @@
<string name="acra_crash_email_subject"><xliff:g id="app_name">%s</xliff:g> crash report</string>
<string name="pref_enable_acra">Ask to send crash reports</string>
<string name="pref_enable_acra_summary">When enabled, you will be asked to report a crash when it happens. Crash reports are never sent automatically.</string>
<string name="copy_value">Copy value</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="nothing_to_copy">No value found</string>
</resources>