From efef397870cb2fe09081abb1c1541da23859ad5f Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Wed, 23 Mar 2022 19:13:54 +0100 Subject: [PATCH] Fix gray block appearing on invalid value for barcode --- CHANGELOG.md | 5 ++ .../card_locker/LoyaltyCardViewActivity.java | 52 +++++++++++++------ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02dc8e14a..dabf7e004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased - 105 + +- Fix gray block appearing on invalid value for barcode +- Stocard import fixes + ## v2.16.0 - 104 (2022-03-09) - Save card detail expansion state diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java index caa53f928..da3839a91 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java @@ -122,6 +122,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements private final int HEADER_FILTER_ALPHA = 127; final private TaskHandler mTasks = new TaskHandler(); + Runnable barcodeImageGenerationFinishedCallback; @Override public boolean onDown(MotionEvent e) { @@ -286,6 +287,19 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements iconImage = findViewById(R.id.icon_image); landscapeToolbar = findViewById(R.id.toolbar_landscape); + barcodeImageGenerationFinishedCallback = () -> { + if (!(boolean) mainImage.getTag()) { + mainImage.setVisibility(View.GONE); + imageTypes.remove(ImageType.BARCODE); + + // Redraw UI + setDotIndicator(Utils.isDarkModeEnabled(LoyaltyCardViewActivity.this)); + setFullscreen(isFullscreen); + + Toast.makeText(LoyaltyCardViewActivity.this, getString(R.string.wrongValueForBarcodeType), Toast.LENGTH_LONG).show(); + } + }; + centerGuideline = findViewById(R.id.centerGuideline); barcodeScaler = findViewById(R.id.barcodeScaler); barcodeScaler.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @@ -649,22 +663,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements imageTypes.add(ImageType.IMAGE_BACK); } - dotIndicator.removeAllViews(); - if (imageTypes.size() >= 2) { - dots = new ImageView[imageTypes.size()]; - - for (int i = 0; i < imageTypes.size(); i++) { - dots[i] = new ImageView(this); - dots[i].setImageDrawable(getDotIcon(false, darkMode)); - - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); - params.setMargins(8, 0, 8, 0); - - dotIndicator.addView(dots[i], params); - } - - dotIndicator.setVisibility(View.VISIBLE); - } + setDotIndicator(darkMode); setFullscreen(isFullscreen); @@ -818,7 +817,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements format, null, false, - null, + barcodeImageGenerationFinishedCallback, addPadding); mTasks.executeTask(TaskHandler.TYPE.BARCODE, barcodeWriter); } @@ -900,6 +899,25 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements drawMainImage(newIndex, false, isFullscreen); } + private void setDotIndicator(boolean darkMode) { + dotIndicator.removeAllViews(); + if (imageTypes.size() >= 2) { + dots = new ImageView[imageTypes.size()]; + + for (int i = 0; i < imageTypes.size(); i++) { + dots[i] = new ImageView(this); + dots[i].setImageDrawable(getDotIcon(false, darkMode)); + + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); + params.setMargins(8, 0, 8, 0); + + dotIndicator.addView(dots[i], params); + } + + dotIndicator.setVisibility(View.VISIBLE); + } + } + /** * When enabled, hides the status bar and moves the barcode to the top of the screen. *