-
-
Notifications
You must be signed in to change notification settings - Fork 219
Add “Copy value” overflow action to card view #2789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
|
@@ -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) -> { | ||
| ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); | ||
| cm.setPrimaryClip(ClipData.newPlainText("QR value", loyaltyCard.cardId)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| // 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(); | ||
| }); | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed: not in the 3 dots menu please. |
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also use the |
||
| cm.setPrimaryClip(clip); | ||
|
|
||
| Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show(); | ||
| } | ||
|
|
||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
||
There was a problem hiding this comment.
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.