Copy card ID to clipboard from menu or long press (#2789)

Co-authored-by: Sylvia van Os <sylvia@hackerchick.me>
This commit is contained in:
Aditya Varma
2025-11-28 00:13:26 +05:30
committed by GitHub
parent c89a759c8b
commit 5a0d99fc80
2 changed files with 34 additions and 2 deletions

View File

@@ -1,8 +1,9 @@
package protect.card_locker;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
@@ -704,10 +705,22 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
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(android.R.string.ok, (dialog, which) -> dialog.dismiss());
builder.setNeutralButton(R.string.copy_value, (dialog, which) -> {
copyCardIdToClipboard();
});
AlertDialog dialog = builder.create();
dialog.show();
});
binding.mainImageDescription.setOnLongClickListener(view -> {
if (mainImageIndex != 0) {
// Don't copy to clipboard, we're showing something else
return false;
}
copyCardIdToClipboard();
return true;
});
int backgroundHeaderColor = Utils.getHeaderColor(this, loyaltyCard);
@@ -1247,4 +1260,20 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
);
}
}
private void copyCardIdToClipboard() {
// Take the value thats 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(getString(R.string.cardId), value);
cm.setPrimaryClip(clip);
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
}

View File

@@ -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>