Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/fix exception crash #302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ public void onGetBanksRequestFailed(String message) {
public void collectOtp(String publicKey, String flutterwaveReference, String validateInstruction) {
this.flwRef = flutterwaveReference;

new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showOtpScreen(validateInstruction);
if (isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showOtpScreen(validateInstruction);
}
}

@Override
Expand All @@ -424,8 +426,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public void displayInternetBankingPage(String authurl, String flwRef) {
this.flwRef = flwRef;
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authurl);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ public void showRedirectMessage(boolean active) {

@Override
public void showWebView(String authUrl, String flwRef) {

new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authUrl);
if (isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authUrl);
}
}

private void dismissDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ public void showFetchFeeFailed(String message) {
public void loadBarterCheckout(String authUrlCrude, String flwRef) {

this.flwRef = flwRef;
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showBarterCheckoutScreen(authUrlCrude, flwRef);
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showBarterCheckoutScreen(authUrlCrude, flwRef);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,10 @@ public void onPaymentError(String errorMessage) {
@Override
public void collectCardPin(final Payload payload) {
this.payLoad = payload; //added so as to get back in onActivityResult
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showPinScreen();
if (isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showPinScreen();
}
}

@Override
Expand Down Expand Up @@ -485,7 +487,9 @@ public void onSaveInstanceState(Bundle outState) {
* @param message = text to display
*/
public void showToast(String message) {
Toast.makeText(requireContext(), message+"", Toast.LENGTH_SHORT).show();
if(isAdded()){
Toast.makeText(requireContext(), message+"", Toast.LENGTH_SHORT).show();
}
}

/**
Expand All @@ -508,15 +512,19 @@ private void dismissDialog() {
public void collectOtp(String flwRef, String message) {
this.flwRef = flwRef;
dismissDialog();
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showOtpScreen(message);
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showOtpScreen(message);
}
}

public void showOTPLayoutForSavedCard(Payload payload, String authInstruction) {
this.payLoad = payload;
dismissDialog();
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showOtpScreenForSavedCard(authInstruction);
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showOtpScreenForSavedCard(authInstruction);
}
}

@Override
Expand Down Expand Up @@ -576,8 +584,10 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
public void showWebPage(String authenticationUrl, String flwRef) {

this.flwRef = flwRef;
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
}
}

@Override
Expand Down Expand Up @@ -774,19 +784,17 @@ public void onClick(DialogInterface dialog, int which) {
public void collectCardAddressDetails(final Payload payload, String authModel) {
this.payLoad = payload;
this.authModel = authModel;
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showAddressScreen();
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showAddressScreen();
}
}

private class ExpiryWatcher implements TextWatcher {

private final Calendar calendar;
private final SimpleDateFormat simpleDateFormat;
private String lastInput = "";

public ExpiryWatcher() {
calendar = Calendar.getInstance();
simpleDateFormat = new SimpleDateFormat("MM/yy");
}

@Override
Expand All @@ -803,44 +811,47 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
public void afterTextChanged(Editable editable) {
String input = editable.toString();
String cardExpiryToSet = cardExpiryTv.getText().toString() + "/";
String defaultExpiry = "12";

try {
calendar.setTime(simpleDateFormat.parse(input));
} catch (ParseException e) {

if (editable.length() == 2 && !lastInput.endsWith("/")) {
if (editable.length() == 2 && !lastInput.endsWith("/")) {

try {
int month = Integer.parseInt(input);
if (month <= 12) {
cardExpiryTv.setText(cardExpiryToSet);
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
} else {
cardExpiryTv.setText(getResources().getString(R.string.defaultCardExpiry));
cardExpiryTv.setText(defaultExpiry);
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
}
} else if (editable.length() == 2 && lastInput.endsWith("/")) {
try {
int month = Integer.parseInt(input);
if (month <= 12) {
cardExpiryTv.setText(cardExpiryTv.getText().toString().substring(0, 1));
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
} else {
cardExpiryTv.setText(getResources().getString(R.string.defaultCardExpiry));
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
}
} catch (NumberFormatException ex) {
cardExpiryTv.setText(input.replace("/", ""));
}catch (NumberFormatException ex){
cardExpiryTv.setText(defaultExpiry);
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
}
} else if (editable.length() == 2 && lastInput.endsWith("/")) {
try {
int month = Integer.parseInt(input);
if (month <= 12) {
cardExpiryTv.setText(cardExpiryTv.getText().toString().substring(0, 1));
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
} else {
cardExpiryTv.setText(defaultExpiry);
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
} catch (Resources.NotFoundException ex) {
ex.printStackTrace();
}
} catch (NumberFormatException ex) {
cardExpiryTv.setText(input.replace("/", ""));
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
}

} else if (editable.length() == 1) {
} else if (editable.length() == 1) {
try {
int month = Integer.parseInt(input);
if (month > 1) {
cardExpiryTv.setText("0" + cardExpiryTv.getText().toString() + "/");
cardExpiryTv.setText(String.format(getString(R.string.formatted_expiry), input));
cardExpiryTv.setSelection(cardExpiryTv.getText().toString().length());
}
}catch (NumberFormatException ignored){

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ public void showProgressIndicator(boolean active) {
public void showWebPage(String authenticationUrl, String flwRef) {

this.flwRef = flwRef;
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl,flwRef);
if (isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl,flwRef);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ public void showWebPage(String authenticationUrl
) {

// this.flwRef = flwRef;
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ public void showToast(String message) {

@Override
public void showWebPage(String authenticationUrl) {
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
if (isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ public void showPollingIndicator(boolean active) {
@Override
public void showWebView(String authUrl, String flwRef){
this.flwRef = flwRef;
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authUrl);
if (isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authUrl);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ public void showToast(String message) {

@Override
public void showWebPage(String authenticationUrl) {
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ public void showToast(String message) {

@Override
public void showWebPage(String authenticationUrl) {
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
if(isAdded()){
new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme())
.showWebpageVerificationScreen(authenticationUrl);
}
}

@Override
Expand Down
1 change: 1 addition & 0 deletions rave_android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,6 @@
<string name="please_select_a_card">Please select a card</string>
<string name="barter_funding">Barter Funding</string>
<string name="verifying_transaction">Verifying transaction...</string>
<string name="formatted_expiry">0%1$s/</string>

</resources>