@@ -421,8 +421,10 @@ public void onPaymentError(String errorMessage) {
421
421
@ Override
422
422
public void collectCardPin (final Payload payload ) {
423
423
this .payLoad = payload ; //added so as to get back in onActivityResult
424
- new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
425
- .showPinScreen ();
424
+ if (isAdded ()){
425
+ new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
426
+ .showPinScreen ();
427
+ }
426
428
}
427
429
428
430
@ Override
@@ -485,7 +487,9 @@ public void onSaveInstanceState(Bundle outState) {
485
487
* @param message = text to display
486
488
*/
487
489
public void showToast (String message ) {
488
- Toast .makeText (requireContext (), message +"" , Toast .LENGTH_SHORT ).show ();
490
+ if (isAdded ()){
491
+ Toast .makeText (requireContext (), message +"" , Toast .LENGTH_SHORT ).show ();
492
+ }
489
493
}
490
494
491
495
/**
@@ -508,15 +512,19 @@ private void dismissDialog() {
508
512
public void collectOtp (String flwRef , String message ) {
509
513
this .flwRef = flwRef ;
510
514
dismissDialog ();
511
- new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
512
- .showOtpScreen (message );
515
+ if (isAdded ()){
516
+ new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
517
+ .showOtpScreen (message );
518
+ }
513
519
}
514
520
515
521
public void showOTPLayoutForSavedCard (Payload payload , String authInstruction ) {
516
522
this .payLoad = payload ;
517
523
dismissDialog ();
518
- new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
519
- .showOtpScreenForSavedCard (authInstruction );
524
+ if (isAdded ()){
525
+ new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
526
+ .showOtpScreenForSavedCard (authInstruction );
527
+ }
520
528
}
521
529
522
530
@ Override
@@ -576,8 +584,10 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
576
584
public void showWebPage (String authenticationUrl , String flwRef ) {
577
585
578
586
this .flwRef = flwRef ;
579
- new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
580
- .showWebpageVerificationScreen (authenticationUrl );
587
+ if (isAdded ()){
588
+ new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
589
+ .showWebpageVerificationScreen (authenticationUrl );
590
+ }
581
591
}
582
592
583
593
@ Override
@@ -774,19 +784,17 @@ public void onClick(DialogInterface dialog, int which) {
774
784
public void collectCardAddressDetails (final Payload payload , String authModel ) {
775
785
this .payLoad = payload ;
776
786
this .authModel = authModel ;
777
- new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
778
- .showAddressScreen ();
787
+ if (isAdded ()){
788
+ new RaveVerificationUtils (this , ravePayInitializer .isStaging (), ravePayInitializer .getPublicKey (), ravePayInitializer .getTheme ())
789
+ .showAddressScreen ();
790
+ }
779
791
}
780
792
781
793
private class ExpiryWatcher implements TextWatcher {
782
794
783
- private final Calendar calendar ;
784
- private final SimpleDateFormat simpleDateFormat ;
785
795
private String lastInput = "" ;
786
796
787
797
public ExpiryWatcher () {
788
- calendar = Calendar .getInstance ();
789
- simpleDateFormat = new SimpleDateFormat ("MM/yy" );
790
798
}
791
799
792
800
@ Override
@@ -803,44 +811,47 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
803
811
public void afterTextChanged (Editable editable ) {
804
812
String input = editable .toString ();
805
813
String cardExpiryToSet = cardExpiryTv .getText ().toString () + "/" ;
814
+ String defaultExpiry = "12" ;
806
815
807
- try {
808
- calendar .setTime (simpleDateFormat .parse (input ));
809
- } catch (ParseException e ) {
810
-
811
- if (editable .length () == 2 && !lastInput .endsWith ("/" )) {
816
+ if (editable .length () == 2 && !lastInput .endsWith ("/" )) {
812
817
818
+ try {
813
819
int month = Integer .parseInt (input );
814
820
if (month <= 12 ) {
815
821
cardExpiryTv .setText (cardExpiryToSet );
816
822
cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
817
823
} else {
818
- cardExpiryTv .setText (getResources (). getString ( R . string . defaultCardExpiry ) );
824
+ cardExpiryTv .setText (defaultExpiry );
819
825
cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
820
826
}
821
- } else if ( editable . length () == 2 && lastInput . endsWith ( "/" )) {
822
- try {
823
- int month = Integer . parseInt ( input );
824
- if ( month <= 12 ) {
825
- cardExpiryTv . setText ( cardExpiryTv . getText (). toString (). substring ( 0 , 1 ));
826
- cardExpiryTv . setSelection ( cardExpiryTv . getText (). toString (). length ());
827
- } else {
828
- cardExpiryTv . setText ( getResources (). getString ( R . string . defaultCardExpiry ));
829
- cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ( ));
830
- }
831
- } catch ( NumberFormatException ex ) {
832
- cardExpiryTv .setText (input . replace ( "/" , "" ) );
827
+ }catch ( NumberFormatException ex ) {
828
+ cardExpiryTv . setText ( defaultExpiry );
829
+ cardExpiryTv . setSelection ( cardExpiryTv . getText (). toString (). length () );
830
+ }
831
+ } else if ( editable . length () == 2 && lastInput . endsWith ( "/" )) {
832
+ try {
833
+ int month = Integer . parseInt ( input );
834
+ if ( month <= 12 ) {
835
+ cardExpiryTv .setText (cardExpiryTv .getText ().toString ().substring ( 0 , 1 ));
836
+ cardExpiryTv . setSelection ( cardExpiryTv . getText (). toString (). length ());
837
+ } else {
838
+ cardExpiryTv .setText (defaultExpiry );
833
839
cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
834
- } catch (Resources .NotFoundException ex ) {
835
- ex .printStackTrace ();
836
840
}
841
+ } catch (NumberFormatException ex ) {
842
+ cardExpiryTv .setText (input .replace ("/" , "" ));
843
+ cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
844
+ }
837
845
838
- } else if (editable .length () == 1 ) {
846
+ } else if (editable .length () == 1 ) {
847
+ try {
839
848
int month = Integer .parseInt (input );
840
849
if (month > 1 ) {
841
- cardExpiryTv .setText ("0" + cardExpiryTv . getText (). toString () + "/" );
850
+ cardExpiryTv .setText (String . format ( getString ( R . string . formatted_expiry ), input ) );
842
851
cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
843
852
}
853
+ }catch (NumberFormatException ignored ){
854
+
844
855
}
845
856
}
846
857
0 commit comments