Skip to content

Commit 87338bd

Browse files
committed
showing applied manual discount, manual discount fixes, pull to refresh fixed
1 parent 785c911 commit 87338bd

File tree

7 files changed

+48
-17
lines changed

7 files changed

+48
-17
lines changed

CHANGELOG.md

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

4+
## [0.37.12]
5+
6+
### Added
7+
- Added indicator if an manual discount was applied or not
8+
9+
### Fixed
10+
- Fixed pull to refresh in ShoppingCartView
11+
- Fixed selecting manual discounts resetting amount, even when no item is already in cart
12+
- Products with manual discounts are now editable
13+
414
## [0.37.11]
515

616
### Fixed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ allprojects {
3131
}
3232

3333
project.ext {
34-
sdkVersion='0.37.11'
34+
sdkVersion='0.37.12'
3535
versionCode=1
3636

3737
compileSdkVersion=30

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public static class LineItem {
107107
int totalPrice;
108108
LineItemType type;
109109
List<PriceModifier> priceModifiers;
110+
boolean redeemed;
110111
}
111112

112113
public static class PriceModifier {
@@ -123,6 +124,8 @@ public enum LineItemType {
123124
DISCOUNT,
124125
@SerializedName("giveaway")
125126
GIVEAWAY,
127+
@SerializedName("coupon")
128+
COUPON,
126129
}
127130

128131
public static class ExitToken {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ public void invalidateOnlinePrices() {
316316
items.remove(i);
317317
} else {
318318
item.lineItem = null;
319+
item.isManualCouponApplied = false;
319320
}
320321
}
321322

@@ -327,7 +328,7 @@ public void updatePrices(boolean debounce) {
327328
if(debounce) {
328329
updater.dispatchUpdate();
329330
} else {
330-
updater.update();
331+
updater.update(true);
331332
}
332333
}
333334

@@ -534,6 +535,7 @@ public static class Item {
534535
private String id;
535536
private boolean isUsingSpecifiedQuantity;
536537
private transient ShoppingCart cart;
538+
private boolean isManualCouponApplied;
537539
private Coupon coupon;
538540

539541
protected Item() {
@@ -672,16 +674,16 @@ public ItemType getType() {
672674
return null;
673675
}
674676

675-
public boolean isManualCouponApplied() {
676-
if (lineItem != null) {
677-
return lineItem.priceModifiers.size() > 0; // TODO that is not correct
678-
}
677+
public void setManualCouponApplied(boolean manualCouponApplied) {
678+
isManualCouponApplied = manualCouponApplied;
679+
}
679680

680-
return false;
681+
public boolean isManualCouponApplied() {
682+
return isManualCouponApplied;
681683
}
682684

683685
public boolean isEditable() {
684-
if (coupon != null) {
686+
if (coupon != null && coupon.getType() != CouponType.MANUAL) {
685687
return false;
686688
}
687689

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ class ShoppingCartUpdater {
3939
private Runnable updatePriceRunnable = new Runnable() {
4040
@Override
4141
public void run() {
42-
update();
42+
update(false);
4343
}
4444
};
4545

4646
public CheckoutApi.PaymentMethodInfo[] getLastAvailablePaymentMethods() {
4747
return lastAvailablePaymentMethods;
4848
}
4949

50-
public void update() {
50+
public void update(boolean force) {
5151
Logger.d("Updating prices...");
5252

5353
if (cart.size() == 0) {
@@ -57,7 +57,7 @@ public void update() {
5757
}
5858

5959
final int modCount = cart.getModCount();
60-
if (modCount == successfulModCount) {
60+
if (modCount == successfulModCount && !force) {
6161
return;
6262
}
6363

@@ -199,6 +199,11 @@ private void commitCartUpdate(int modCount, CheckoutApi.SignedCheckoutInfo signe
199199
if (add) {
200200
cart.insert(cart.newItem(lineItem), cart.size(), false);
201201
}
202+
203+
if (lineItem.type == CheckoutApi.LineItemType.COUPON) {
204+
ShoppingCart.Item refersTo = cart.getByItemId(lineItem.refersTo);
205+
refersTo.setManualCouponApplied(lineItem.redeemed);
206+
}
202207
}
203208
}
204209
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public void updatePrice() {
296296
enterReducedPrice.setVisibility(isVisible ? View.VISIBLE : View.GONE);
297297
enterReducedPrice.setOnClickListener(v -> {
298298
FragmentActivity fragmentActivity = UIUtils.getHostFragmentActivity(context);
299-
new SelectReducedPriceDialogFragment(ProductConfirmationDialog.this, cartItem)
299+
new SelectReducedPriceDialogFragment(ProductConfirmationDialog.this, cartItem, shoppingCart)
300300
.show(fragmentActivity.getSupportFragmentManager(), null);
301301
});
302302

ui/src/main/java/io/snabble/sdk/ui/scanner/SelectReducedPriceDialogFragment.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import io.snabble.sdk.CouponType
1010
import io.snabble.sdk.ShoppingCart
1111
import io.snabble.sdk.ui.R
1212
import io.snabble.sdk.ui.SnabbleUI
13+
import java.security.PrivateKey
1314

1415
class SelectReducedPriceDialogFragment(
1516
private val productConfirmationDialog: ProductConfirmationDialog?,
16-
private val cartItem: ShoppingCart.Item?
17+
private val cartItem: ShoppingCart.Item?,
18+
private val shoppingCart: ShoppingCart?
1719
) : DialogFragment() {
1820
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
1921
if (productConfirmationDialog == null || cartItem == null) {
@@ -22,6 +24,9 @@ class SelectReducedPriceDialogFragment(
2224

2325
val project = SnabbleUI.getProject()
2426
val discounts = project.coupons.get(CouponType.MANUAL)
27+
val dialog = productConfirmationDialog
28+
val item = cartItem
29+
val cart = shoppingCart
2530

2631
val adapter = ArrayAdapter(requireContext(),
2732
R.layout.snabble_item_pricereduction_select,
@@ -33,12 +38,18 @@ class SelectReducedPriceDialogFragment(
3338
.setTitle(R.string.Snabble_addDiscount)
3439
.setAdapter(adapter) { _, which ->
3540
if (which == 0) {
36-
cartItem?.coupon = null
41+
item?.coupon = null
3742
} else {
38-
cartItem?.coupon = discounts[which - 1]
43+
item?.coupon = discounts[which - 1]
3944
}
40-
productConfirmationDialog?.updatePrice()
41-
productConfirmationDialog?.updateQuantityText()
45+
46+
val existingItem = cart?.getExistingMergeableProduct(item?.product)
47+
if (existingItem?.isMergeable == true) {
48+
dialog?.setQuantity(1)
49+
}
50+
51+
dialog?.updatePrice()
52+
dialog?.updateQuantityText()
4253
}
4354
.create()
4455
}

0 commit comments

Comments
 (0)