Put all barcode related fields together in the edit screen

This commit is contained in:
Sylvia van Os
2022-01-02 21:40:44 +01:00
parent 3883617a34
commit a7a775bc01
4 changed files with 119 additions and 134 deletions

View File

@@ -4,6 +4,7 @@
- Fixed pressing the save button multiple times creating multiple entries
- Lower card header size when hiding details to fit even more cards
- Restructure edit dialog
## v2.12.0 - 96 (2021-12-23)

View File

@@ -153,7 +153,7 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
AlertDialog confirmExitDialog = null;
boolean validBalance = true;
Runnable warnOnInvalidBarcodeType;
Runnable barcodeImageGenerationFinishedCallback;
HashMap<String, Currency> currencies = new HashMap<>();
@@ -208,6 +208,10 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
private void updateTempState(LoyaltyCardField fieldName, Object value) {
tempLoyaltyCard = updateTempState(tempLoyaltyCard, fieldName, value);
if (initDone && (fieldName == LoyaltyCardField.cardId || fieldName == LoyaltyCardField.barcodeId || fieldName == LoyaltyCardField.barcodeType)) {
generateBarcode();
}
hasChanged = true;
}
@@ -223,7 +227,7 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
importLoyaltyCardUri = intent.getData();
Log.d(TAG, "View activity: id=" + loyaltyCardId
Log.d(TAG, "Edit activity: id=" + loyaltyCardId
+ ", updateLoyaltyCard=" + updateLoyaltyCard);
}
@@ -326,8 +330,9 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
cardImageFront.setBackgroundColor(getThemeColor());
cardImageBack.setBackgroundColor(getThemeColor());
warnOnInvalidBarcodeType = () -> {
barcodeImageGenerationFinishedCallback = () -> {
if (!(boolean) barcodeImage.getTag()) {
barcodeImageLayout.setVisibility(View.GONE);
Toast.makeText(LoyaltyCardEditActivity.this, getString(R.string.wrongValueForBarcodeType), Toast.LENGTH_LONG).show();
}
};
@@ -524,8 +529,6 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
} else {
updateTempState(LoyaltyCardField.barcodeId, s.toString());
}
generateOrHideBarcode();
}
@Override
@@ -556,8 +559,6 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
} catch (IllegalArgumentException e) {
}
}
generateOrHideBarcode();
}
}
@@ -889,7 +890,7 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
hasChanged = hadChanges;
}
generateOrHideBarcode();
generateBarcode();
enterButton.setOnClickListener(new EditCardIdAndBarcode());
barcodeImage.setOnClickListener(new EditCardIdAndBarcode());
@@ -1403,27 +1404,22 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
);
}
private void showBarcode() {
barcodeImageLayout.setVisibility(View.VISIBLE);
}
private void generateBarcode() {
if (tempLoyaltyCard == null) {
return;
}
private void hideBarcode() {
barcodeImageLayout.setVisibility(View.GONE);
}
mTasks.flushTaskList(TaskHandler.TYPE.BARCODE, true, false, false);
private void generateOrHideBarcode() {
String cardIdString = tempLoyaltyCard.barcodeId != null ? tempLoyaltyCard.barcodeId : tempLoyaltyCard.cardId;
CatimaBarcode barcodeFormat = tempLoyaltyCard.barcodeType;
if (barcodeFormat == null || cardIdString.isEmpty() || !barcodeFormat.isSupported()) {
hideBarcode();
} else {
generateBarcode(cardIdString, barcodeFormat);
if (cardIdString == null || barcodeFormat == null) {
barcodeImageLayout.setVisibility(View.GONE);
return;
}
}
private void generateBarcode(String cardIdString, CatimaBarcode barcodeFormat) {
mTasks.flushTaskList(TaskHandler.TYPE.BARCODE, true, false, false);
barcodeImageLayout.setVisibility(View.VISIBLE);
if (barcodeImage.getHeight() == 0) {
Log.d(TAG, "ImageView size is not known known at start, waiting for load");
@@ -1436,17 +1432,15 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
barcodeImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Log.d(TAG, "ImageView size now known");
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getApplicationContext(), barcodeImage, cardIdString, barcodeFormat, null, false, warnOnInvalidBarcodeType);
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getApplicationContext(), barcodeImage, cardIdString, barcodeFormat, null, false, barcodeImageGenerationFinishedCallback);
mTasks.executeTask(TaskHandler.TYPE.BARCODE, barcodeWriter);
}
});
} else {
Log.d(TAG, "ImageView size known known, creating barcode");
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getApplicationContext(), barcodeImage, cardIdString, barcodeFormat, null, false, warnOnInvalidBarcodeType);
BarcodeImageWriterTask barcodeWriter = new BarcodeImageWriterTask(getApplicationContext(), barcodeImage, cardIdString, barcodeFormat, null, false, barcodeImageGenerationFinishedCallback);
mTasks.executeTask(TaskHandler.TYPE.BARCODE, barcodeWriter);
}
showBarcode();
}
private void generateIcon(String store) {
@@ -1476,30 +1470,24 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
}
View cardPart = findViewById(R.id.cardPart);
View barcodePart = findViewById(R.id.barcodePart);
View optionsPart = findViewById(R.id.optionsPart);
View picturesPart = findViewById(R.id.picturesPart);
if (getString(R.string.card).equals(part)) {
cardPart.setVisibility(View.VISIBLE);
barcodePart.setVisibility(View.GONE);
picturesPart.setVisibility(View.GONE);
// Explicitly hide barcode (fixes blurriness on redraw)
hideBarcode();
} else if (getString(R.string.barcode).equals(part)) {
cardPart.setVisibility(View.GONE);
barcodePart.setVisibility(View.VISIBLE);
optionsPart.setVisibility(View.GONE);
picturesPart.setVisibility(View.GONE);
// Redraw barcode due to size change (Visibility.GONE sets it to 0)
generateOrHideBarcode();
generateBarcode();
} else if (getString(R.string.options).equals(part)) {
cardPart.setVisibility(View.GONE);
optionsPart.setVisibility(View.VISIBLE);
picturesPart.setVisibility(View.GONE);
} else if (getString(R.string.photos).equals(part)) {
cardPart.setVisibility(View.GONE);
barcodePart.setVisibility(View.GONE);
optionsPart.setVisibility(View.GONE);
picturesPart.setVisibility(View.VISIBLE);
// Explicitly hide barcode (fixes blurriness on redraw)
hideBarcode();
} else {
throw new UnsupportedOperationException();
}

View File

@@ -39,7 +39,7 @@
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/barcode"/>
android:text="@string/options"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -128,6 +128,94 @@
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<!-- Barcode ID -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/inputPadding"
android:paddingTop="@dimen/inputPadding"
android:orientation="horizontal">
<!-- Barcode ID -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/barcodeIdView"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:hint="@string/barcodeId"
android:labelFor="@+id/barcodeIdView">
<AutoCompleteTextView
android:id="@+id/barcodeIdField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<!-- Barcode type -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/inputPadding"
android:paddingTop="@dimen/inputPadding"
android:orientation="horizontal">
<!-- Barcode type -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/barcodeTypeView"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:hint="@string/barcodeType"
android:labelFor="@+id/barcodeTypeField">
<AutoCompleteTextView
android:id="@+id/barcodeTypeField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<!-- Barcode -->
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/barcodeLayout">
<ImageView
android:layout_width="0dp"
android:layout_height="@dimen/barcode_disp_height"
android:layout_gravity="center_horizontal"
android:padding="10.0dp"
android:background="#ffffff"
android:id="@+id/barcode"
android:layout_weight="1.0"/>
</LinearLayout>
<!-- Buttons -->
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/barcodeCaptureLayout">
<Button android:id="@+id/enterButton"
android:layout_margin="@dimen/inputMargin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/editBarcode"
android:textColor="#FFFFFF"
android:layout_weight="1.0"/>
</LinearLayout>
</TableLayout>
<TableLayout
android:id="@+id/optionsPart"
android:visibility="gone">
<!-- Note -->
<LinearLayout
android:layout_width="match_parent"
@@ -240,99 +328,6 @@
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</TableLayout>
<TableLayout
android:id="@+id/barcodePart"
android:visibility="gone">
<!-- Barcode ID -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/inputPadding"
android:paddingTop="@dimen/inputPadding"
android:orientation="horizontal">
<!-- Barcode ID -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/barcodeIdView"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:hint="@string/barcodeId"
android:labelFor="@+id/barcodeIdView">
<AutoCompleteTextView
android:id="@+id/barcodeIdField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<!-- Barcode type -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/inputPadding"
android:paddingTop="@dimen/inputPadding"
android:orientation="horizontal">
<!-- Barcode type -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/barcodeTypeView"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:hint="@string/barcodeType"
android:labelFor="@+id/barcodeTypeField">
<AutoCompleteTextView
android:id="@+id/barcodeTypeField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<!-- Barcode -->
<View
android:layout_height="@dimen/inputBorderThickness"
android:layout_width="match_parent" />
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="@+id/barcodeLayout">
<ImageView
android:layout_width="0dp"
android:layout_height="@dimen/barcode_disp_height"
android:layout_gravity="center_horizontal"
android:padding="10.0dp"
android:background="#ffffff"
android:id="@+id/barcode"
android:layout_weight="1.0"/>
</LinearLayout>
<!-- Buttons -->
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/barcodeCaptureLayout">
<Button android:id="@+id/enterButton"
android:layout_margin="@dimen/inputMargin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/editBarcode"
android:textColor="#FFFFFF"
android:layout_weight="1.0"/>
</LinearLayout>
</TableLayout>
<TableLayout
android:id="@+id/picturesPart"

View File

@@ -259,4 +259,5 @@
<string name="action_hide_details">Hide details</string>
<string name="translate_platform">on Weblate</string>
<string name="shortcutSelectCard">Select a card</string>
<string name="options">Options</string>
</resources>