diff --git a/app/src/main/java/protect/card_locker/BarcodeSelectorActivity.java b/app/src/main/java/protect/card_locker/BarcodeSelectorActivity.java
index 47552ef36..1ee56eb19 100644
--- a/app/src/main/java/protect/card_locker/BarcodeSelectorActivity.java
+++ b/app/src/main/java/protect/card_locker/BarcodeSelectorActivity.java
@@ -116,6 +116,9 @@ public class BarcodeSelectorActivity extends AppCompatActivity
ImageView image = findViewById(barcodeViewMap.get(key));
createBarcodeOption(image, key, s.toString());
}
+
+ View noBarcodeButtonView = findViewById(R.id.noBarcode);
+ setButtonListener(noBarcodeButtonView, s.toString());
}
@Override
@@ -134,6 +137,21 @@ public class BarcodeSelectorActivity extends AppCompatActivity
}
}
+ private void setButtonListener(final View button, final String cardId)
+ {
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View 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();
+ }
+ });
+ }
+
private void createBarcodeOption(final ImageView image, final String formatType, final String cardId)
{
final BarcodeFormat format = BarcodeFormat.valueOf(formatType);
diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java
index 0d115c4a8..bb185b857 100644
--- a/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java
+++ b/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java
@@ -370,7 +370,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
return;
}
- if(cardId.isEmpty() || barcodeType.isEmpty())
+ if(cardId.isEmpty())
{
Snackbar.make(cardIdFieldView, R.string.noCardIdError, Snackbar.LENGTH_LONG).show();
return;
@@ -480,7 +480,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
}
if(contents != null && contents.isEmpty() == false &&
- format != null && format.isEmpty() == false)
+ format != null)
{
Log.i(TAG, "Read barcode id: " + contents);
Log.i(TAG, "Read format: " + format);
diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
index d3db308e3..d89efe3a7 100644
--- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
+++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
@@ -118,7 +118,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
}
String formatString = loyaltyCard.barcodeType;
- final BarcodeFormat format = BarcodeFormat.valueOf(formatString);
+ final BarcodeFormat format = !formatString.isEmpty() ? BarcodeFormat.valueOf(formatString) : null;
final String cardIdString = loyaltyCard.cardId;
cardIdFieldView.setText(loyaltyCard.cardId);
@@ -165,37 +165,44 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
collapsingToolbarLayout.setBackgroundColor(backgroundHeaderColor);
- if(barcodeImage.getHeight() == 0)
+ if(format != null)
{
- Log.d(TAG, "ImageView size is not known known at start, waiting for load");
- // The size of the ImageView is not yet available as it has not
- // yet been drawn. Wait for it to be drawn so the size is available.
- barcodeImage.getViewTreeObserver().addOnGlobalLayoutListener(
- new ViewTreeObserver.OnGlobalLayoutListener()
- {
- @Override
- public void onGlobalLayout()
+ findViewById(R.id.barcode).setVisibility(View.VISIBLE);
+ if(barcodeImage.getHeight() == 0)
+ {
+ Log.d(TAG, "ImageView size is not known known at start, waiting for load");
+ // The size of the ImageView is not yet available as it has not
+ // yet been drawn. Wait for it to be drawn so the size is available.
+ barcodeImage.getViewTreeObserver().addOnGlobalLayoutListener(
+ new ViewTreeObserver.OnGlobalLayoutListener()
{
- if (Build.VERSION.SDK_INT < 16)
+ @Override
+ public void onGlobalLayout()
{
- barcodeImage.getViewTreeObserver().removeGlobalOnLayoutListener(this);
- }
- else
- {
- barcodeImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
- }
+ if (Build.VERSION.SDK_INT < 16)
+ {
+ barcodeImage.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ }
+ else
+ {
+ barcodeImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ }
- Log.d(TAG, "ImageView size now known");
- new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
- }
- });
+ Log.d(TAG, "ImageView size now known");
+ new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
+ }
+ });
+ }
+ else
+ {
+ Log.d(TAG, "ImageView size known known, creating barcode");
+ new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
+ }
}
else
{
- Log.d(TAG, "ImageView size known known, creating barcode");
- new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
+ findViewById(R.id.barcode).setVisibility(View.GONE);
}
-
}
@Override
diff --git a/app/src/main/res/layout/barcode_selector_activity.xml b/app/src/main/res/layout/barcode_selector_activity.xml
index e5884af2e..57470480e 100644
--- a/app/src/main/res/layout/barcode_selector_activity.xml
+++ b/app/src/main/res/layout/barcode_selector_activity.xml
@@ -196,10 +196,11 @@
android:contentDescription="@string/barcodeImageDescription"
android:layout_weight="1.0"/>
+
-
-
-
-
diff --git a/app/src/main/res/layout/loyalty_card_view_layout.xml b/app/src/main/res/layout/loyalty_card_view_layout.xml
index 097a1a898..1ba8ca5e8 100644
--- a/app/src/main/res/layout/loyalty_card_view_layout.xml
+++ b/app/src/main/res/layout/loyalty_card_view_layout.xml
@@ -47,7 +47,7 @@
android:layout_height="0dp"
android:layout_marginLeft="10.0dip"
android:layout_marginRight="10.0dip"
- app:layout_constraintTop_toBottomOf="@id/centerGuideline"
+ app:layout_constraintTop_toBottomOf="@+id/barcode"
app:layout_constraintBottom_toTopOf="@+id/noteViewDivider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index dd540c0b7..46edaf584 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -12,6 +12,7 @@
Note
Card ID
Barcode Type
+ This card has no barcode
Cancel
Save
diff --git a/app/src/test/java/protect/card_locker/LoyaltyCardViewActivityTest.java b/app/src/test/java/protect/card_locker/LoyaltyCardViewActivityTest.java
index 2d543527f..2f02813c2 100644
--- a/app/src/test/java/protect/card_locker/LoyaltyCardViewActivityTest.java
+++ b/app/src/test/java/protect/card_locker/LoyaltyCardViewActivityTest.java
@@ -246,10 +246,6 @@ public class LoyaltyCardViewActivityTest
noteField.setText("note");
shadowActivity.clickMenuItem(R.id.action_save);
assertEquals(0, db.getLoyaltyCardCount());
-
- cardIdField.setText("cardId");
- shadowActivity.clickMenuItem(R.id.action_save);
- assertEquals(0, db.getLoyaltyCardCount());
}
@Test