@@ -26,6 +26,7 @@ class CheckoutEncodedCodesView extends FrameLayout implements View.OnLayoutChang
2626 private View scrollContainer ;
2727 private ScrollView scrollView ;
2828 private TextView explanationText ;
29+ private SnabbleSdk sdkInstance ;
2930
3031 public CheckoutEncodedCodesView (Context context ) {
3132 super (context );
@@ -48,7 +49,7 @@ private void inflateView() {
4849 scrollContainer = findViewById (R .id .scroll_container );
4950 scrollView = findViewById (R .id .scroll_view );
5051
51- SnabbleSdk sdkInstance = SnabbleUI .getSdkInstance ();
52+ sdkInstance = SnabbleUI .getSdkInstance ();
5253 ShoppingCart shoppingCart = sdkInstance .getShoppingCart ();
5354
5455 Button paidButton = findViewById (R .id .paid );
@@ -121,33 +122,34 @@ public CodeListView(@NonNull Context context) {
121122
122123 stringBuilder = new StringBuilder ();
123124
124- SnabbleSdk sdkInstance = SnabbleUI .getSdkInstance ();
125125 Checkout checkout = sdkInstance .getCheckout ();
126126 ShoppingCart shoppingCart = sdkInstance .getShoppingCart ();
127127
128128 int h = scrollContainer .getHeight ();
129129 barcodeHeight = h - h / 5 ;
130130
131131 for (String code : checkout .getCodes ()) {
132- addLine (code );
132+ addScannableCode (code );
133133 }
134134
135135 for (int i = 0 ; i < shoppingCart .size (); i ++) {
136136 for (int j = 0 ; j < shoppingCart .getQuantity (i ); j ++) {
137- addLine (shoppingCart .getScannedCode (i ));
137+ addScannableCode (shoppingCart .getScannedCode (i ));
138138 }
139139 }
140140
141141 if (getChildCount () == 0 ){
142142 barcodeHeight = h ;
143143 }
144144
145- addCode (stringBuilder .toString ());
146-
145+ generateView ();
147146 updateExplanationText (getChildCount ());
148147 }
149148
150- private void addCode (String code ) {
149+ private void generateView () {
150+ stringBuilder .append (sdkInstance .getEncodedCodesSuffix ());
151+ String code = stringBuilder .toString ();
152+
151153 BarcodeView barcodeView = new BarcodeView (getContext ());
152154 barcodeView .setFormat (BarcodeFormat .QR_CODE );
153155
@@ -163,13 +165,19 @@ private void addCode(String code) {
163165 stringBuilder = new StringBuilder ();
164166 }
165167
166- private void addLine (String line ) {
167- if (stringBuilder .length () + (line .length () + 1 ) > MAX_CHARS ) {
168- addCode (stringBuilder .toString ());
168+ private void addScannableCode (String scannableCode ) {
169+ int requiredLength = scannableCode .length () + sdkInstance .getEncodedCodesSuffix ().length () + 1 ;
170+ if (stringBuilder .length () + (requiredLength ) > MAX_CHARS ) {
171+ generateView ();
172+ }
173+
174+ if (stringBuilder .length () == 0 ){
175+ stringBuilder .append (sdkInstance .getEncodedCodesPrefix ());
176+ } else {
177+ stringBuilder .append (sdkInstance .getEncodedCodesSeperator ());
169178 }
170179
171- stringBuilder .append (line );
172- stringBuilder .append ("\n " );
180+ stringBuilder .append (scannableCode );
173181 }
174182 }
175183}
0 commit comments