Skip to content

Commit

Permalink
Merge pull request #2038 from CatimaLoyalty/feature/pkpass2024
Browse files Browse the repository at this point in the history
Add Pkpass parser
  • Loading branch information
TheLastProject authored Dec 7, 2024
2 parents 3bdc06b + 8009bac commit f8a8a84
Show file tree
Hide file tree
Showing 41 changed files with 1,665 additions and 668 deletions.
16 changes: 9 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.spotbugs.snom.SpotBugsTask
plugins {
id("com.android.application")
id("com.github.spotbugs")
id("org.jetbrains.kotlin.android")
}

spotbugs {
Expand Down Expand Up @@ -62,8 +63,8 @@ android {
// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

sourceSets {
Expand All @@ -84,25 +85,26 @@ android {
lint {
lintConfig = file("lint.xml")
}
kotlinOptions {
jvmTarget = "17"
}
}

dependencies {

// AndroidX
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.constraintlayout:constraintlayout:2.2.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.exifinterface:exifinterface:1.3.7")
implementation("androidx.palette:palette:1.0.0")
implementation("androidx.preference:preference:1.2.1")
implementation("com.google.android.material:material:1.12.0")
implementation("com.github.yalantis:ucrop:2.2.10")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.3")

// Splash Screen
implementation("androidx.core:core-splashscreen:1.0.1")

// Third-party
implementation("com.journeyapps:zxing-android-embedded:4.3.0@aar")
implementation("com.github.yalantis:ucrop:2.2.10")
implementation("com.google.zxing:core:3.5.3")
implementation("org.apache.commons:commons-csv:1.9.0")
implementation("com.jaredrummler:colorpicker:1.1.0")
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,24 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data android:scheme="content"/>
<data android:host="*"/>
<data android:mimeType="image/*" />
<data android:mimeType="application/pdf" />
<data android:mimeType="application/vnd.apple.pkpass" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
<data android:mimeType="application/pdf" />
<data android:mimeType="application/vnd.apple.pkpass" />
</intent-filter>
</activity>
<activity
Expand Down
29 changes: 0 additions & 29 deletions app/src/main/java/protect/card_locker/BarcodeValues.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void onResume() {
private void onClickAction(int position) {
Cursor selected = DBHelper.getLoyaltyCardCursor(mDatabase, DBHelper.LoyaltyCardArchiveFilter.All);
selected.moveToPosition(position);
LoyaltyCard loyaltyCard = LoyaltyCard.fromCursor(selected);
LoyaltyCard loyaltyCard = LoyaltyCard.fromCursor(CardShortcutConfigure.this, 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,7 +42,7 @@ public Flow.Publisher<Control> createPublisherForAllAvailable() {
Cursor loyaltyCardCursor = DBHelper.getLoyaltyCardCursor(mDatabase, DBHelper.LoyaltyCardArchiveFilter.Unarchived);
return subscriber -> {
while (loyaltyCardCursor.moveToNext()) {
LoyaltyCard card = LoyaltyCard.fromCursor(loyaltyCardCursor);
LoyaltyCard card = LoyaltyCard.fromCursor(this, loyaltyCardCursor);
Intent openIntent = new Intent(this, LoyaltyCardViewActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(LoyaltyCardViewActivity.BUNDLE_ID, card.id);
Expand All @@ -69,7 +69,7 @@ public Flow.Publisher<Control> createPublisherFor(@NonNull List<String> controlI
for (String controlId : controlIds) {
Control control;
Integer cardId = this.controlIdToCardId(controlId);
LoyaltyCard card = DBHelper.getLoyaltyCard(mDatabase, cardId);
LoyaltyCard card = DBHelper.getLoyaltyCard(this, mDatabase, cardId);
if (card != null) {
Intent openIntent = new Intent(this, LoyaltyCardViewActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand Down Expand Up @@ -99,7 +99,7 @@ public Flow.Publisher<Control> createPublisherFor(@NonNull List<String> controlI
}

private Bitmap getIcon(Context context, LoyaltyCard loyaltyCard) {
Bitmap cardIcon = Utils.retrieveCardImage(context, loyaltyCard.id, ImageLocationType.icon);
Bitmap cardIcon = loyaltyCard.getImageThumbnail(context);

if (cardIcon != null) {
return cardIcon;
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/protect/card_locker/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ 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.fromCursor(cardCursor);
LoyaltyCard card = LoyaltyCard.fromCursor(context, cardCursor);
for (ImageLocationType imageLocationType : ImageLocationType.values()) {
String name = Utils.getCardImageFileName(card.id, imageLocationType);
if (Utils.retrieveCardImageAsFile(context, name).exists()) {
if (card.getImageForImageLocationType(context, imageLocationType) != null) {
files.add(name);
}
}
Expand Down Expand Up @@ -535,14 +535,14 @@ public static boolean updateLoyaltyCardBalance(SQLiteDatabase database, final in
return (rowsUpdated == 1);
}

public static LoyaltyCard getLoyaltyCard(SQLiteDatabase database, final int id) {
public static LoyaltyCard getLoyaltyCard(Context context, SQLiteDatabase database, final int id) {
Cursor data = database.query(LoyaltyCardDbIds.TABLE, null, whereAttrs(LoyaltyCardDbIds.ID), withArgs(id), null, null, null);

LoyaltyCard card = null;

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

data.close();
Expand Down
24 changes: 23 additions & 1 deletion app/src/main/java/protect/card_locker/ImportURIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,29 @@ public LoyaltyCard parse(Uri uri) throws InvalidObjectException {
headerColor = Integer.parseInt(unparsedHeaderColor);
}

return new LoyaltyCard(-1, store, note, validFrom, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, 0, Utils.getUnixTime(), 100, 0);
return new LoyaltyCard(
-1,
store,
note,
validFrom,
expiry,
balance,
balanceType,
cardId,
barcodeId,
barcodeType,
headerColor,
0,
Utils.getUnixTime(),
100,
0,
null,
null,
null,
null,
null,
null
);
} catch (NumberFormatException | UnsupportedEncodingException | ArrayIndexOutOfBoundsException ex) {
throw new InvalidObjectException("Not a valid import URI");
}
Expand Down
Loading

0 comments on commit f8a8a84

Please sign in to comment.