@@ -421,8 +421,10 @@ public void onPaymentError(String errorMessage) {
421421 @ Override
422422 public void collectCardPin (final Payload payload ) {
423423 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+ }
426428 }
427429
428430 @ Override
@@ -485,7 +487,9 @@ public void onSaveInstanceState(Bundle outState) {
485487 * @param message = text to display
486488 */
487489 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+ }
489493 }
490494
491495 /**
@@ -508,15 +512,19 @@ private void dismissDialog() {
508512 public void collectOtp (String flwRef , String message ) {
509513 this .flwRef = flwRef ;
510514 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+ }
513519 }
514520
515521 public void showOTPLayoutForSavedCard (Payload payload , String authInstruction ) {
516522 this .payLoad = payload ;
517523 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+ }
520528 }
521529
522530 @ Override
@@ -576,8 +584,10 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
576584 public void showWebPage (String authenticationUrl , String flwRef ) {
577585
578586 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+ }
581591 }
582592
583593 @ Override
@@ -774,19 +784,17 @@ public void onClick(DialogInterface dialog, int which) {
774784 public void collectCardAddressDetails (final Payload payload , String authModel ) {
775785 this .payLoad = payload ;
776786 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+ }
779791 }
780792
781793 private class ExpiryWatcher implements TextWatcher {
782794
783- private final Calendar calendar ;
784- private final SimpleDateFormat simpleDateFormat ;
785795 private String lastInput = "" ;
786796
787797 public ExpiryWatcher () {
788- calendar = Calendar .getInstance ();
789- simpleDateFormat = new SimpleDateFormat ("MM/yy" );
790798 }
791799
792800 @ Override
@@ -803,44 +811,47 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
803811 public void afterTextChanged (Editable editable ) {
804812 String input = editable .toString ();
805813 String cardExpiryToSet = cardExpiryTv .getText ().toString () + "/" ;
814+ String defaultExpiry = "12" ;
806815
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 ("/" )) {
812817
818+ try {
813819 int month = Integer .parseInt (input );
814820 if (month <= 12 ) {
815821 cardExpiryTv .setText (cardExpiryToSet );
816822 cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
817823 } else {
818- cardExpiryTv .setText (getResources (). getString ( R . string . defaultCardExpiry ) );
824+ cardExpiryTv .setText (defaultExpiry );
819825 cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
820826 }
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 );
833839 cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
834- } catch (Resources .NotFoundException ex ) {
835- ex .printStackTrace ();
836840 }
841+ } catch (NumberFormatException ex ) {
842+ cardExpiryTv .setText (input .replace ("/" , "" ));
843+ cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
844+ }
837845
838- } else if (editable .length () == 1 ) {
846+ } else if (editable .length () == 1 ) {
847+ try {
839848 int month = Integer .parseInt (input );
840849 if (month > 1 ) {
841- cardExpiryTv .setText ("0" + cardExpiryTv . getText (). toString () + "/" );
850+ cardExpiryTv .setText (String . format ( getString ( R . string . formatted_expiry ), input ) );
842851 cardExpiryTv .setSelection (cardExpiryTv .getText ().toString ().length ());
843852 }
853+ }catch (NumberFormatException ignored ){
854+
844855 }
845856 }
846857
0 commit comments