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

MOB-148 Added the ability to show loading indicator during processing #146

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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
]

repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
Expand Down
7 changes: 7 additions & 0 deletions example/src/main/java/co/paystack/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ public void beforeValidate(Transaction transaction) {
updateTextViews();
}

@Override
public void showLoading(Boolean isProcessing) {
if (isProcessing) {
Toast.makeText(MainActivity.this, "Processing...", Toast.LENGTH_LONG).show();
}
}

@Override
public void onError(Throwable error, Transaction transaction) {
// If an access code has expired, simply ask your server for a new one
Expand Down
2 changes: 1 addition & 1 deletion paystack/src/main/java/co/paystack/android/Paystack.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private interface BaseCallback {
public interface TransactionCallback extends BaseCallback {
void onSuccess(Transaction transaction);
void beforeValidate(Transaction transaction);

void showLoading(Boolean isProcessing);
void onError(Throwable error, Transaction transaction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TransactionManager {
@Override
public void onResponse(Call<TransactionApiResponse> call, Response<TransactionApiResponse> response) {
handleApiResponse(response.body());
transactionCallback.showLoading(false);
}

@Override
Expand Down Expand Up @@ -166,6 +167,7 @@ private void chargeWithAvs(Address address) {
HashMap<String, String> fields = address.toHashMap();
fields.put("trans", transaction.getId());
try {
this.transactionCallback.showLoading(true);
Call<TransactionApiResponse> call = apiService.submitCardAddress(fields);
call.enqueue(serverCallback);
} catch (Exception e) {
Expand All @@ -175,20 +177,23 @@ private void chargeWithAvs(Address address) {
}

private void validateChargeOnServer() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
this.transactionCallback.showLoading(true);
HashMap<String, String> params = validateRequestBody.getParamsHashMap();
Call<TransactionApiResponse> call = apiService.validateCharge(params);
call.enqueue(serverCallback);
}

private void reQueryChargeOnServer() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
this.transactionCallback.showLoading(true);
Call<TransactionApiResponse> call = apiService.requeryTransaction(transaction.getId());
call.enqueue(serverCallback);
}

private void initiateChargeOnServer() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {

this.transactionCallback.showLoading(true);
Call<TransactionApiResponse> call = apiService.charge(chargeRequestBody.getParamsHashMap());
call.enqueue(serverCallback);

}

private void handleApiResponse(TransactionApiResponse transactionApiResponse) {
Expand Down Expand Up @@ -275,6 +280,7 @@ public void onTick(long millisUntilFinished) {

private void notifyProcessingError(Throwable t) {
setProcessingOff();
transactionCallback.showLoading(false);
transactionCallback.onError(t, transaction);
}

Expand Down