-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathRavePayActivity.java
More file actions
679 lines (564 loc) · 28.5 KB
/
RavePayActivity.java
File metadata and controls
679 lines (564 loc) · 28.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
package com.flutterwave.raveandroid;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.constraintlayout.widget.Guideline;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.transition.AutoTransition;
import androidx.transition.TransitionManager;
import com.flutterwave.raveandroid.account.AccountFragment;
import com.flutterwave.raveandroid.ach.AchFragment;
import com.flutterwave.raveandroid.banktransfer.BankTransferFragment;
import com.flutterwave.raveandroid.barter.BarterFragment;
import com.flutterwave.raveandroid.card.CardFragment;
import com.flutterwave.raveandroid.data.DeviceIdGetter;
import com.flutterwave.raveandroid.data.events.SessionFinishedEvent;
import com.flutterwave.raveandroid.di.components.DaggerRaveUiComponent;
import com.flutterwave.raveandroid.di.components.RaveUiComponent;
import com.flutterwave.raveandroid.di.modules.AndroidModule;
import com.flutterwave.raveandroid.francMobileMoney.FrancMobileMoneyFragment;
import com.flutterwave.raveandroid.ghmobilemoney.GhMobileMoneyFragment;
import com.flutterwave.raveandroid.mpesa.MpesaFragment;
import com.flutterwave.raveandroid.rave_core.di.DeviceIdGetterModule;
import com.flutterwave.raveandroid.rave_java_commons.RaveConstants;
import com.flutterwave.raveandroid.rave_logger.Event;
import com.flutterwave.raveandroid.rave_logger.EventLogger;
import com.flutterwave.raveandroid.rave_logger.di.EventLoggerModule;
import com.flutterwave.raveandroid.rave_logger.events.ScreenLaunchEvent;
import com.flutterwave.raveandroid.rave_logger.events.ScreenMinimizeEvent;
import com.flutterwave.raveandroid.rave_presentation.di.DaggerRaveComponent;
import com.flutterwave.raveandroid.rave_presentation.di.RaveComponent;
import com.flutterwave.raveandroid.rave_remote.di.RemoteModule;
import com.flutterwave.raveandroid.rwfmobilemoney.RwfMobileMoneyFragment;
import com.flutterwave.raveandroid.sabankaccount.SaBankAccountFragment;
import com.flutterwave.raveandroid.ugmobilemoney.UgMobileMoneyFragment;
import com.flutterwave.raveandroid.uk.UkFragment;
import com.flutterwave.raveandroid.ussd.UssdFragment;
import com.flutterwave.raveandroid.zmmobilemoney.ZmMobileMoneyFragment;
import org.parceler.Parcels;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import javax.inject.Inject;
import static androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.HORIZONTAL;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.LIVE_URL;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_ACCOUNT;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_ACH;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_BANK_TRANSFER;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_BARTER;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_FRANCO_MOBILE_MONEY;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_GH_MOBILE_MONEY;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_MPESA;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_RW_MOBILE_MONEY;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_SA_BANK_ACCOUNT;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_UG_MOBILE_MONEY;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_UK;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_USSD;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PAYMENT_TYPE_ZM_MOBILE_MONEY;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVE_PARAMS;
import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.STAGING_URL;
public class RavePayActivity extends AppCompatActivity {
public static String BASE_URL;
View.OnClickListener onClickListener;
private HashMap<Integer, Guideline> guidelineMap = new HashMap<>();
private ArrayList<PaymentTile> paymentTiles = new ArrayList<>();
private HashMap<Integer, PaymentTile> tileMap = new HashMap<>();
private Guideline topGuide;
RavePayInitializer ravePayInitializer;
private Guideline bottomGuide;
private ConstraintLayout root;
public static int RESULT_SUCCESS = RaveConstants.RESULT_SUCCESS;
public static int RESULT_ERROR = RaveConstants.RESULT_ERROR;
public static int RESULT_CANCELLED = RaveConstants.RESULT_CANCELLED;
private int tileCount = 0;
int theme;
private float paymentTilesTextSize;
private long transitionDuration = 350;
RaveUiComponent raveUiComponent;
@Inject
EventLogger eventLogger;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
ravePayInitializer = Parcels.unwrap(getIntent().getParcelableExtra(RAVE_PARAMS));
} catch (Exception e) {
e.printStackTrace();
Log.d(RAVEPAY, "Error retrieving initializer");
}
buildGraph();
theme = ravePayInitializer.getTheme();
if (theme != 0) {
try {
setTheme(theme);
} catch (Exception e) {
e.printStackTrace();
}
}
setContentView(R.layout.rave_sdk_activity_rave_pay);
root = findViewById(R.id.rave_pay_activity_rootview);
Event event = new ScreenLaunchEvent("Payment Activity").getEvent();
event.setPublicKey(ravePayInitializer.getPublicKey());
eventLogger.logEvent(event);
setupMainContent();
}
private void setupMainContent() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
handleClick(view);
}
};
topGuide = createGuideline(this, HORIZONTAL);
root.addView(topGuide);
topGuide.setGuidelinePercent(0.08f);
bottomGuide = createGuideline(this, HORIZONTAL);
root.addView(bottomGuide);
bottomGuide.setGuidelinePercent(0.92f);
generatePaymentTiles();
generateGuides(tileCount);
render();
}
private void render() {
render(false);
}
private void render(boolean animated) {
if (tileCount == 1) {
View singlePaymentTileView = paymentTiles.get(0).view;
singlePaymentTileView.callOnClick(); // Show payment fragment
singlePaymentTileView.findViewById(R.id.arrowIv2).setVisibility(View.GONE);
((TextView) singlePaymentTileView.findViewById(R.id.rave_payment_type_title_textView)).setGravity(Gravity.CENTER);
singlePaymentTileView.setOnClickListener(null);
} else {
View fragmentContainerLayout = root.getViewById(R.id.payment_fragment_container_layout);
if (fragmentContainerLayout != null) {
renderAsHidden(fragmentContainerLayout, animated);
}
ConstraintSet set = new ConstraintSet();
set.clone(root);
for (int i = 0; i < paymentTiles.size(); i++) {
View tv2 = paymentTiles.get(i).view;
int upIndex = 10 - (i + 1);
Guideline upGuide = guidelineMap.get(upIndex);
Guideline downGuide = guidelineMap.get(upIndex + 1);
if (upGuide != null && downGuide != null) {
set.connect(tv2.getId(), ConstraintSet.TOP, upGuide.getId(), ConstraintSet.BOTTOM);
set.connect(tv2.getId(), ConstraintSet.BOTTOM, downGuide.getId(), ConstraintSet.TOP);
set.connect(tv2.getId(), ConstraintSet.LEFT, root.getId(), ConstraintSet.LEFT);
set.connect(tv2.getId(), ConstraintSet.RIGHT, root.getId(), ConstraintSet.RIGHT);
set.constrainWidth(tv2.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.constrainHeight(tv2.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.setVisibility(tv2.getId(), ConstraintSet.VISIBLE);
View arrowIv = tv2.findViewById(R.id.arrowIv2);
if (arrowIv != null)
arrowIv.animate().rotation(0f).setDuration(transitionDuration);
}
}
// Set title view
View titleView = root.findViewById(R.id.title_container);
if (titleView == null) {
titleView = getLayoutInflater().inflate(R.layout.rave_sdk_payment_title_layout, root, false);
root.addView(titleView);
}
set.connect(titleView.getId(), ConstraintSet.TOP, root.getId(), ConstraintSet.TOP);
set.connect(titleView.getId(), ConstraintSet.BOTTOM, guidelineMap.get(10 - paymentTiles.size() + 1).getId(), ConstraintSet.BOTTOM);
set.connect(titleView.getId(), ConstraintSet.LEFT, root.getId(), ConstraintSet.LEFT);
set.connect(titleView.getId(), ConstraintSet.RIGHT, root.getId(), ConstraintSet.RIGHT);
set.constrainWidth(titleView.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.constrainHeight(titleView.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.setVisibility(titleView.getId(), ConstraintSet.VISIBLE);
if (animated) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AutoTransition transition = new AutoTransition();
transition.setDuration(transitionDuration);
TransitionManager.beginDelayedTransition(root, transition);
set.applyTo(root);
}
} else {
set.applyTo(root);
}
}
}
private void handleClick(View clickedView) {
PaymentTile paymentTile = tileMap.get(clickedView.getId());
if (paymentTile.isTop) {
Event event = new ScreenMinimizeEvent("payment methods").getEvent();
event.setPublicKey(ravePayInitializer.getPublicKey());
eventLogger.logEvent(event);
showAllPaymentTypes();
} else {
showSelectedPaymentType(clickedView);
}
}
private void showAllPaymentTypes() {
render(true);
for (int i = 0; i < paymentTiles.size(); i++) {
PaymentTile t = paymentTiles.get(i);
t.isTop = false;
tileMap.put(t.view.getId(), t);
}
}
private void showSelectedPaymentType(View clickedView) {
for (int i = 0; i < paymentTiles.size(); i++) {
PaymentTile t = paymentTiles.get(i);
t.isTop = t.view.getId() == clickedView.getId();
tileMap.put(t.view.getId(), t);
}
Integer tileId = null;
PaymentTile foundPaymentTile = null;
Integer foundIndex = null;
for (int i = 0; i < paymentTiles.size(); i++) {
PaymentTile current = paymentTiles.get(i);
if (current.view.getId() == clickedView.getId()) {
tileId = current.view.getId();
foundPaymentTile = current;
foundIndex = i;
break;
}
}
// If view was found
if (tileId != null && paymentTiles.size() != 0) {
renderAsHidden(root.getViewById(R.id.title_container));
renderToTop(foundPaymentTile.view);
displayPaymentFragment(foundPaymentTile);
if (tileCount > 1) {
if (tileId == paymentTiles.get(paymentTiles.size() - 1).view.getId()) {
//pick first as bottom
int bottomId = paymentTiles.get(0).view.getId();
renderToBottom(paymentTiles.get(0).view);
//hide other(s)
for (int i = 0; i < paymentTiles.size(); i++) {
PaymentTile t = paymentTiles.get(i);
if (clickedView.getId() != t.view.getId() && bottomId != t.view.getId()) {
renderAsHidden(t.view);
}
}
} else {
int bottomId = paymentTiles.get(foundIndex + 1).view.getId();
//pick next as bottom
renderToBottom(paymentTiles.get(foundIndex + 1).view);
//hide other(S)
for (int i = 0; i < paymentTiles.size(); i++) {
PaymentTile t = paymentTiles.get(i);
if (clickedView.getId() != t.view.getId() && bottomId != t.view.getId()) {
renderAsHidden(t.view);
}
}
}
}
}
}
private void displayPaymentFragment(final PaymentTile foundPaymentTile) {
View fragmentContainerLayout = root.getViewById(R.id.payment_fragment_container_layout);
if (fragmentContainerLayout == null) {
fragmentContainerLayout
= getLayoutInflater()
.inflate(R.layout.rave_sdk_payment_fragment_container_layout, root, false);
root.addView(fragmentContainerLayout);
fragmentContainerLayout
.findViewById(R.id.choose_another_payment_method_tv)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Event event = new ScreenMinimizeEvent("Payment Methods").getEvent();
event.setPublicKey(ravePayInitializer.getPublicKey());
eventLogger.logEvent(event);
showAllPaymentTypes();
}
});
}
if (ravePayInitializer.isStaging() && ravePayInitializer.getShowStagingLabel()) {
findViewById(R.id.stagingModeBannerLay).setVisibility(View.VISIBLE);
}
int topToBottomConstraint = ((ConstraintLayout.LayoutParams)
fragmentContainerLayout.getLayoutParams()).topToBottom;
int topToTopConstraint = ((ConstraintLayout.LayoutParams)
fragmentContainerLayout.getLayoutParams()).topToTop;
if (topToBottomConstraint != topGuide.getId() && topToTopConstraint != topGuide.getId()) {
setPaymentFragmentInPlace(fragmentContainerLayout, foundPaymentTile);
} else hideThenShowFragment(fragmentContainerLayout, foundPaymentTile);
}
private void hideThenShowFragment(final View fragmentContainerLayout, final PaymentTile paymentTile) {
fragmentContainerLayout.animate()
.setDuration(transitionDuration / 3)
.alpha(0.0f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
addFragmentToLayout(paymentTile);
fragmentContainerLayout
.animate()
.setListener(null)
.setDuration(transitionDuration * 2 / 3)
.alpha(1.0f);
}
});
}
private void setPaymentFragmentInPlace(View fragmentContainerLayout, PaymentTile foundPaymentTile) {
ConstraintSet set = new ConstraintSet();
set.clone(root);
set.connect(fragmentContainerLayout.getId(), ConstraintSet.TOP, topGuide.getId(), ConstraintSet.TOP);
if (tileCount > 1)
set.connect(fragmentContainerLayout.getId(), ConstraintSet.BOTTOM, bottomGuide.getId(), ConstraintSet.BOTTOM);
else
set.connect(fragmentContainerLayout.getId(), ConstraintSet.BOTTOM, root.getId(), ConstraintSet.BOTTOM);
set.connect(fragmentContainerLayout.getId(), ConstraintSet.LEFT, root.getId(), ConstraintSet.LEFT);
set.connect(fragmentContainerLayout.getId(), ConstraintSet.RIGHT, root.getId(), ConstraintSet.RIGHT);
set.constrainWidth(fragmentContainerLayout.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.constrainHeight(fragmentContainerLayout.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.setVisibility(fragmentContainerLayout.getId(), ConstraintSet.VISIBLE);
addFragmentToLayout(foundPaymentTile);
if (tileCount == 1)
fragmentContainerLayout.findViewById(R.id.choose_another_payment_method_tv).setVisibility(View.GONE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AutoTransition transition = new AutoTransition();
transition.setDuration(transitionDuration);
TransitionManager.beginDelayedTransition(root, transition);
set.applyTo(root);
} else {
set.applyTo(root);
}
}
private void addFragmentToLayout(PaymentTile foundPaymentTile) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
switch (foundPaymentTile.paymentType) {
case PAYMENT_TYPE_ACCOUNT:
transaction.replace(R.id.payment_fragment_container, new AccountFragment());
break;
case PAYMENT_TYPE_ACH:
transaction.replace(R.id.payment_fragment_container, new AchFragment());
break;
case PAYMENT_TYPE_BANK_TRANSFER:
transaction.replace(R.id.payment_fragment_container, new BankTransferFragment());
break;
case RaveConstants.PAYMENT_TYPE_CARD:
transaction.replace(R.id.payment_fragment_container, new CardFragment());
break;
case PAYMENT_TYPE_FRANCO_MOBILE_MONEY:
transaction.replace(R.id.payment_fragment_container, new FrancMobileMoneyFragment());
break;
case PAYMENT_TYPE_GH_MOBILE_MONEY:
transaction.replace(R.id.payment_fragment_container, new GhMobileMoneyFragment());
break;
case PAYMENT_TYPE_MPESA:
transaction.replace(R.id.payment_fragment_container, new MpesaFragment());
break;
case PAYMENT_TYPE_RW_MOBILE_MONEY:
transaction.replace(R.id.payment_fragment_container, new RwfMobileMoneyFragment());
break;
case PAYMENT_TYPE_UG_MOBILE_MONEY:
transaction.replace(R.id.payment_fragment_container, new UgMobileMoneyFragment());
break;
case PAYMENT_TYPE_UK:
transaction.replace(R.id.payment_fragment_container, new UkFragment());
break;
case PAYMENT_TYPE_BARTER:
transaction.replace(R.id.payment_fragment_container, new BarterFragment());
break;
case PAYMENT_TYPE_USSD:
transaction.replace(R.id.payment_fragment_container, new UssdFragment());
break;
case PAYMENT_TYPE_ZM_MOBILE_MONEY:
transaction.replace(R.id.payment_fragment_container, new ZmMobileMoneyFragment());
break;
case PAYMENT_TYPE_SA_BANK_ACCOUNT:
transaction.replace(R.id.payment_fragment_container, new SaBankAccountFragment());
break;
default:
Log.d("Adding Payment Fragment", "Payment type does not exist in payment types list");
render();// Show default view
return;
}
try {
transaction.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void renderToTop(View tv) {
ConstraintSet set = new ConstraintSet();
set.clone(root);
set.connect(tv.getId(), ConstraintSet.TOP, root.getId(), ConstraintSet.TOP);
set.connect(tv.getId(), ConstraintSet.BOTTOM, topGuide.getId(), ConstraintSet.TOP);
set.connect(tv.getId(), ConstraintSet.LEFT, root.getId(), ConstraintSet.LEFT);
set.connect(tv.getId(), ConstraintSet.RIGHT, root.getId(), ConstraintSet.RIGHT);
set.constrainWidth(tv.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.constrainHeight(tv.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.setVisibility(tv.getId(), ConstraintSet.VISIBLE);
View arrowIv = tv.findViewById(R.id.arrowIv2);
if (arrowIv != null)
arrowIv.animate().rotation(180f).setDuration(transitionDuration);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AutoTransition transition = new AutoTransition();
transition.setDuration(transitionDuration);
TransitionManager.beginDelayedTransition(root, transition);
set.applyTo(root);
} else set.applyTo(root);
}
private void renderToBottom(View tv) {
ConstraintSet set = new ConstraintSet();
set.clone(root);
set.connect(tv.getId(), ConstraintSet.TOP, bottomGuide.getId(), ConstraintSet.BOTTOM);
set.connect(tv.getId(), ConstraintSet.BOTTOM, root.getId(), ConstraintSet.BOTTOM);
set.connect(tv.getId(), ConstraintSet.LEFT, root.getId(), ConstraintSet.LEFT);
set.connect(tv.getId(), ConstraintSet.RIGHT, root.getId(), ConstraintSet.RIGHT);
set.constrainWidth(tv.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.constrainHeight(tv.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.setVisibility(tv.getId(), ConstraintSet.VISIBLE);
View arrowIv = tv.findViewById(R.id.arrowIv2);
if (arrowIv != null) arrowIv.animate().rotation(0f).setDuration(transitionDuration);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AutoTransition transition = new AutoTransition();
transition.setDuration(transitionDuration);
TransitionManager.beginDelayedTransition(root, transition);
set.applyTo(root);
} else
set.applyTo(root);
}
private void renderAsHidden(View view) {
renderAsHidden(view, false);
}
private void renderAsHidden(View view, Boolean fadeOut) {
if (view != null) {
ConstraintSet set = new ConstraintSet();
set.clone(root);
set.connect(view.getId(), ConstraintSet.TOP, root.getId(), ConstraintSet.TOP);
set.connect(view.getId(), ConstraintSet.BOTTOM, root.getId(), ConstraintSet.TOP);
set.connect(view.getId(), ConstraintSet.LEFT, root.getId(), ConstraintSet.LEFT);
set.connect(view.getId(), ConstraintSet.RIGHT, root.getId(), ConstraintSet.RIGHT);
set.constrainWidth(view.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
set.constrainHeight(view.getId(), ConstraintSet.MATCH_CONSTRAINT_SPREAD);
if (fadeOut) set.setVisibility(view.getId(), ConstraintSet.GONE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AutoTransition transition = new AutoTransition();
transition.setDuration(transitionDuration);
TransitionManager.beginDelayedTransition(root, transition);
set.applyTo(root);
} else {
set.applyTo(root);
}
}
}
private void generatePaymentTiles() {
ArrayList<Integer> orderedPaymentTypesList = ravePayInitializer.getOrderedPaymentTypesList();
// Reverse payment types order since payment types are added from the bottom
Collections.reverse(orderedPaymentTypesList);
tileCount = orderedPaymentTypesList.size();
if (tileCount > 8) paymentTilesTextSize = 16f;
else paymentTilesTextSize = 18f;
for (int index = 0; index < orderedPaymentTypesList.size(); index++)
addPaymentType(orderedPaymentTypesList.get(index));
}
private void addPaymentType(int paymentType) {
View tileView;
try {
tileView = createPaymentTileView(RaveConstants.paymentTypesNamesList.get(paymentType) + "");
} catch (Exception e) {
e.printStackTrace();
Log.d("Add payment type error", "Payment type doesn't exist.");
return;
}
PaymentTile paymentTile = new PaymentTile(tileView, paymentType, false);
paymentTiles.add(paymentTile);
tileView.setOnClickListener(onClickListener);
tileMap.put(tileView.getId(), paymentTile);
}
private View createPaymentTileView(String title) {
View tileView = getLayoutInflater().inflate(R.layout.rave_sdk_payment_type_tile_layout, root, false);
TextView tv2 = tileView.findViewById(R.id.rave_payment_type_title_textView);
tileView.setId(ViewCompat.generateViewId());
String fullTitle = "Pay with " + title;
SpannableStringBuilder sb = new SpannableStringBuilder(fullTitle);
sb.setSpan(new StyleSpan(Typeface.BOLD), 9, fullTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
tv2.setText(sb);
tv2.setTextSize(paymentTilesTextSize);
root.addView(tileView);
return tileView;
}
private void generateGuides(int count) {
for (int i = 0; i <= count; i++) {
Guideline guideline = createGuideline(this, HORIZONTAL);
root.addView(guideline);
double percent;
if (count > 8) percent = (1 - (0.07 * i));
else percent = (1 - (0.08 * i));
guideline.setGuidelinePercent((float) percent);
guideline.setTag(10 - i);
guidelineMap.put(10 - i, guideline);
}
}
private Guideline createGuideline(Context context, int orientation) {
Guideline guideline = new Guideline(context);
guideline.setId(ViewCompat.generateViewId());
ConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.WRAP_CONTENT,
ConstraintLayout.LayoutParams.WRAP_CONTENT
);
lp.orientation = orientation;
guideline.setLayoutParams(lp);
return guideline;
}
private void buildGraph() {
if (ravePayInitializer.isStaging()) {
BASE_URL = STAGING_URL;
} else {
BASE_URL = LIVE_URL;
}
RaveComponent raveComponent = DaggerRaveComponent.builder()
.deviceIdGetterModule(new DeviceIdGetterModule(new DeviceIdGetter(this).getDeviceId()))
.remoteModule(new RemoteModule(BASE_URL))
.eventLoggerModule(new EventLoggerModule())
.build();
raveUiComponent = DaggerRaveUiComponent.builder()
.androidModule(new AndroidModule(this))
.raveComponent(raveComponent).build();
raveUiComponent.inject(this);
}
@Override
public void onBackPressed() {
setRavePayResult(RavePayActivity.RESULT_CANCELLED, new Intent());
super.onBackPressed();
}
public void setRavePayResult(int result, Intent intent) {
if (result == RESULT_CANCELLED) {
Event event = new SessionFinishedEvent("Payment cancelled").getEvent();
event.setPublicKey(ravePayInitializer.getPublicKey());
eventLogger.logEvent(event);
} else if (result == RESULT_ERROR) {
Event event = new SessionFinishedEvent("Payment error").getEvent();
event.setPublicKey(ravePayInitializer.getPublicKey());
eventLogger.logEvent(event);
} else if (result == RESULT_SUCCESS) {
Event event = new SessionFinishedEvent("Payment successful").getEvent();
event.setPublicKey(ravePayInitializer.getPublicKey());
eventLogger.logEvent(event);
}
setResult(result, intent);
}
public RaveUiComponent getRaveUiComponent() {
return raveUiComponent;
}
public RavePayInitializer getRavePayInitializer() {
return ravePayInitializer;
}
public EventLogger getEventLogger() {
return eventLogger;
}
}