Skip to content

Commit c7cd9d8

Browse files
committed
Added shop hints after adding the first item
1 parent 8797a7d commit c7cd9d8

File tree

5 files changed

+138
-1
lines changed

5 files changed

+138
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ allprojects {
2424
}
2525

2626
project.ext {
27-
sdkVersion='0.9.0-beta1'
27+
sdkVersion='0.9.0-beta2'
2828
versionCode=1
2929

3030
compileSdkVersion=28

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ private Entry(Product product, int quantity) {
4444
private String id;
4545
private long lastModificationTime;
4646
private List<Entry> items = new ArrayList<>();
47+
private int modCount = 0;
48+
private int addCount = 0;
4749
private transient List<ShoppingCartListener> listeners = new CopyOnWriteArrayList<>();
4850
private transient Handler handler = new Handler(Looper.getMainLooper());
4951
private transient Project project;
@@ -249,6 +251,7 @@ public int getQuantity(int index) {
249251
private void removeAll(Entry e) {
250252
if (e != null) {
251253
items.remove(e);
254+
modCount++;
252255
notifyItemRemoved(this, e.product);
253256
}
254257
}
@@ -259,6 +262,8 @@ public int size() {
259262

260263
public void clear() {
261264
items.clear();
265+
modCount = 0;
266+
addCount = 0;
262267
notifyCleared(this);
263268
}
264269

@@ -280,6 +285,7 @@ private void setEntryQuantity(Entry e, int newQuantity) {
280285
if (newQuantity > 0) {
281286
if (newQuantity != e.quantity) {
282287
e.quantity = Math.max(0, Math.min(MAX_QUANTITY, newQuantity));
288+
modCount++;
283289
notifyQuantityChanged(this, e.product);
284290
}
285291
} else {
@@ -293,6 +299,8 @@ private void addEntry(Entry e, int index) {
293299
setEntryQuantity(e, e.quantity + 1);
294300
} else {
295301
items.add(index, e);
302+
modCount++;
303+
addCount++;
296304
notifyItemAdded(this, e.product);
297305
}
298306
}
@@ -335,6 +343,7 @@ private void setScannedCodeForEntry(Entry entry, ScannableCode scannedCode){
335343
entry.amount = scannedCode.getEmbeddedData();
336344
}
337345

346+
modCount++;
338347
notifyQuantityChanged(this, entry.product);
339348
}
340349

@@ -365,6 +374,14 @@ private boolean contains(Entry e) {
365374
return items.contains(e);
366375
}
367376

377+
public int getAddCount() {
378+
return addCount;
379+
}
380+
381+
public int getModCount() {
382+
return modCount;
383+
}
384+
368385
/**
369386
* Swaps the position of two entries based on their index.
370387
* <p>
@@ -373,6 +390,7 @@ private boolean contains(Entry e) {
373390
public void swap(int fromIndex, int toIndex) {
374391
if (fromIndex >= 0 && fromIndex < items.size() && toIndex >= 0 && toIndex < items.size() && fromIndex != toIndex) {
375392
Collections.swap(items, fromIndex, toIndex);
393+
modCount++;
376394
notifyItemMoved(this, fromIndex, toIndex);
377395
}
378396
}

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.text.InputType;
1919
import android.util.AttributeSet;
2020
import android.view.KeyEvent;
21+
import android.view.LayoutInflater;
2122
import android.view.View;
2223
import android.widget.EditText;
2324
import android.widget.LinearLayout;
@@ -28,12 +29,15 @@
2829
import io.snabble.sdk.Product;
2930
import io.snabble.sdk.ProductDatabase;
3031
import io.snabble.sdk.Project;
32+
import io.snabble.sdk.Shop;
33+
import io.snabble.sdk.ShoppingCart;
3134
import io.snabble.sdk.codes.ScannableCode;
3235
import io.snabble.sdk.ui.R;
3336
import io.snabble.sdk.ui.SnabbleUI;
3437
import io.snabble.sdk.ui.SnabbleUICallback;
3538
import io.snabble.sdk.ui.telemetry.Telemetry;
3639
import io.snabble.sdk.ui.utils.DelayedProgressDialog;
40+
import io.snabble.sdk.ui.utils.OneShotClickListener;
3741
import io.snabble.sdk.ui.utils.UIUtils;
3842
import io.snabble.sdk.utils.SimpleActivityLifecycleCallbacks;
3943
import io.snabble.sdk.utils.Utils;
@@ -51,6 +55,7 @@ public class SelfScanningView extends CoordinatorLayout implements Checkout.OnCh
5155
private DelayedProgressDialog progressDialog;
5256
private long detectAfterTimeMs;
5357
private boolean ignoreNextDialog;
58+
private ShoppingCart shoppingCart;
5459

5560
public SelfScanningView(Context context) {
5661
super(context);
@@ -72,6 +77,8 @@ private void inflateView() {
7277

7378
Project project = SnabbleUI.getProject();
7479

80+
shoppingCart = project.getShoppingCart();
81+
7582
barcodeScanner = findViewById(R.id.barcode_scanner_view);
7683
noPermission = findViewById(R.id.no_permission);
7784

@@ -305,6 +312,43 @@ public void onClick(DialogInterface dialog, int which) {
305312
}
306313
}
307314

315+
public void showHints() {
316+
Project project = SnabbleUI.getProject();
317+
Shop currentShop = project.getCheckout().getShop();
318+
319+
if(currentShop != null) {
320+
Context context = getContext();
321+
322+
LayoutInflater inflater = LayoutInflater.from(context);
323+
View view = inflater.inflate(R.layout.dialog_hints, null, false);
324+
325+
TextView textView = view.findViewById(R.id.title);
326+
textView.setText(context.getString(R.string.Snabble_Hints_title, currentShop.getName()));
327+
328+
final AlertDialog alertDialog = new AlertDialog.Builder(context)
329+
.setView(view)
330+
.setPositiveButton(R.string.Snabble_OK, new DialogInterface.OnClickListener() {
331+
@Override
332+
public void onClick(DialogInterface dialog, int which) {
333+
dialog.dismiss();
334+
}
335+
})
336+
.setCancelable(true)
337+
.create();
338+
339+
alertDialog.setCanceledOnTouchOutside(true);
340+
341+
view.findViewById(R.id.close).setOnClickListener(new OneShotClickListener() {
342+
@Override
343+
public void click() {
344+
alertDialog.dismiss();
345+
}
346+
});
347+
348+
alertDialog.show();
349+
}
350+
}
351+
308352
public void resume() {
309353
resumeBarcodeScanner();
310354
}
@@ -395,6 +439,7 @@ public void registerListeners() {
395439
isRunning = true;
396440

397441
startBarcodeScanner();
442+
shoppingCart.addListener(shoppingCartListener);
398443
}
399444

400445
public void unregisterListeners() {
@@ -404,6 +449,7 @@ public void unregisterListeners() {
404449

405450
progressDialog.dismiss();
406451
productDialog.dismiss();
452+
shoppingCart.removeListener(shoppingCartListener);
407453
}
408454

409455
@Override
@@ -426,6 +472,35 @@ public void onDetachedFromWindow() {
426472
unregisterListeners();
427473
}
428474

475+
private ShoppingCart.ShoppingCartListener shoppingCartListener = new ShoppingCart.ShoppingCartListener() {
476+
@Override
477+
public void onItemAdded(ShoppingCart list, Product product) {
478+
if(list.getAddCount() == 1) {
479+
showHints();
480+
}
481+
}
482+
483+
@Override
484+
public void onQuantityChanged(ShoppingCart list, Product product) {
485+
486+
}
487+
488+
@Override
489+
public void onCleared(ShoppingCart list) {
490+
491+
}
492+
493+
@Override
494+
public void onItemMoved(ShoppingCart list, int fromIndex, int toIndex) {
495+
496+
}
497+
498+
@Override
499+
public void onItemRemoved(ShoppingCart list, Product product) {
500+
501+
}
502+
};
503+
429504
private Application.ActivityLifecycleCallbacks activityLifecycleCallbacks =
430505
new SimpleActivityLifecycleCallbacks() {
431506
@Override
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="wrap_content"
6+
android:layout_height="wrap_content"
7+
android:orientation="vertical">
8+
9+
<android.support.v7.widget.AppCompatImageView
10+
android:id="@+id/close"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:layout_gravity="center_horizontal"
14+
android:padding="12dp"
15+
android:background="?android:attr/selectableItemBackground"
16+
app:srcCompat="@drawable/ic_close" />
17+
18+
<android.support.v7.widget.AppCompatTextView
19+
android:id="@+id/title"
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:layout_marginBottom="8dp"
23+
android:paddingLeft="16dp"
24+
android:paddingRight="16dp"
25+
android:layout_gravity="center_horizontal"
26+
android:gravity="center"
27+
android:textSize="17sp"
28+
android:textStyle="bold"
29+
tools:text="Hinweis von snabble GmbH" />
30+
31+
<android.support.v7.widget.AppCompatTextView
32+
android:id="@+id/message"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:layout_gravity="center_horizontal"
36+
android:paddingLeft="16dp"
37+
android:paddingRight="16dp"
38+
android:gravity="center"
39+
android:textSize="17sp"
40+
android:text="@string/Snabble.Hints.closedBags" />
41+
</LinearLayout>

ui/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<string name="Snabble.Edit">Edit</string>
1212
<string name="Snabble.Yes">Yes</string>
1313
<string name="Snabble.No">No</string>
14+
<string name="Snabble.OK">OK</string>
1415
<string name="Snabble.Settings">Settings</string>
1516
<string name="Snabble.Delete">Delete</string>
1617
<string name="Snabble.remove">Remove</string>
@@ -55,6 +56,8 @@
5556
<string name="Snabble.Shoppingcart.deposit">Deposit</string>
5657
<string name="Snabble.PaymentMethod.encodedCodes">Checkstand</string>
5758
<string name="Snabble.PaymentMethod.qrCodePOS">Checkstand</string>
59+
<string name="Snabble.Hints.title">Hint from %s</string>
60+
<string name="Snabble.Hints.closedBags">Please make it easy for the cashier and do not put your items directly in closed pockets. Thank you!</string>
5861

5962
<!-- SECTION: Android -->
6063
<string name="Snabble.askForPermission">Ask for permission</string>

0 commit comments

Comments
 (0)