Ask to update barcode value if card ID changes

This commit is contained in:
Sylvia van Os
2021-06-06 21:13:44 +02:00
parent eec7359603
commit 929633e4dd
3 changed files with 84 additions and 28 deletions

View File

@@ -7,6 +7,7 @@ Changes:
- Support new PDF417 export from Voucher Vault
- Support copying multiple barcodes at once
- Support sharing multiple loyalty cards at once
- Ask to update barcode value if card ID changes
## v1.13 (2021-04-10)

View File

@@ -93,6 +93,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
ImportURIHelper importUriHelper;
boolean hasChanged = false;
String tempStoredOldBarcodeValue = null;
boolean initDone = false;
AlertDialog confirmExitDialog = null;
@@ -171,12 +172,9 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
enterButton = findViewById(R.id.enterButton);
warnOnInvalidBarcodeType = new Runnable() {
@Override
public void run() {
if (!(boolean) barcodeImage.getTag()) {
Toast.makeText(LoyaltyCardEditActivity.this, getString(R.string.wrongValueForBarcodeType), Toast.LENGTH_LONG).show();
}
warnOnInvalidBarcodeType = () -> {
if (!(boolean) barcodeImage.getTag()) {
Toast.makeText(LoyaltyCardEditActivity.this, getString(R.string.wrongValueForBarcodeType), Toast.LENGTH_LONG).show();
}
};
@@ -322,15 +320,30 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
cardIdFieldView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (initDone) {
if (tempStoredOldBarcodeValue == null) {
// We changed the card ID, save the current barcode ID in a temp
// variable and make sure to ask the user later if they also want to
// update the barcode ID
if (barcodeIdField.getTag() == null) {
// If it is set to "same as Card ID", temp-save the value before the
// Card ID change
tempStoredOldBarcodeValue = s.toString();
} else {
// Otherwise, set the temp value to the current field value
tempStoredOldBarcodeValue = barcodeIdField.getText().toString();
}
barcodeIdField.setText(tempStoredOldBarcodeValue);
barcodeIdField.setTag(tempStoredOldBarcodeValue);
}
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
hasChanged = true;
if (!s.toString().isEmpty()) {
generateOrHideBarcode();
}
}
@Override
@@ -350,6 +363,10 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
hasChanged = true;
if (s.toString().equals(getString(R.string.sameAsCardId))) {
// If the user manually changes the barcode again make sure we disable the
// request to update it to match the card id (if changed)
tempStoredOldBarcodeValue = null;
barcodeIdField.setTag(null);
} else if (s.toString().equals(getString(R.string.setBarcodeId))) {
if (!lastValue.toString().equals(getString(R.string.setBarcodeId))) {
@@ -365,19 +382,15 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
}
builder.setView(input);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
barcodeIdField.setTag(input.getText().toString());
barcodeIdField.setText(input.getText());
}
});
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
builder.setPositiveButton(getString(R.string.ok), (dialog, which) -> {
// If the user manually changes the barcode again make sure we disable the
// request to update it to match the card id (if changed)
tempStoredOldBarcodeValue = null;
barcodeIdField.setTag(input.getText().toString());
barcodeIdField.setText(input.getText());
});
builder.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.cancel());
AlertDialog dialog = builder.create();
dialog.show();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
@@ -635,11 +648,6 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
thumbnail.setOnClickListener(new ColorSelectListener(headingColorValue));
if (!initDone) {
hasChanged = false;
initDone = true;
}
// Update from intent
if (barcodeType != null) {
try {
@@ -661,6 +669,11 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
}
}
if (!initDone) {
hasChanged = false;
initDone = true;
}
generateOrHideBarcode();
enterButton.setOnClickListener(new EditCardIdAndBarcode());
@@ -693,8 +706,36 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
askBeforeQuitIfChanged();
}
private void askBarcodeChange(Runnable callback) {
new AlertDialog.Builder(this)
.setTitle(R.string.updateBarcodeQuestionTitle)
.setMessage(R.string.updateBarcodeQuestionText)
.setPositiveButton(R.string.yes, (dialog, which) -> {
barcodeIdField.setText(R.string.sameAsCardId);
tempStoredOldBarcodeValue = null;
if (callback != null) {
callback.run();
}
})
.setNegativeButton(R.string.no, (dialog, which) -> {
barcodeIdField.setText(tempStoredOldBarcodeValue);
tempStoredOldBarcodeValue = null;
if (callback != null) {
callback.run();
}
})
.show();
}
private void askBeforeQuitIfChanged() {
if (!hasChanged) {
if (tempStoredOldBarcodeValue != null) {
askBarcodeChange(this::askBeforeQuitIfChanged);
return;
}
finish();
return;
}
@@ -819,6 +860,11 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
private void doSave()
{
if (tempStoredOldBarcodeValue != null) {
askBarcodeChange(this::doSave);
return;
}
String store = storeFieldEdit.getText().toString();
String note = noteFieldEdit.getText().toString();
Date expiry = (Date) expiryField.getTag();
@@ -1008,6 +1054,11 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
}
private void showPart(String part) {
if (tempStoredOldBarcodeValue != null) {
askBarcodeChange(() -> showPart(part));
return;
}
View cardPart = findViewById(R.id.cardPart);
View barcodePart = findViewById(R.id.barcodePart);

View File

@@ -177,4 +177,8 @@
<string name="wrongValueForBarcodeType">The value is not valid for the selected barcode type</string>
<string name="copy_to_clipboard_multiple_toast">Copied card IDs to clipboard</string>
<string name="intent_import_card_from_url_share_multiple_text">I want to share some cards with you</string>
<string name="updateBarcodeQuestionTitle">Update barcode value?</string>
<string name="updateBarcodeQuestionText">You changed the card ID. Do you want to also update the barcode to use the same value?</string>
<string name="yes">Yes</string>
<string name="no">No</string>
</resources>