Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to allow updating a loyalty card from a bundle #2051

Merged
merged 4 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
});

final Bundle b = getIntent().getExtras();
final String initialCardId = b != null ? b.getString("initialCardId") : null;
final String initialCardId = b != null ? b.getString(LoyaltyCard.BUNDLE_LOYALTY_CARD_CARD_ID) : null;

if (initialCardId != null) {
cardId.setText(initialCardId);
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/protect/card_locker/BarcodeValues.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package protect.card_locker;

import androidx.annotation.Nullable;

public class BarcodeValues {
private final String mFormat;
@Nullable
private final CatimaBarcode mFormat;
private final String mContent;
private String mNote;

public BarcodeValues(String format, String content) {
public BarcodeValues(@Nullable CatimaBarcode format, String content) {
mFormat = format;
mContent = content;
}
Expand All @@ -14,7 +17,7 @@ public void setNote(String note) {
mNote = note;
}

public String format() {
public @Nullable CatimaBarcode format() {
return mFormat;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onCreate(Bundle bundle) {
private void onClickAction(int position) {
Cursor selected = DBHelper.getLoyaltyCardCursor(mDatabase, DBHelper.LoyaltyCardArchiveFilter.All);
selected.moveToPosition(position);
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(selected);
LoyaltyCard loyaltyCard = LoyaltyCard.fromCursor(selected);

Log.d(TAG, "Creating shortcut for card " + loyaltyCard.store + "," + loyaltyCard.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public Flow.Publisher<Control> createPublisherForAllAvailable() {
Cursor loyaltyCardCursor = DBHelper.getLoyaltyCardCursor(mDatabase, DBHelper.LoyaltyCardArchiveFilter.Unarchived);
return subscriber -> {
while (loyaltyCardCursor.moveToNext()) {
LoyaltyCard card = LoyaltyCard.toLoyaltyCard(loyaltyCardCursor);
LoyaltyCard card = LoyaltyCard.fromCursor(loyaltyCardCursor);
Intent openIntent = new Intent(this, LoyaltyCardViewActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra("id", card.id);
.putExtra(LoyaltyCardViewActivity.BUNDLE_ID, card.id);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), card.id, openIntent, PendingIntent.FLAG_IMMUTABLE);
subscriber.onNext(
new Control.StatelessBuilder(PREFIX + card.id, pendingIntent)
Expand Down Expand Up @@ -73,7 +73,7 @@ public Flow.Publisher<Control> createPublisherFor(@NonNull List<String> controlI
if (card != null) {
Intent openIntent = new Intent(this, LoyaltyCardViewActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra("id", card.id);
.putExtra(LoyaltyCardViewActivity.BUNDLE_ID, card.id);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), card.id, openIntent, PendingIntent.FLAG_IMMUTABLE);
control = new Control.StatefulBuilder(controlId, pendingIntent)
.setTitle(card.store)
Expand Down Expand Up @@ -129,7 +129,7 @@ public void performControlAction(@NonNull String controlId, @NonNull ControlActi
consumer.accept(ControlAction.RESPONSE_OK);
Intent openIntent = new Intent(this, LoyaltyCardViewActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra("id", controlIdToCardId(controlId));
.putExtra(LoyaltyCardViewActivity.BUNDLE_ID, controlIdToCardId(controlId));
startActivity(openIntent);

closePowerScreenOnAndroid11();
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/protect/card_locker/CatimaBarcode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package protect.card_locker;

import androidx.annotation.NonNull;

import com.google.zxing.BarcodeFormat;

import java.util.Arrays;
Expand Down Expand Up @@ -45,15 +47,15 @@ private CatimaBarcode(BarcodeFormat barcodeFormat) {
mBarcodeFormat = barcodeFormat;
}

public static CatimaBarcode fromBarcode(BarcodeFormat barcodeFormat) {
public static CatimaBarcode fromBarcode(@NonNull BarcodeFormat barcodeFormat) {
return new CatimaBarcode(barcodeFormat);
}

public static CatimaBarcode fromName(String name) {
public static CatimaBarcode fromName(@NonNull String name) {
return new CatimaBarcode(BarcodeFormat.valueOf(name));
}

public static CatimaBarcode fromPrettyName(String prettyName) {
public static CatimaBarcode fromPrettyName(@NonNull String prettyName) {
try {
return new CatimaBarcode(barcodeFormats.get(barcodePrettyNames.indexOf(prettyName)));
} catch (IndexOutOfBoundsException e) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/protect/card_locker/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public static Set<String> imageFiles(Context context, final SQLiteDatabase datab
Set<String> files = new HashSet<>();
Cursor cardCursor = getLoyaltyCardCursor(database);
while (cardCursor.moveToNext()) {
LoyaltyCard card = LoyaltyCard.toLoyaltyCard(cardCursor);
LoyaltyCard card = LoyaltyCard.fromCursor(cardCursor);
for (ImageLocationType imageLocationType : ImageLocationType.values()) {
String name = Utils.getCardImageFileName(card.id, imageLocationType);
if (Utils.retrieveCardImageAsFile(context, name).exists()) {
Expand Down Expand Up @@ -542,7 +542,7 @@ public static LoyaltyCard getLoyaltyCard(SQLiteDatabase database, final int id)

if (data.getCount() == 1) {
data.moveToFirst();
card = LoyaltyCard.toLoyaltyCard(data);
card = LoyaltyCard.fromCursor(data);
}

data.close();
Expand Down
Loading