Skip to content

Commit e38f435

Browse files
committed
added support for qrCodeOffline metadata
1 parent 88b70cd commit e38f435

File tree

8 files changed

+82
-69
lines changed

8 files changed

+82
-69
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.14.14]
5+
6+
### Added
7+
- Support for new qrCodeOffline metadata
8+
9+
### Changed
10+
- Removed support for old encodedCodes payment methods
11+
412
## [0.14.13]
513

614
### Added

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ allprojects {
2323
}
2424

2525
project.ext {
26-
sdkVersion='0.14.13'
26+
sdkVersion='0.14.14'
2727
versionCode=1
2828

2929
compileSdkVersion=28

core/src/main/java/io/snabble/sdk/PaymentMethod.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
public enum PaymentMethod {
66
@SerializedName("qrCodePOS")
77
QRCODE_POS(false, false),
8-
@SerializedName("encodedCodes")
9-
ENCODED_CODES(true, false),
10-
@SerializedName("encodedCodesCSV")
11-
ENCODED_CODES_CSV(true, false),
12-
@SerializedName("encodedCodesIKEA")
13-
ENCODED_CODES_IKEA(true, false),
8+
@SerializedName("qrCodeOffline")
9+
QRCODE_OFFLINE(true, false),
1410
@SerializedName("deDirectDebit")
1511
DE_DIRECT_DEBIT(false, true);
1612

core/src/main/java/io/snabble/sdk/Project.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,11 @@ void parse(JsonObject jsonObject) {
130130

131131
isCheckoutAvailable = JsonUtils.getBooleanOpt(jsonObject, "enableCheckout", true);
132132

133-
if (jsonObject.has("encodedCodes")) {
134-
JsonElement encodedCodes = jsonObject.get("encodedCodes");
133+
if (jsonObject.has("qrCodeOffline")) {
134+
JsonElement encodedCodes = jsonObject.get("qrCodeOffline");
135135
if (!encodedCodes.isJsonNull()) {
136136
JsonObject object = encodedCodes.getAsJsonObject();
137-
138-
encodedCodesOptions = new EncodedCodesOptions.Builder(this)
139-
.prefix(JsonUtils.getStringOpt(object, "prefix", ""))
140-
.separator(JsonUtils.getStringOpt(object, "separator", "\n"))
141-
.suffix(JsonUtils.getStringOpt(object, "suffix", ""))
142-
.maxCodes(JsonUtils.getIntOpt(object, "maxCodes", 100))
143-
.finalCode(JsonUtils.getStringOpt(object, "finalCode", ""))
144-
.nextCode(JsonUtils.getStringOpt(object, "nextCode", ""))
145-
.nextCodeWithCheck(JsonUtils.getStringOpt(object, "nextCodeWithCheck", ""))
146-
.maxSizeMm(JsonUtils.getIntOpt(object, "maxSizeMM", -1))
147-
.maxChars(JsonUtils.getIntOpt(object, "maxChars", EncodedCodesOptions.DEFAULT_MAX_CHARS))
148-
.build();
137+
encodedCodesOptions = EncodedCodesOptions.fromJsonObject(this, object);
149138
}
150139
}
151140

core/src/main/java/io/snabble/sdk/encodedcodes/EncodedCodesOptions.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import android.util.SparseArray;
44

5+
import com.google.gson.JsonObject;
6+
import com.google.gson.annotations.SerializedName;
7+
58
import io.snabble.sdk.Project;
9+
import io.snabble.sdk.utils.JsonUtils;
610

711
public class EncodedCodesOptions {
812
public static final int DEFAULT_MAX_CHARS = 2953;
@@ -125,4 +129,66 @@ public EncodedCodesOptions build() {
125129
finalCode, nextCode, nextCodeWithCheck, repeatCodes, countSeparator, maxSizeMm, project);
126130
}
127131
}
132+
133+
public static EncodedCodesOptions fromJsonObject(Project project, JsonObject object) {
134+
String format = JsonUtils.getStringOpt(object, "format", "simple");
135+
switch (format) {
136+
case "csv":
137+
return new EncodedCodesOptions.Builder(project)
138+
.prefix("snabble;{qrCodeCount};{count}\n")
139+
.separator("\n")
140+
.suffix("")
141+
.repeatCodes(false)
142+
.countSeparator(";")
143+
.maxCodes(100)
144+
.build();
145+
case "csv_globus":
146+
return new EncodedCodesOptions.Builder(project)
147+
.prefix("snabble;\n")
148+
.separator("\n")
149+
.suffix("")
150+
.repeatCodes(false)
151+
.countSeparator(";")
152+
.maxCodes(100)
153+
.build();
154+
case "ikea":
155+
EncodedCodesOptions options = project.getEncodedCodesOptions();
156+
int maxCodes = 45;
157+
int maxChars = EncodedCodesOptions.DEFAULT_MAX_CHARS;
158+
if (options != null) {
159+
maxCodes = options.maxCodes;
160+
maxChars = options.maxChars;
161+
}
162+
163+
String prefix = "9100003\u001d100{qrCodeCount}\u001d240";
164+
165+
String prefixWithCustomerCard = "9100003\u001d100{qrCodeCount}";
166+
if (project.getCustomerCardId() != null) {
167+
prefixWithCustomerCard += "\u001d92" + project.getCustomerCardId();
168+
}
169+
prefixWithCustomerCard += "\u001d240";
170+
171+
return new EncodedCodesOptions.Builder(project)
172+
.prefix(prefix)
173+
.prefix(0, prefixWithCustomerCard)
174+
.separator("\u001d240")
175+
.suffix("")
176+
.maxCodes(maxCodes)
177+
.maxChars(maxChars)
178+
.build();
179+
case "simple":
180+
default:
181+
return new EncodedCodesOptions.Builder(project)
182+
.prefix(JsonUtils.getStringOpt(object, "prefix", ""))
183+
.separator(JsonUtils.getStringOpt(object, "separator", "\n"))
184+
.suffix(JsonUtils.getStringOpt(object, "suffix", ""))
185+
.maxCodes(JsonUtils.getIntOpt(object, "maxCodes", 100))
186+
.finalCode(JsonUtils.getStringOpt(object, "finalCode", ""))
187+
.nextCode(JsonUtils.getStringOpt(object, "nextCode", ""))
188+
.nextCodeWithCheck(JsonUtils.getStringOpt(object, "nextCodeWithCheck", ""))
189+
.maxSizeMm(JsonUtils.getIntOpt(object, "maxSizeMM", -1))
190+
.maxChars(JsonUtils.getIntOpt(object, "maxChars", EncodedCodesOptions.DEFAULT_MAX_CHARS))
191+
.build();
192+
}
193+
}
128194
}

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutEncodedCodesView.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ public CheckoutEncodedCodesView(Context context) {
5353
inflateView(project.getEncodedCodesOptions());
5454
}
5555

56-
public CheckoutEncodedCodesView(Context context, EncodedCodesOptions options) {
57-
super(context);
58-
59-
project = SnabbleUI.getProject();
60-
inflateView(options);
61-
}
62-
6356
private void inflateView(EncodedCodesOptions options) {
6457
inflate(getContext(), R.layout.snabble_view_checkout_encodedcodes, this);
6558

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutView.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -142,47 +142,9 @@ private void displayPaymentView() {
142142
checkoutQRCodePOSView.setQRCodeText(checkout.getQRCodePOSContent());
143143
displayView(checkoutQRCodePOSView);
144144
break;
145-
case ENCODED_CODES:
145+
case QRCODE_OFFLINE:
146146
displayView(new CheckoutEncodedCodesView(getContext()));
147147
break;
148-
case ENCODED_CODES_CSV:
149-
displayView(new CheckoutEncodedCodesView(getContext(),
150-
new EncodedCodesOptions.Builder(project)
151-
.prefix("snabble;\n")
152-
.separator("\n")
153-
.suffix("")
154-
.repeatCodes(false)
155-
.countSeparator(";")
156-
.maxCodes(100)
157-
.build()));
158-
break;
159-
case ENCODED_CODES_IKEA:
160-
EncodedCodesOptions options = project.getEncodedCodesOptions();
161-
int maxCodes = 45;
162-
int maxChars = EncodedCodesOptions.DEFAULT_MAX_CHARS;
163-
if (options != null) {
164-
maxCodes = options.maxCodes;
165-
maxChars = options.maxChars;
166-
}
167-
168-
String prefix = "9100003\u001d100{qrCodeCount}\u001d240";
169-
170-
String prefixWithCustomerCard = "9100003\u001d100{qrCodeCount}";
171-
if (project.getCustomerCardId() != null) {
172-
prefixWithCustomerCard += "\u001d92" + project.getCustomerCardId();
173-
}
174-
prefixWithCustomerCard += "\u001d240";
175-
176-
displayView(new CheckoutEncodedCodesView(getContext(),
177-
new EncodedCodesOptions.Builder(project)
178-
.prefix(prefix)
179-
.prefix(0, prefixWithCustomerCard)
180-
.separator("\u001d240")
181-
.suffix("")
182-
.maxCodes(maxCodes)
183-
.maxChars(maxChars)
184-
.build()));
185-
break;
186148
}
187149
}
188150

ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentMethodView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ class PaymentMethodView extends FrameLayout implements PaymentCredentialsStore.C
5454
static {
5555
icons.put(PaymentMethod.DE_DIRECT_DEBIT, R.drawable.snabble_ic_pm_sepa);
5656
icons.put(PaymentMethod.QRCODE_POS, R.drawable.snabble_ic_pm_checkstand);
57-
icons.put(PaymentMethod.ENCODED_CODES, R.drawable.snabble_ic_pm_checkstand);
58-
icons.put(PaymentMethod.ENCODED_CODES_CSV, R.drawable.snabble_ic_pm_checkstand);
57+
icons.put(PaymentMethod.QRCODE_OFFLINE, R.drawable.snabble_ic_pm_checkstand);
5958
}
6059

6160
private Checkout checkout;

0 commit comments

Comments
 (0)