@@ -57,7 +57,6 @@ public class BankTransferFragment extends Fragment implements BankTransferContra
5757 private ProgressDialog progressDialog ;
5858 private ProgressDialog pollingProgressDialog ;
5959 BankTransferPresenter presenter ;
60- boolean canShowPollingIndicator = false ;
6160
6261 public BankTransferFragment () {
6362 // Required empty public constructor
@@ -81,32 +80,25 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
8180
8281 presenter .init (ravePayInitializer );
8382
84- double amountToPay = ravePayInitializer .getAmount ();
85-
86- if (amountToPay > 0 ) {
87- amountTil .setVisibility (GONE );
88- amountEt .setText (String .valueOf (amountToPay ));
89- }
90-
9183 return v ;
9284 }
9385
9486 private void setListeners () {
95- payButton .setOnClickListener (this );
87+ payButton .setOnClickListener (this );
9688 verifyPaymentButton .setOnClickListener (this );
9789
9890 }
9991
10092 @ Override
10193 public void onClick (View view ) {
102- int i = view .getId ();
103- if (i == payButton .getId ()) {
94+ int viewId = view .getId ();
95+ if (viewId == payButton .getId ()) {
10496 clearErrors ();
10597 Utils .hide_keyboard (getActivity ());
10698 collectData ();
10799 }
108100
109- if ( i == verifyPaymentButton .getId ()){
101+ if ( viewId == verifyPaymentButton .getId ()) {
110102 verifyPayment ();
111103 }
112104 }
@@ -155,23 +147,11 @@ public void showFieldError(int viewID, String message, Class<?> viewType) {
155147
156148
157149 private void verifyPayment () {
158- canShowPollingIndicator = true ;
159150 showPollingIndicator (true );
160- presenter .setRequeryCountdownTime ( System . currentTimeMillis () );
151+ presenter .startPaymentVerification ( );
161152
162153 }
163154
164- @ Override
165- public void onPollingRoundComplete (String flwRef , String txRef , String publicKey ) {
166-
167- if (canShowPollingIndicator ) {
168- if (pollingProgressDialog != null && pollingProgressDialog .isShowing ()) {
169- presenter .requeryTx (flwRef , txRef , publicKey );
170- }
171- } else presenter .requeryTx (flwRef , txRef , publicKey );
172-
173-
174- }
175155
176156 @ Override
177157 public void showPollingIndicator (boolean active ) {
@@ -180,27 +160,25 @@ public void showPollingIndicator(boolean active) {
180160 return ;
181161 }
182162
183- if (canShowPollingIndicator ) {
184- if (pollingProgressDialog == null ) {
185- pollingProgressDialog = new ProgressDialog (getActivity ());
186- pollingProgressDialog .setMessage ("Checking transaction status. \n Please wait" );
187- }
163+ if (pollingProgressDialog == null ) {
164+ pollingProgressDialog = new ProgressDialog (getActivity ());
165+ pollingProgressDialog .setMessage ("Checking transaction status. \n Please wait" );
166+ }
188167
189- if (active && !pollingProgressDialog .isShowing ()) {
190- pollingProgressDialog .setButton (DialogInterface .BUTTON_NEGATIVE , "Cancel" , new DialogInterface .OnClickListener () {
191- @ Override
192- public void onClick (DialogInterface dialog , int which ) {
193- pollingProgressDialog .dismiss ();
194- }
195- });
196-
197- pollingProgressDialog .show ();
198- } else if (active && pollingProgressDialog .isShowing ()) {
199- //pass
200- } else {
201- pollingProgressDialog .dismiss ();
202- }
168+ if (active && !pollingProgressDialog .isShowing ()) {
169+ pollingProgressDialog .setButton (DialogInterface .BUTTON_NEGATIVE , "Cancel" , new DialogInterface .OnClickListener () {
170+ @ Override
171+ public void onClick (DialogInterface dialog , int which ) {
172+ pollingProgressDialog .dismiss ();
173+ }
174+ });
175+ pollingProgressDialog .show ();
176+ } else if (active && pollingProgressDialog .isShowing ()) {
177+ //pass
178+ } else {
179+ pollingProgressDialog .dismiss ();
203180 }
181+
204182 }
205183
206184 private void clearErrors () {
@@ -289,66 +267,24 @@ public void showToast(String message) {
289267
290268 @ Override
291269 public void onPaymentSuccessful (String status , String flwRef , final String responseAsString ) {
270+ Intent intent = new Intent ();
271+ intent .putExtra ("response" , responseAsString );
292272
293- if (canShowPollingIndicator ) { //Verify payment button has been clicked previously
294- Intent intent = new Intent ();
295- intent .putExtra ("response" , responseAsString );
296-
297- if (getActivity () != null ) {
298- getActivity ().setResult (RavePayActivity .RESULT_SUCCESS , intent );
299- getActivity ().finish ();
300- }
301- } else {
302- verifyPaymentButton .setText (getString (R .string .proceed ));
303- transferStatusTv .setText (getString (R .string .transfer_received_successfully ));
304- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
305- transferStatusTv .setCompoundDrawablesWithIntrinsicBounds (R .drawable .ic_check_circle_black_24dp , 0 , 0 , 0 );
306- } else transferStatusTv .setTextColor (Color .parseColor ("#4BB543" ));
307- transferStatusTv .setVisibility (View .VISIBLE );
308-
309- verifyPaymentButton .setOnClickListener (new View .OnClickListener () {
310- @ Override
311- public void onClick (View view ) {
312- Intent intent = new Intent ();
313- intent .putExtra ("response" , responseAsString );
314-
315- if (getActivity () != null ) {
316- getActivity ().setResult (RavePayActivity .RESULT_SUCCESS , intent );
317- getActivity ().finish ();
318- }
319- }
320- });
273+ if (getActivity () != null ) {
274+ getActivity ().setResult (RavePayActivity .RESULT_SUCCESS , intent );
275+ getActivity ().finish ();
321276 }
322277 }
323278
324279 @ Override
325280 public void onPaymentFailed (String message , final String responseAsJSONString ) {
326- if (canShowPollingIndicator ) {// Verify Payment button has been clicked
327- Intent intent = new Intent ();
328- intent .putExtra ("response" , responseAsJSONString );
329- if (getActivity () != null ) {
330- getActivity ().setResult (RavePayActivity .RESULT_ERROR , intent );
331- getActivity ().finish ();
332- }
333- } else {
334- transferStatusTv .setText (getString (R .string .payment_failed ));
335- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
336- transferStatusTv .setCompoundDrawablesWithIntrinsicBounds (R .drawable .ic_error_black_24dp , 0 , 0 , 0 );
337- } else transferStatusTv .setTextColor (Color .parseColor ("#FC100D" ));
338- transferStatusTv .setVisibility (View .VISIBLE );
339- verifyPaymentButton .setText (getString (R .string .back_to_app ));
340- verifyPaymentButton .setOnClickListener (new View .OnClickListener () {
341- @ Override
342- public void onClick (View view ) {
343- Intent intent = new Intent ();
344- intent .putExtra ("response" , responseAsJSONString );
345- if (getActivity () != null ) {
346- getActivity ().setResult (RavePayActivity .RESULT_ERROR , intent );
347- getActivity ().finish ();
348- }
349- }
350- });
281+ Intent intent = new Intent ();
282+ intent .putExtra ("response" , responseAsJSONString );
283+ if (getActivity () != null ) {
284+ getActivity ().setResult (RavePayActivity .RESULT_ERROR , intent );
285+ getActivity ().finish ();
351286 }
287+
352288 }
353289
354290 @ Override
@@ -387,4 +323,9 @@ public void onValidationSuccessful(HashMap<String, ViewObject> dataHashMap) {
387323
388324 }
389325
326+ @ Override
327+ public void onAmountValidationFailed () {
328+ amountTil .setVisibility (View .VISIBLE );
329+ }
330+
390331}
0 commit comments