Skip to content

Commit 8b5fff0

Browse files
committed
price updates & always show local price
1 parent f6141cc commit 8b5fff0

File tree

6 files changed

+64
-14
lines changed

6 files changed

+64
-14
lines changed

CHANGELOG.md

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

4+
## [0.11.2]
5+
6+
### Fixed
7+
- Prices are now updated when updating the ProductDatabase
8+
- Always show the locally calculated price for consistency
9+
410
## [0.11.1]
511

612
### Fixed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void success(CheckoutApi.SignedCheckoutInfo checkoutInfo,
202202
int onlinePrice,
203203
PaymentMethod[] availablePaymentMethods) {
204204
signedCheckoutInfo = checkoutInfo;
205-
priceToPay = onlinePrice;
205+
priceToPay = shoppingCart.getTotalPrice();
206206

207207
if (availablePaymentMethods.length == 1 && !availablePaymentMethods[0].isRequiringCredentials()) {
208208
pay(availablePaymentMethods[0], null, true);
@@ -394,7 +394,7 @@ public void run() {
394394
public void success(CheckoutApi.SignedCheckoutInfo signedCheckoutInfo,
395395
int onlinePrice,
396396
PaymentMethod[] availablePaymentMethods) {
397-
priceToPay = onlinePrice;
397+
priceToPay = shoppingCart.getTotalPrice();
398398

399399
checkoutApi.createPaymentProcess(signedCheckoutInfo, pm, null,
400400
new CheckoutApi.PaymentProcessResult() {

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -550,29 +550,30 @@ public void update(final UpdateCallback callback, boolean deltaUpdateOnly) {
550550
productDatabaseDownloader.update(new Downloader.Callback() {
551551
@Override
552552
protected void onDataLoaded(boolean wasStillValid) {
553-
updateLastUpdateTimestamp(System.currentTimeMillis());
554-
notifyOnDatabaseUpdated();
555-
556-
if (callback != null) {
557-
callback.success();
558-
}
553+
update();
559554
}
560555

561556
@Override
562557
protected void onError() {
563558
if (productDatabaseDownloader.wasSameRevision()) {
564-
updateLastUpdateTimestamp(System.currentTimeMillis());
565-
notifyOnDatabaseUpdated();
566-
567-
if (callback != null) {
568-
callback.success();
569-
}
559+
update();
570560
} else {
571561
if (callback != null) {
572562
callback.error();
573563
}
574564
}
575565
}
566+
567+
private void update() {
568+
updateLastUpdateTimestamp(System.currentTimeMillis());
569+
notifyOnDatabaseUpdated();
570+
571+
if (callback != null) {
572+
callback.success();
573+
}
574+
575+
project.getShoppingCart().update();
576+
}
576577
}, deltaUpdateOnly);
577578
}
578579

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ public void invalidate() {
277277
clear();
278278
}
279279

280+
public void update() {
281+
ProductDatabase productDatabase = project.getProductDatabase();
282+
283+
if (productDatabase.isUpToDate()) {
284+
for (Entry e : items) {
285+
Product product = productDatabase.findByCode(e.scannedCode);
286+
287+
if (product != null) {
288+
e.product = product;
289+
}
290+
}
291+
292+
notifyUpdate(this);
293+
}
294+
}
295+
280296
public void checkForTimeout() {
281297
long currentTime = System.currentTimeMillis();
282298

@@ -504,11 +520,18 @@ public interface ShoppingCartListener {
504520
void onItemMoved(ShoppingCart list, int fromIndex, int toIndex);
505521

506522
void onItemRemoved(ShoppingCart list, Product product);
523+
524+
void onUpdate(ShoppingCart list);
507525
}
508526

509527
public static abstract class SimpleShoppingCartListener implements ShoppingCartListener {
510528
public abstract void onChanged(ShoppingCart list);
511529

530+
@Override
531+
public void onUpdate(ShoppingCart list) {
532+
onChanged(list);
533+
}
534+
512535
@Override
513536
public void onItemAdded(ShoppingCart list, Product product) {
514537
onChanged(list);
@@ -587,6 +610,16 @@ public void run() {
587610
});
588611
}
589612

613+
private void notifyUpdate(final ShoppingCart list) {
614+
handler.post(new Runnable() {
615+
@Override
616+
public void run() {
617+
for (ShoppingCartListener listener : listeners) {
618+
listener.onUpdate(list);
619+
}
620+
}
621+
});
622+
}
590623
/**
591624
* Notifies all {@link #listeners} that the shopping list was cleared of all entries.
592625
*

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public void onItemMoved(ShoppingCart list, int fromIndex, int toIndex) {
8888
public void onItemRemoved(ShoppingCart list, Product product) {
8989

9090
}
91+
92+
@Override
93+
public void onUpdate(ShoppingCart list) {
94+
onCartUpdated();
95+
}
9196
};
9297

9398
public ShoppingCartView(Context context) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ public void onItemMoved(ShoppingCart list, int fromIndex, int toIndex) {
411411
public void onItemRemoved(ShoppingCart list, Product product) {
412412

413413
}
414+
415+
@Override
416+
public void onUpdate(ShoppingCart list) {
417+
418+
}
414419
};
415420

416421
private Application.ActivityLifecycleCallbacks activityLifecycleCallbacks =

0 commit comments

Comments
 (0)