Skip to content

Commit

Permalink
MOB-148 Added the ability to show loading indicator during processing (
Browse files Browse the repository at this point in the history
…#146)

- Added a method that provides a loading call back when the SDK is processing
	- Added implementation for when loading callback should be triggered.
	- Added sample in the sample activity
	- updated gradle file to use Maven.
  • Loading branch information
Peter-John-paystack authored Nov 30, 2022
1 parent a09250b commit a0ba7a0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
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

0 comments on commit a0ba7a0

Please sign in to comment.