Skip to content

Commit 49b6b78

Browse files
committed
Lookup weighItemId product locally first before lookup up product online
1 parent c93f723 commit 49b6b78

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,33 @@ public void lookupAndShowProduct(final String scannedCode) {
153153
progressDialog.showAfterDelay(300);
154154
barcodeScanner.pause();
155155

156-
productDatabase.findByCodeOnline(scannedCode, new OnProductAvailableListener() {
157-
@Override
158-
public void onProductAvailable(Product product, boolean wasOnlineProduct) {
159-
handleProductAvailable(product, wasOnlineProduct, scannedCode);
160-
}
156+
Product product = productDatabase.findByCode(scannedCode);
157+
if(product != null){
158+
handleProductAvailable(product, false, scannedCode);
159+
} else {
160+
String weighItemId = Ean13Utils.toWeighItemId(scannedCode);
161+
product = productDatabase.findByWeighItemId(weighItemId);
162+
if(product != null){
163+
handleProductAvailable(product, false, scannedCode);
164+
} else {
165+
productDatabase.findByCodeOnline(scannedCode, new OnProductAvailableListener() {
166+
@Override
167+
public void onProductAvailable(Product product, boolean wasOnlineProduct) {
168+
handleProductAvailable(product, wasOnlineProduct, scannedCode);
169+
}
161170

162-
@Override
163-
public void onProductNotFound() {
164-
searchForWeighItemId(scannedCode);
165-
}
171+
@Override
172+
public void onProductNotFound() {
173+
searchForWeighItemId(scannedCode);
174+
}
166175

167-
@Override
168-
public void onError() {
169-
handleProductError();
176+
@Override
177+
public void onError() {
178+
handleProductError();
179+
}
180+
});
170181
}
171-
});
182+
}
172183
}
173184

174185
@SuppressLint("MissingPermission")

0 commit comments

Comments
 (0)