Skip to content

Commit 77fd31b

Browse files
committed
add support for changing actionbar titles in checkout
1 parent ad68179 commit 77fd31b

File tree

12 files changed

+87
-27
lines changed

12 files changed

+87
-27
lines changed

CHANGELOG.md

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

4-
## [0.11.0-alpha1]
4+
## [0.11.0]
55

66
### Changes
77
- SnabbleUICallback has now additional interface methods that needs to be implemented,
@@ -26,6 +26,11 @@ the new class ProductResolver
2626
- Snabble.Payment.emptyState.add
2727
- Snabble.Payment.delete.message
2828
- Snabble.Payment.add
29+
- Snabble.Checkout.verifying
30+
- Snabble.Checkout.done
31+
- Snabble.Checkout.payAtCashRegister
32+
- Snabble.Checkout.error
33+
2934

3035
## Fixed
3136
- Properly cleanup okhttp connections on error responses

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,24 @@ allprojects {
2424
}
2525

2626
project.ext {
27-
sdkVersion='0.11.0-alpha1'
27+
sdkVersion='0.11.0-alpha2'
2828
versionCode=1
2929

3030
compileSdkVersion=28
3131
minSdkVersion=16
3232
targetSdkVersion=28
3333

3434
buildToolsVersion='28.0.3'
35-
okhttpVersion='3.11.0'
35+
okhttpVersion='3.12.0'
3636

3737
sdkVersion += project.getProperties().get("versionSuffix", "")
3838
}
3939
}
4040

41+
task printVersion() {
42+
println project.sdkVersion
43+
}
44+
4145
task clean(type: Delete) {
4246
delete rootProject.buildDir
4347
}

local_release.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
22

3-
./gradlew install -PversionSuffix=-SNAPSHOT
4-
3+
d=`date +"%s"`
4+
./gradlew install -PversionSuffix=-${d}
5+
./gradlew printVersion -PversionSuffix=-${d}

ui/src/main/java/io/snabble/sdk/ui/SnabbleUI.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package io.snabble.sdk.ui;
22

33

4+
import androidx.appcompat.app.ActionBar;
45
import io.snabble.sdk.Project;
56
import io.snabble.sdk.utils.Logger;
67

78
public class SnabbleUI {
89
private static Project project;
910
private static SnabbleUICallback uiCallback;
11+
private static ActionBar actionBar;
1012

1113
/**
1214
* Registers a globally used project for use with views.
@@ -20,7 +22,7 @@ public static void useProject(Project project) {
2022
* Registers a callback that the application needs to implement and respond accordingly.
2123
* <p>
2224
* Remember to unregister the callback when not used anymore, for example if you implement
23-
* this callback in an Activity onCreate, remember to call unregisterUiCallbacks in onDestroy()
25+
* this callback in an Activity onStart, remember to call unregisterUiCallbacks in onStop()
2426
* <p>
2527
* Calling this multiple times overwrites the old callback
2628
*/
@@ -45,6 +47,31 @@ public static SnabbleUICallback getUiCallback() {
4547
return uiCallback;
4648
}
4749

50+
/**
51+
* Registers a ActionBar for suggested changes on the action bar.
52+
* <p>
53+
* Remember to unregister the ActionBar when not used anymore, for example if you set
54+
* this ActionBar in an Activity onCreate, remember to call unregisterActionBarListener in onDestroy()
55+
* <p>
56+
* Calling this multiple times overwrites the old callback
57+
*/
58+
public static void registerActionBar(ActionBar bar) {
59+
actionBar = bar;
60+
}
61+
62+
/**
63+
* Unregisters a callback that was previously registered.
64+
*/
65+
public static void unregisterActionBar(ActionBar bar) {
66+
if (actionBar == bar) {
67+
actionBar = null;
68+
}
69+
}
70+
71+
public static ActionBar getActionBar() {
72+
return actionBar;
73+
}
74+
4875
public static Project getProject() {
4976
if (project == null) {
5077
throw new RuntimeException("No Project instance set." +

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutAbortedView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public CheckoutAbortedView(Context context, AttributeSet attrs, int defStyleAttr
2828
private void inflateView() {
2929
inflate(getContext(), R.layout.view_checkout_aborted, this);
3030

31+
if (SnabbleUI.getActionBar() != null) {
32+
SnabbleUI.getActionBar().setTitle(R.string.Snabble_Checkout_error);
33+
}
34+
3135
findViewById(R.id.back).setOnClickListener(new OnClickListener() {
3236
@Override
3337
public void onClick(View v) {

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutDoneView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public CheckoutDoneView(Context context, AttributeSet attrs, int defStyleAttr) {
2828
private void inflateView() {
2929
inflate(getContext(), R.layout.view_checkout_done, this);
3030

31+
if (SnabbleUI.getActionBar() != null) {
32+
SnabbleUI.getActionBar().setTitle(R.string.Snabble_Checkout_done);
33+
}
34+
3135
findViewById(R.id.back).setOnClickListener(new OnClickListener() {
3236
@Override
3337
public void onClick(View v) {

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutEncodedCodesView.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,26 @@ public void onClick(View v) {
7979
String formattedAmount = priceFormatter.format(project.getCheckout().getPriceToPay());
8080

8181
TextView textView = findViewById(R.id.pay_amount);
82-
textView.setText(getContext().getString(R.string.Snabble_PaymentSelection_title) + " " + formattedAmount);
82+
String text = getContext().getString(R.string.Snabble_QRCode_total) + " " + formattedAmount;
83+
textView.setText(text);
8384

8485
explanationText = findViewById(R.id.explanation1);
8586
explanationText2 = findViewById(R.id.explanation2);
8687
}
8788

8889
private void updateExplanationText(int codeCount) {
90+
int resId;
8991
if (codeCount > 1) {
90-
explanationText.setText(R.string.Snabble_QRCode_showTheseCodes);
92+
resId = R.string.Snabble_QRCode_showTheseCodes;
9193
} else {
92-
explanationText.setText(R.string.Snabble_QRCode_showThisCode);
94+
resId = R.string.Snabble_QRCode_showThisCode;
95+
}
96+
97+
if (SnabbleUI.getActionBar() != null) {
98+
explanationText.setVisibility(View.GONE);
99+
SnabbleUI.getActionBar().setTitle(resId);
100+
} else {
101+
explanationText.setText(resId);
93102
}
94103
}
95104

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutQRCodePOSView.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ public void onClick(View v) {
4949
String formattedAmount = priceFormatter.format(project.getCheckout().getPriceToPay());
5050

5151
TextView textView = findViewById(R.id.pay_amount);
52-
textView.setText(getContext().getString(R.string.Snabble_PaymentSelection_title) + " " + formattedAmount);
52+
String text = getContext().getString(R.string.Snabble_QRCode_total) + " " + formattedAmount;
53+
54+
if (SnabbleUI.getActionBar() != null) {
55+
textView.setVisibility(View.GONE);
56+
SnabbleUI.getActionBar().setTitle(text);
57+
} else {
58+
textView.setText(text);
59+
}
5360
}
5461

5562
public void setQRCodeText(String text) {

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutStatusView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public void onClick(View v) {
9191
}
9292
}
9393

94+
if (SnabbleUI.getActionBar() != null) {
95+
SnabbleUI.getActionBar().setTitle(R.string.Snabble_Checkout_verifying);
96+
}
97+
9498
checkout = SnabbleUI.getProject().getCheckout();
9599
onStateChanged(checkout.getState());
96100
}

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutView.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class CheckoutView extends FrameLayout implements Checkout.OnCheckoutStat
3535

3636
private Checkout.State previousState;
3737
private DelayedProgressDialog progressDialog;
38-
private boolean showPricetoPayInPaymentSelection = true;
3938

4039
public CheckoutView(Context context) {
4140
super(context);
@@ -89,7 +88,6 @@ public void onStateChanged(Checkout.State state) {
8988
switch (state) {
9089
case REQUEST_PAYMENT_METHOD:
9190
PaymentMethodView paymentMethodView = new PaymentMethodView(getContext());
92-
paymentMethodView.setShowPriceToPay(showPricetoPayInPaymentSelection);
9391
displayView(paymentMethodView);
9492
break;
9593
case WAIT_FOR_APPROVAL:
@@ -205,10 +203,6 @@ public void onDetachedFromWindow() {
205203
unregisterListeners();
206204
}
207205

208-
public void setShowPriceToPayInPaymentSelection(boolean show) {
209-
showPricetoPayInPaymentSelection = show;
210-
}
211-
212206
private Application.ActivityLifecycleCallbacks activityLifecycleCallbacks =
213207
new SimpleActivityLifecycleCallbacks() {
214208
@Override

0 commit comments

Comments
 (0)