Skip to content

Commit a37cacd

Browse files
committed
add support for indexed prefixes in encoded codes
1 parent 0a2b72d commit a37cacd

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

CHANGELOG.md

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

4+
## [0.13.10]
5+
6+
### Fixed
7+
- Prevent repeating of customer card ids in encoded codes
8+
49
## [0.13.9]
510

611
### Fixed
@@ -14,13 +19,13 @@ All notable changes to this project will be documented in this file.
1419
## [0.13.7]
1520

1621
### Fixed
17-
- Handle missing customer card id in encodedCodesIKEA
22+
- Handle missing customer card id in encodedCodes
1823

1924
## [0.13.6]
2025

2126
### Added
2227
- Support for maximum size of encoded code qr code display
23-
- Support for encodedCodesIKEA payment method
28+
- Support for additional payment methods
2429

2530
### Fixed
2631
- Race condition when updating product database and shopping cart prices at the same time

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private void append(String code) {
258258
}
259259

260260
if (stringBuilder.length() == 0) {
261-
stringBuilder.append(options.prefix);
261+
stringBuilder.append(options.prefixMap.get(encodedCodes.size(), options.prefix));
262262
} else {
263263
stringBuilder.append(options.separator);
264264
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package io.snabble.sdk.encodedcodes;
22

3+
import android.util.SparseArray;
4+
35
import io.snabble.sdk.Project;
46

57
public class EncodedCodesOptions {
68
public final String prefix;
9+
public final SparseArray<String> prefixMap;
710
public final String separator;
811
public final String suffix;
912
public final int maxChars;
@@ -16,12 +19,13 @@ public class EncodedCodesOptions {
1619
public final int maxSizeMm;
1720
public final Project project;
1821

19-
private EncodedCodesOptions(String prefix, String separator, String suffix, int maxChars,
22+
private EncodedCodesOptions(String prefix, SparseArray<String> prefixMap, String separator, String suffix, int maxChars,
2023
int maxCodes, String finalCode, String nextCode,
2124
String nextCodeWithCheck, boolean repeatCodes, String countSeparator,
2225
int maxSizeMm,
2326
Project project) {
2427
this.prefix = prefix;
28+
this.prefixMap = prefixMap;
2529
this.separator = separator;
2630
this.suffix = suffix;
2731
this.maxChars = maxChars;
@@ -38,6 +42,7 @@ private EncodedCodesOptions(String prefix, String separator, String suffix, int
3842
public static class Builder {
3943
private Project project;
4044
private String prefix = "";
45+
private SparseArray<String> prefixMap = new SparseArray<>();
4146
private String separator = "\n";
4247
private String suffix = "";
4348
private int maxChars = 2953;
@@ -58,6 +63,11 @@ public Builder prefix(String prefix) {
5863
return this;
5964
}
6065

66+
public Builder prefix(int index, String prefix) {
67+
prefixMap.put(index, prefix);
68+
return this;
69+
}
70+
6171
public Builder separator(String separator) {
6272
this.separator = separator;
6373
return this;
@@ -109,7 +119,7 @@ public Builder maxSizeMm(int maxSizeMm) {
109119
}
110120

111121
public EncodedCodesOptions build() {
112-
return new EncodedCodesOptions(prefix, separator, suffix, maxChars, maxCodes,
122+
return new EncodedCodesOptions(prefix, prefixMap, separator, suffix, maxChars, maxCodes,
113123
finalCode, nextCode, nextCodeWithCheck, repeatCodes, countSeparator, maxSizeMm, project);
114124
}
115125
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,18 @@ private void displayPaymentView() {
138138
maxCodes = options.maxCodes;
139139
}
140140

141-
String prefix = "9100003\u001d100{qrCodeCount}";
141+
String prefix = "9100003\u001d100{qrCodeCount}\u001d240";
142+
143+
String prefixWithCustomerCard = "9100003\u001d100{qrCodeCount}";
142144
if (project.getCustomerCardId() != null) {
143-
prefix += "\u001d92" + project.getCustomerCardId();
145+
prefixWithCustomerCard += "\u001d92" + project.getCustomerCardId();
144146
}
145-
prefix += "\u001d240";
147+
prefixWithCustomerCard += "\u001d240";
146148

147149
displayView(new CheckoutEncodedCodesView(getContext(),
148150
new EncodedCodesOptions.Builder(project)
149151
.prefix(prefix)
152+
.prefix(0, prefixWithCustomerCard)
150153
.separator("\u001d240")
151154
.suffix("")
152155
.maxCodes(maxCodes)

0 commit comments

Comments
 (0)