Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ziadOUA committed Sep 29, 2023
2 parents 76863d6 + a2b224d commit f1c4370
Show file tree
Hide file tree
Showing 58 changed files with 455 additions and 426 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog-to-fastlane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
permissions:
actions: none
checks: none
contents: read
contents: write
deployments: none
discussions: none
id-token: none
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased - 132

- Refine "Add card" workflow
- Validation flow improvements

## v2.26.0 - 131 (2023-09-14)

- Move "Archive mode" into "Display options" (previously "Show details") menu
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/java/com/ziadoua/zcard/BarcodeSelectorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.util.ArrayList;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;

import com.ziadoua.zcard.databinding.BarcodeSelectorActivityBinding;
Expand Down Expand Up @@ -66,10 +65,6 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

runOnUiThread(() -> {
generateBarcodes(s.toString());

View noBarcodeButtonView = binding.noBarcode;
setButtonListener(noBarcodeButtonView, s.toString());
noBarcodeButtonView.setEnabled(s.length() > 0);
});
}, INPUT_DELAY);
}
Expand All @@ -95,17 +90,6 @@ private void generateBarcodes(String value) {
mAdapter.setBarcodes(barcodes);
}

private void setButtonListener(final View button, final String cardId) {
button.setOnClickListener(view -> {
Log.d(TAG, "Selected no barcode");
Intent result = new Intent();
result.putExtra(BARCODE_FORMAT, "");
result.putExtra(BARCODE_CONTENTS, cardId);
BarcodeSelectorActivity.this.setResult(RESULT_OK, result);
finish();
});
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Expand Down
65 changes: 53 additions & 12 deletions app/src/main/java/com/ziadoua/zcard/LoyaltyCardEditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ private void extractIntentFields(Intent intent) {
+ ", updateLoyaltyCard=" + updateLoyaltyCard);
}


@Override
public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
Expand Down Expand Up @@ -378,8 +377,15 @@ protected void onCreate(Bundle savedInstanceState) {
storeFieldEdit.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateTempState(LoyaltyCardField.store, s.toString());
generateIcon(s.toString());
String storeName = s.toString().trim();
updateTempState(LoyaltyCardField.store, storeName);
generateIcon(storeName);

if (storeName.length() == 0) {
storeFieldEdit.setError(getString(R.string.field_must_not_be_empty));
} else {
storeFieldEdit.setError(null);
}
}
});

Expand Down Expand Up @@ -411,6 +417,10 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

balanceField.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus && !onResuming && !onRestoring) {
if (balanceField.getText().toString().isEmpty()) {
updateTempState(LoyaltyCardField.balance, BigDecimal.valueOf(0));
}

balanceField.setText(Utils.formatBalanceWithoutCurrencySymbol(tempLoyaltyCard.balance, tempLoyaltyCard.balanceType));
}
});
Expand All @@ -422,10 +432,12 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
try {
BigDecimal balance = Utils.parseBalance(s.toString(), tempLoyaltyCard.balanceType);
updateTempState(LoyaltyCardField.balance, balance);
balanceField.setError(null);
validBalance = true;
} catch (ParseException e) {
validBalance = false;
e.printStackTrace();
balanceField.setError(getString(R.string.balanceParsingFailed));
validBalance = false;
}
}
});
Expand Down Expand Up @@ -501,6 +513,12 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateTempState(LoyaltyCardField.cardId, s.toString());

if (s.length() == 0) {
cardIdFieldView.setError(getString(R.string.field_must_not_be_empty));
} else {
cardIdFieldView.setError(null);
}
}
});

Expand Down Expand Up @@ -946,7 +964,7 @@ public void onResume() {
saveButton.setOnClickListener(v -> doSave());
saveButton.bringToFront();

generateIcon(storeFieldEdit.getText().toString());
generateIcon(storeFieldEdit.getText().toString().trim());

// It can't be null because we set it in updateTempState but SpotBugs insists it can be
// NP_NULL_ON_SOME_PATH: Possible null pointer dereference and
Expand Down Expand Up @@ -1365,7 +1383,7 @@ public void onColorSelected(int dialogId, int color) {
thumbnailEditIcon.setBackgroundColor(Utils.needsDarkForeground(color) ? Color.BLACK : Color.WHITE);
thumbnailEditIcon.setColorFilter(Utils.needsDarkForeground(color) ? Color.WHITE : Color.BLACK);

generateIcon(storeFieldEdit.getText().toString());
generateIcon(storeFieldEdit.getText().toString().trim());
}

// ColorPickerDialogListener callback
Expand Down Expand Up @@ -1484,18 +1502,41 @@ private void doSave() {
return;
}

boolean hasError = false;

if (tempLoyaltyCard.store.isEmpty()) {
Snackbar.make(storeFieldEdit, R.string.noStoreError, Snackbar.LENGTH_LONG).show();
return;
storeFieldEdit.setError(getString(R.string.field_must_not_be_empty));

// Focus element
tabs.selectTab(tabs.getTabAt(0));
storeFieldEdit.requestFocus();

hasError = true;
}

if (tempLoyaltyCard.cardId.isEmpty()) {
Snackbar.make(cardIdFieldView, R.string.noCardIdError, Snackbar.LENGTH_LONG).show();
return;
cardIdFieldView.setError(getString(R.string.field_must_not_be_empty));

// Focus element if first error element
if (!hasError) {
tabs.selectTab(tabs.getTabAt(0));
cardIdFieldView.requestFocus();
hasError = true;
}
}

if (!validBalance) {
Snackbar.make(balanceField, getString(R.string.parsingBalanceFailed, balanceField.getText().toString()), Snackbar.LENGTH_LONG).show();
balanceField.setError(getString(R.string.balanceParsingFailed));

// Focus element if first error element
if (!hasError) {
tabs.selectTab(tabs.getTabAt(1));
balanceField.requestFocus();
hasError = true;
}
}

if (hasError) {
return;
}

Expand Down Expand Up @@ -1631,7 +1672,7 @@ private void generateBarcode() {
String cardIdString = tempLoyaltyCard.barcodeId != null ? tempLoyaltyCard.barcodeId : tempLoyaltyCard.cardId;
CatimaBarcode barcodeFormat = tempLoyaltyCard.barcodeType;

if (cardIdString == null || barcodeFormat == null) {
if (cardIdString == null || cardIdString.isEmpty() || barcodeFormat == null) {
barcodeImageLayout.setVisibility(View.GONE);
return;
}
Expand Down
Loading

0 comments on commit f1c4370

Please sign in to comment.