Skip to content

Commit 622f2c5

Browse files
committed
Improved encoded codes layout
1 parent 97a2ead commit 622f2c5

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.snabble.sdk.ui.checkout;
22

33
import android.content.Context;
4+
import android.content.res.Resources;
45
import android.support.annotation.NonNull;
56
import android.util.AttributeSet;
67
import android.view.View;
@@ -28,6 +29,7 @@ class CheckoutEncodedCodesView extends FrameLayout implements View.OnLayoutChang
2829
private View scrollContainer;
2930
private ScrollView scrollView;
3031
private TextView explanationText;
32+
private TextView explanationText2;
3133
private SnabbleSdk sdkInstance;
3234
private int codeCount;
3335

@@ -75,10 +77,11 @@ public void onClick(View v) {
7577
textView.setText(getContext().getString(R.string.Snabble_PaymentSelection_title) + " " + formattedAmount);
7678

7779
explanationText = findViewById(R.id.explanation1);
80+
explanationText2 = findViewById(R.id.explanation2);
7881
}
7982

80-
private void updateExplanationText(int codeCount){
81-
if(codeCount > 1) {
83+
private void updateExplanationText(int codeCount) {
84+
if (codeCount > 1) {
8285
explanationText.setText(R.string.Snabble_QRCode_showTheseCodes);
8386
} else {
8487
explanationText.setText(R.string.Snabble_QRCode_showThisCode);
@@ -102,14 +105,22 @@ protected void onDetachedFromWindow() {
102105
@Override
103106
public void onLayoutChange(View v, int left, int top, int right, int bottom,
104107
int oldLeft, int oldTop, int oldRight, int oldBottom) {
105-
if(left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
106-
if(scrollContainer.getWidth() > 0 && scrollContainer.getHeight() > 0) {
108+
if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
109+
if (scrollContainer.getWidth() > 0 && scrollContainer.getHeight() > 0) {
107110
scrollView.removeAllViews();
108111
CodeListView codeListView = new CodeListView(getContext());
109112
scrollView.addView(codeListView, new ViewGroup.LayoutParams(
110113
ViewGroup.LayoutParams.MATCH_PARENT,
111114
ViewGroup.LayoutParams.WRAP_CONTENT));
112115
}
116+
117+
Resources resources = getResources();
118+
119+
int h = Math.round(scrollContainer.getHeight() * resources.getDisplayMetrics().density);
120+
if (h < 160) {
121+
explanationText.setVisibility(View.GONE);
122+
explanationText2.setVisibility(View.GONE);
123+
}
113124
}
114125
}
115126

@@ -129,7 +140,7 @@ public CodeListView(@NonNull Context context) {
129140

130141
addCodes();
131142

132-
if(getChildCount() == 0){
143+
if (getChildCount() == 0) {
133144
barcodeHeight = h;
134145
}
135146

@@ -147,16 +158,16 @@ private void addCodes() {
147158

148159
for (int i = 0; i < shoppingCart.size(); i++) {
149160
Product product = shoppingCart.getProduct(i);
150-
if(product.getType() == Product.Type.UserWeighed){
161+
if (product.getType() == Product.Type.UserWeighed) {
151162
//encoding weight in ean
152163
String[] weighItemIds = product.getWeighedItemIds();
153-
if(weighItemIds != null && weighItemIds.length > 0){
164+
if (weighItemIds != null && weighItemIds.length > 0) {
154165
StringBuilder code = new StringBuilder(weighItemIds[0]);
155-
if(code.length() == 13){
166+
if (code.length() == 13) {
156167
StringBuilder embeddedWeight = new StringBuilder();
157168
String quantity = String.valueOf(shoppingCart.getQuantity(i));
158169
int leadingZeros = 5 - quantity.length();
159-
for(int j=0; j<leadingZeros; j++){
170+
for (int j = 0; j < leadingZeros; j++) {
160171
embeddedWeight.append('0');
161172
}
162173
embeddedWeight.append(quantity);
@@ -201,7 +212,7 @@ private void addScannableCode(String scannableCode) {
201212
generateView();
202213
}
203214

204-
if(stringBuilder.length() == 0){
215+
if (stringBuilder.length() == 0) {
205216
stringBuilder.append(sdkInstance.getEncodedCodesPrefix());
206217
} else {
207218
stringBuilder.append(sdkInstance.getEncodedCodesSeperator());

ui/src/main/res/layout/view_checkout_encodedcodes.xml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,29 @@
33
xmlns:tools="http://schemas.android.com/tools"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6-
android:background="@color/snabble_primaryColor">
6+
android:background="#ffffff">
77

8-
<TextView
9-
android:id="@+id/pay_amount"
10-
android:layout_width="wrap_content"
11-
android:layout_height="wrap_content"
12-
android:layout_centerHorizontal="true"
13-
android:layout_marginTop="8dp"
14-
android:textStyle="bold"
15-
android:gravity="center"
16-
android:textSize="17sp"
17-
android:textColor="@color/snabble_textColorLight"
18-
tools:text="@string/Snabble.PaymentSelection.title" />
198

209
<TextView
2110
android:id="@+id/explanation1"
2211
android:layout_width="wrap_content"
2312
android:layout_height="wrap_content"
2413
android:gravity="center"
2514
android:layout_centerHorizontal="true"
26-
android:layout_below="@+id/pay_amount"
15+
android:layout_alignParentTop="true"
2716
android:text="@string/Snabble.QRCode.showThisCode"
28-
android:textColor="@color/snabble_textColorLight"
29-
android:layout_marginTop="8dp"
17+
android:textColor="@color/snabble_textColorDark"
18+
android:layout_marginTop="16dp"
3019
android:layout_marginLeft="24dp"
3120
android:layout_marginRight="24dp"
32-
android:textSize="15sp"
33-
android:textStyle="bold"/>
21+
android:textSize="17sp"/>
3422

3523
<FrameLayout
3624
android:layout_width="match_parent"
3725
android:layout_height="match_parent"
38-
android:layout_above="@+id/explanation2"
26+
android:layout_above="@+id/pay_amount"
3927
android:layout_below="@+id/explanation1"
28+
android:minHeight="200dp"
4029
android:id="@+id/scroll_container">
4130
<ScrollView
4231
android:layout_width="match_parent"
@@ -46,6 +35,20 @@
4635
</ScrollView>
4736
</FrameLayout>
4837

38+
<TextView
39+
android:id="@+id/pay_amount"
40+
android:layout_width="wrap_content"
41+
android:layout_height="wrap_content"
42+
android:layout_centerHorizontal="true"
43+
android:layout_above="@+id/explanation2"
44+
android:textStyle="bold"
45+
android:gravity="center"
46+
android:textSize="19sp"
47+
android:layout_marginTop="8dp"
48+
android:layout_marginBottom="8dp"
49+
android:textColor="@color/snabble_textColorDark"
50+
tools:text="@string/Snabble.PaymentSelection.title" />
51+
4952
<TextView
5053
android:id="@+id/explanation2"
5154
android:layout_width="wrap_content"
@@ -54,15 +57,15 @@
5457
android:layout_centerHorizontal="true"
5558
android:layout_above="@+id/paid"
5659
android:text="@string/Snabble.QRCode.priceMayDiffer"
57-
android:textColor="@color/snabble_textColorLight"
60+
android:textColor="@color/snabble_textColorDark"
5861
android:layout_marginLeft="24dp"
5962
android:layout_marginRight="24dp"
6063
android:layout_marginBottom="16dp"
61-
android:textSize="14sp"/>
64+
android:textSize="13sp"/>
6265

6366
<android.support.v7.widget.AppCompatButton
6467
android:id="@+id/paid"
65-
style="@style/SnabbleButtonWhite"
68+
style="@style/SnabbleButton"
6669
android:layout_width="wrap_content"
6770
android:layout_height="wrap_content"
6871
android:layout_alignParentBottom="true"

0 commit comments

Comments
 (0)