Skip to content

Commit 14acf4f

Browse files
committed
now inserting new shopping cart item at the top, restored shopping cart button animations, fixed undo for zero amount products
1 parent e742f3c commit 14acf4f

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void setQuantity(Product product, int quantity, ScannableCode scannedCode
154154

155155
setEntryQuantity(e, quantity);
156156
} else {
157-
add(product, quantity, scannedCode);
157+
insert(product, 0, quantity, scannedCode);
158158
}
159159
}
160160
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void onItemAdded(ShoppingCart list, Product product) {
7070

7171
@Override
7272
public void onQuantityChanged(ShoppingCart list, Product product) {
73-
onCartUpdated();
73+
7474
}
7575

7676
@Override
@@ -214,18 +214,20 @@ public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
214214
final Product product = cart.getProduct(pos);
215215
final String scannedCode = cart.getScannedCode(pos);
216216
final int quantity = cart.getQuantity(pos);
217+
final boolean isZeroAmountProduct = cart.isZeroAmountProduct(pos);
217218

218219
cart.removeAll(pos);
219220
Telemetry.event(Telemetry.Event.DeletedFromCart, product);
220221
recyclerView.getAdapter().notifyItemRemoved(pos);
222+
update();
221223

222224
snackbar = UIUtils.snackbar(coordinatorLayout,
223225
R.string.Snabble_Shoppingcart_articleRemoved, UIUtils.SNACKBAR_LENGTH_VERY_LONG);
224226
snackbar.setAction(R.string.Snabble_undo, new OnClickListener() {
225227
@Override
226228
public void onClick(View v) {
227229
ScannableCode parsedCode = ScannableCode.parse(SnabbleUI.getProject(), scannedCode);
228-
cart.insert(product, pos, quantity, parsedCode);
230+
cart.insert(product, pos, quantity, parsedCode, isZeroAmountProduct);
229231
recyclerView.getAdapter().notifyDataSetChanged();
230232
Telemetry.event(Telemetry.Event.UndoDeleteFromCart, product);
231233
}
@@ -276,12 +278,16 @@ private void updatePayText() {
276278
}
277279

278280
private void onCartUpdated() {
281+
update();
282+
283+
recyclerViewAdapter.notifyDataSetChanged();
284+
}
285+
286+
private void update() {
279287
updatePayText();
280288
updateEmptyState();
281289
scanForImages();
282290

283-
recyclerViewAdapter.notifyDataSetChanged();
284-
285291
if (snackbar != null) {
286292
snackbar.dismiss();
287293
}
@@ -473,6 +479,7 @@ public void onClick(View v) {
473479
}
474480

475481
recyclerViewAdapter.notifyItemChanged(getAdapterPosition());
482+
update();
476483
}
477484
});
478485

@@ -495,6 +502,7 @@ public void onClick(View v) {
495502
public void onClick(DialogInterface dialog, int which) {
496503
cart.removeAll(getAdapterPosition());
497504
recyclerViewAdapter.notifyItemChanged(getAdapterPosition());
505+
update();
498506
Telemetry.event(Telemetry.Event.DeletedFromCart, product);
499507
}
500508
})
@@ -511,6 +519,7 @@ public void onClick(DialogInterface dialog, int which) {
511519
}
512520

513521
recyclerViewAdapter.notifyItemChanged(getAdapterPosition());
522+
update();
514523
}
515524
}
516525
});
@@ -521,6 +530,7 @@ public void click() {
521530
int pos = getAdapterPosition();
522531
cart.setQuantity(pos, getQuantityEditValue());
523532
recyclerViewAdapter.notifyItemChanged(pos);
533+
update();
524534

525535
hideInput();
526536
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,13 @@ private void addToCart() {
323323
shake();
324324
return;
325325
} else {
326-
shoppingCart.add(product, 1, scannedCode, isZeroAmountProduct);
326+
shoppingCart.insert(product, 0, 1, scannedCode, isZeroAmountProduct);
327327
}
328328
} else if (product.getType() == Product.Type.Article) {
329329
shoppingCart.setQuantity(product, q, scannedCode);
330330
} else if(product.getType() == Product.Type.UserWeighed){
331331
if(q > 0) {
332-
shoppingCart.add(product, q, scannedCode);
332+
shoppingCart.insert(product, 0, q, scannedCode);
333333
} else {
334334
shake();
335335
return;

0 commit comments

Comments
 (0)