Skip to content

Commit a0ba7a0

Browse files
MOB-148 Added the ability to show loading indicator during processing (#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.
1 parent a09250b commit a0ba7a0

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ buildscript {
1212
]
1313

1414
repositories {
15-
jcenter()
15+
mavenCentral()
1616
google()
1717
}
1818
dependencies {

example/src/main/java/co/paystack/example/MainActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ public void beforeValidate(Transaction transaction) {
211211
updateTextViews();
212212
}
213213

214+
@Override
215+
public void showLoading(Boolean isProcessing) {
216+
if (isProcessing) {
217+
Toast.makeText(MainActivity.this, "Processing...", Toast.LENGTH_LONG).show();
218+
}
219+
}
220+
214221
@Override
215222
public void onError(Throwable error, Transaction transaction) {
216223
// If an access code has expired, simply ask your server for a new one

paystack/src/main/java/co/paystack/android/Paystack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private interface BaseCallback {
8282
public interface TransactionCallback extends BaseCallback {
8383
void onSuccess(Transaction transaction);
8484
void beforeValidate(Transaction transaction);
85-
85+
void showLoading(Boolean isProcessing);
8686
void onError(Throwable error, Transaction transaction);
8787
}
8888

paystack/src/main/java/co/paystack/android/TransactionManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class TransactionManager {
6666
@Override
6767
public void onResponse(Call<TransactionApiResponse> call, Response<TransactionApiResponse> response) {
6868
handleApiResponse(response.body());
69+
transactionCallback.showLoading(false);
6970
}
7071

7172
@Override
@@ -166,6 +167,7 @@ private void chargeWithAvs(Address address) {
166167
HashMap<String, String> fields = address.toHashMap();
167168
fields.put("trans", transaction.getId());
168169
try {
170+
this.transactionCallback.showLoading(true);
169171
Call<TransactionApiResponse> call = apiService.submitCardAddress(fields);
170172
call.enqueue(serverCallback);
171173
} catch (Exception e) {
@@ -175,20 +177,23 @@ private void chargeWithAvs(Address address) {
175177
}
176178

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

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

188192
private void initiateChargeOnServer() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
189-
193+
this.transactionCallback.showLoading(true);
190194
Call<TransactionApiResponse> call = apiService.charge(chargeRequestBody.getParamsHashMap());
191195
call.enqueue(serverCallback);
196+
192197
}
193198

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

276281
private void notifyProcessingError(Throwable t) {
277282
setProcessingOff();
283+
transactionCallback.showLoading(false);
278284
transactionCallback.onError(t, transaction);
279285
}
280286

0 commit comments

Comments
 (0)