mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2025-12-23 23:28:14 -05:00
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:
@@ -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 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(getString(R.string.cardId), value);
|
||||
cm.setPrimaryClip(clip);
|
||||
|
||||
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user