Skip to content

Commit 8d2fcd8

Browse files
committed
added support for edeka product codes
1 parent 940be49 commit 8d2fcd8

9 files changed

Lines changed: 78 additions & 17 deletions

File tree

core/src/androidTest/java/io/snabble/sdk/EncodedCodesGeneratorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void testSplitAgeRestrictedProductsInMultipleCodes() throws IOException,
142142
ArrayList<String> codes = generator.generate();
143143
Assert.assertEquals(3, codes.size());
144144
Assert.assertEquals("+4008400301020;4008400301020;####-", codes.get(0));
145-
Assert.assertEquals("+4008400301020;4008287051124;****-", codes.get(1));
145+
Assert.assertEquals("+4008400301020;4008287051124;####-", codes.get(1));
146146
Assert.assertEquals("+4008287051124;4008287051124;%%%%-", codes.get(2));
147147
}
148148

@@ -173,10 +173,10 @@ public void testSplitAgeRestrictedProductsInMultipleCodes2() throws IOException,
173173
ArrayList<String> codes = generator.generate();
174174
Assert.assertEquals(6, codes.size());
175175
Assert.assertEquals("+4008400301020;####-", codes.get(0));
176-
Assert.assertEquals("+4008400301020;****-", codes.get(1));
177-
Assert.assertEquals("+4008400301020;****-", codes.get(2));
178-
Assert.assertEquals("+4008287051124;****-", codes.get(3));
179-
Assert.assertEquals("+4008287051124;****-", codes.get(4));
176+
Assert.assertEquals("+4008400301020;####-", codes.get(1));
177+
Assert.assertEquals("+4008400301020;####-", codes.get(2));
178+
Assert.assertEquals("+4008287051124;####-", codes.get(3));
179+
Assert.assertEquals("+4008287051124;####-", codes.get(4));
180180
Assert.assertEquals("+4008287051124;%%%%-", codes.get(5));
181181
}
182182

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public void insert(Product product, int index, int quantity, ScannableCode scann
107107
Entry e = getEntryBySku(product.getSku());
108108

109109
if (e == null || scannedCode.hasUnitData()
110+
|| scannedCode.hasPriceData()
110111
|| product.getType() == Product.Type.UserWeighed
111112
|| product.getType() == Product.Type.PreWeighed) {
112113
if(quantity > 0) {

core/src/main/java/io/snabble/sdk/codes/EAN13.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private boolean containsGermanPrintPrefix() {
7474
}
7575

7676
@Override
77-
public String getLookupCode() {
77+
public String getMaskedCode() {
7878
return lookupCode;
7979
}
8080

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.snabble.sdk.codes;
2+
3+
import io.snabble.sdk.Project;
4+
5+
public class EdekaProductCode extends ScannableCode {
6+
private String lookupCode;
7+
private int price;
8+
9+
EdekaProductCode(String code) {
10+
super(code);
11+
12+
lookupCode = code.substring(2, 15);
13+
price = Integer.parseInt(code.substring(15, 21));
14+
}
15+
16+
@Override
17+
public String getLookupCode() {
18+
return lookupCode;
19+
}
20+
21+
@Override
22+
public int getEmbeddedData() {
23+
return price;
24+
}
25+
26+
@Override
27+
public boolean hasPriceData() {
28+
return true;
29+
}
30+
31+
@Override
32+
public boolean hasEmbeddedData() {
33+
return true;
34+
}
35+
36+
@Override
37+
public boolean isEmbeddedDataOk() {
38+
return true;
39+
}
40+
41+
public static boolean isEdekaProductCode(Project project, String code) {
42+
return project.getId().contains("edeka") && code.length() == 22 && code.startsWith("97");
43+
}
44+
}

core/src/main/java/io/snabble/sdk/codes/ScannableCode.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public String getCode() {
1616
}
1717

1818
public String getLookupCode() {
19+
return code;
20+
}
21+
22+
public String getMaskedCode() {
1923
return "";
2024
}
2125

@@ -48,6 +52,8 @@ public static ScannableCode parse(Project project, String code) {
4852
return new EAN13(code, project);
4953
} else if (EAN14.isEan14(code)) {
5054
return new EAN14(code);
55+
} else if (EdekaProductCode.isEdekaProductCode(project, code)) {
56+
return new EdekaProductCode(code);
5157
} else {
5258
return new ScannableCode(code);
5359
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,8 @@ private void finishCode() {
111111
codeCount = 0;
112112
}
113113

114-
private boolean needsToAddNextCodeWithCheck() {
115-
return hasAgeRestrictedCode && encodedCodes.size() == 0 && options.nextCodeWithCheck.length() > 0;
116-
}
117-
118114
private void addScannableCode(String scannableCode, boolean isAgeRestricted) {
119-
String nextCode = needsToAddNextCodeWithCheck() ? options.nextCodeWithCheck : options.nextCode;
115+
String nextCode = hasAgeRestrictedCode ? options.nextCodeWithCheck : options.nextCode;
120116

121117
if (isAgeRestricted
122118
&& hasAgeRestrictedCode

ui/src/main/java/io/snabble/sdk/ui/cart/ShoppingCartView.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,13 @@ public void bindTo(final int position) {
449449

450450
controlsUserWeighed.setVisibility(View.GONE);
451451
} else {
452-
controlsDefault.setVisibility(View.VISIBLE);
453-
controlsUserWeighed.setVisibility(View.INVISIBLE);
452+
if(embeddedPrice != null) {
453+
controlsDefault.setVisibility(View.GONE);
454+
controlsUserWeighed.setVisibility(View.GONE);
455+
} else {
456+
controlsDefault.setVisibility(View.VISIBLE);
457+
controlsUserWeighed.setVisibility(View.INVISIBLE);
458+
}
454459
}
455460
break;
456461
case PreWeighed:

ui/src/main/java/io/snabble/sdk/ui/scanner/ProductConfirmationDialog.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ public void onClick(View v) {
217217
}
218218
});
219219

220-
if (cartQuantity > 0 && product.getType() == Product.Type.Article && !scannedCode.hasUnitData()) {
220+
if (cartQuantity > 0
221+
&& product.getType() == Product.Type.Article
222+
&& !scannedCode.hasUnitData()
223+
&& !scannedCode.hasPriceData()) {
221224
addToCart.setText(R.string.Snabble_Scanner_updateCart);
222225
} else {
223226
addToCart.setText(R.string.Snabble_Scanner_addToCart);
@@ -282,6 +285,12 @@ private void updatePrice() {
282285
price.setText(singlePrice);
283286
}
284287

288+
// TODO TEST
289+
if(scannedCode.hasPriceData()){
290+
int embeddedPrice = scannedCode.getEmbeddedData();
291+
price.setText(priceFormatter.format(embeddedPrice));
292+
}
293+
285294
Product depositProduct = product.getDepositProduct();
286295
if(depositProduct != null){
287296
String depositPriceText = priceFormatter.format(depositProduct.getPriceForQuantity(getQuantity(),

ui/src/main/java/io/snabble/sdk/ui/scanner/SelfScanningView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ public void lookupAndShowProduct(final ScannableCode scannedCode) {
189189

190190
progressDialog.showAfterDelay(300);
191191

192-
if(scannedCode.hasEmbeddedData()){
193-
productDatabase.findByWeighItemIdOnline(scannedCode.getLookupCode(), new OnProductAvailableListener() {
192+
if(scannedCode.hasEmbeddedData() && scannedCode.getMaskedCode().length() > 0){
193+
productDatabase.findByWeighItemIdOnline(scannedCode.getMaskedCode(), new OnProductAvailableListener() {
194194
@Override
195195
public void onProductAvailable(Product product, boolean wasOnlineProduct) {
196196
handleProductAvailable(product, wasOnlineProduct, scannedCode);
@@ -207,7 +207,7 @@ public void onError() {
207207
}
208208
});
209209
} else {
210-
productDatabase.findByCodeOnline(scannedCode.getCode(), new OnProductAvailableListener() {
210+
productDatabase.findByCodeOnline(scannedCode.getLookupCode(), new OnProductAvailableListener() {
211211
@Override
212212
public void onProductAvailable(Product product, boolean wasOnlineProduct) {
213213
handleProductAvailable(product, wasOnlineProduct, scannedCode);

0 commit comments

Comments
 (0)