9
9
import android .support .design .widget .TextInputLayout ;
10
10
import android .support .v4 .app .Fragment ;
11
11
import android .support .v7 .app .AlertDialog ;
12
+ import android .text .Html ;
12
13
import android .util .Log ;
13
14
import android .view .LayoutInflater ;
14
15
import android .view .View ;
15
16
import android .view .ViewGroup ;
17
+ import android .widget .AdapterView ;
16
18
import android .widget .ArrayAdapter ;
17
19
import android .widget .Button ;
18
20
import android .widget .Spinner ;
21
+ import android .widget .TextView ;
19
22
import android .widget .Toast ;
20
23
21
24
import com .flutterwave .raveandroid .Payload ;
@@ -42,6 +45,10 @@ public class GhMobileMoneyFragment extends Fragment implements GhMobileMoneyCont
42
45
private ProgressDialog pollingProgressDialog ;
43
46
GhMobileMoneyPresenter presenter ;
44
47
Spinner networkSpinner ;
48
+ TextView instructionsTv ;
49
+ TextInputEditText voucherEt ;
50
+ TextInputLayout voucherTil ;
51
+ String validateInstructions ;
45
52
46
53
@ Override
47
54
public View onCreateView (LayoutInflater inflater , ViewGroup container ,
@@ -56,6 +63,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
56
63
phoneEt = (TextInputEditText ) v .findViewById (R .id .rave_phoneEt );
57
64
phoneTil = (TextInputLayout ) v .findViewById (R .id .rave_phoneTil );
58
65
networkSpinner = (Spinner ) v .findViewById (R .id .rave_networkSpinner );
66
+ voucherEt = (TextInputEditText ) v .findViewById (R .id .rave_voucherEt );
67
+ voucherTil = (TextInputLayout ) v .findViewById (R .id .rave_voucherTil );
68
+ instructionsTv = (TextView ) v .findViewById (R .id .instructionsTv );
59
69
60
70
Button payButton = (Button ) v .findViewById (R .id .rave_payButton );
61
71
@@ -80,15 +90,67 @@ public void onClick(View v) {
80
90
adapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
81
91
networkSpinner .setAdapter (adapter );
82
92
93
+ final String vodafoneInstruction = getResources ().getString (R .string .vodafone_msg );
94
+ final String [] networks = getResources ().getStringArray (R .array .gh_mobile_money_networks );
95
+ final String mtnValidateInstruction = getResources ().getString (R .string .mtn_validate_instructions );
96
+ final String tigoValidateInstruction = getResources ().getString (R .string .tigo_validate_instructions );
97
+
98
+ networkSpinner .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
99
+ @ Override
100
+ public void onItemSelected (AdapterView <?> parent , View view , int position , long id ) {
101
+ if (position < networks .length ) {
102
+ String network = networks [position ];
103
+
104
+ if (position == 0 ) {
105
+ showInstructionsAndVoucher (false );
106
+ validateInstructions = "Checking transaction status. \n Please wait" ;
107
+ }
108
+
109
+ if (network .equalsIgnoreCase ("mtn" )) {
110
+ validateInstructions = mtnValidateInstruction ;
111
+ showInstructionsAndVoucher (false );
112
+ }
113
+ else if (network .equalsIgnoreCase ("tigo" )) {
114
+ validateInstructions = tigoValidateInstruction ;
115
+ showInstructionsAndVoucher (false );
116
+ }
117
+ else if (network .equalsIgnoreCase ("vodafone" )) {
118
+ validateInstructions = "Checking transaction status. \n Please wait" ;
119
+ showInstructionsAndVoucher (true );
120
+ instructionsTv .setText (Html .fromHtml (vodafoneInstruction ));
121
+ }
122
+ }
123
+ }
124
+
125
+ @ Override
126
+ public void onNothingSelected (AdapterView <?> parent ) {
127
+ showInstructionsAndVoucher (false );
128
+ }
129
+ });
130
+
83
131
return v ;
84
132
}
85
133
134
+ private void showInstructionsAndVoucher (boolean show ) {
135
+
136
+ if (show ) {
137
+ voucherTil .setVisibility (View .VISIBLE );
138
+ instructionsTv .setVisibility (View .VISIBLE );
139
+ }
140
+ else {
141
+ voucherTil .setVisibility (View .GONE );
142
+ instructionsTv .setVisibility (View .GONE );
143
+ }
144
+ }
145
+
86
146
private void clearErrors () {
87
147
amountTil .setError (null );
88
148
phoneTil .setError (null );
149
+ voucherTil .setError (null );
89
150
90
151
amountTil .setErrorEnabled (false );
91
152
phoneTil .setErrorEnabled (false );
153
+ voucherTil .setErrorEnabled (false );
92
154
93
155
}
94
156
@@ -100,6 +162,7 @@ private void validate() {
100
162
101
163
String amount = amountEt .getText ().toString ();
102
164
String phone = phoneEt .getText ().toString ();
165
+ String voucher = voucherEt .getText ().toString ();
103
166
104
167
try {
105
168
double amnt = Double .parseDouble (amount );
@@ -127,6 +190,11 @@ private void validate() {
127
190
showToast ("Select a network" );
128
191
}
129
192
193
+ if (voucherTil .getVisibility () == View .VISIBLE && voucher .length () == 0 ) {
194
+ valid = false ;
195
+ voucherTil .setError ("Enter a valid voucher code" );
196
+ }
197
+
130
198
if (valid ) {
131
199
132
200
ravePayInitializer .setAmount (Double .parseDouble (amount ));
@@ -145,6 +213,7 @@ private void validate() {
145
213
.setMeta (ravePayInitializer .getMeta ())
146
214
.setSubAccount (ravePayInitializer .getSubAccount ())
147
215
.setNetwork (network )
216
+ .setVoucher (voucher )
148
217
.setPhonenumber (phone )
149
218
.setPBFPubKey (ravePayInitializer .getPublicKey ())
150
219
.setDevice_fingerprint (Utils .getDeviceImei (getActivity ()));
@@ -160,8 +229,6 @@ private void validate() {
160
229
161
230
}
162
231
163
-
164
-
165
232
@ Override
166
233
public void showProgressIndicator (boolean active ) {
167
234
@@ -186,11 +253,12 @@ public void showPollingIndicator(boolean active) {
186
253
187
254
if (pollingProgressDialog == null ) {
188
255
pollingProgressDialog = new ProgressDialog (getActivity ());
189
- pollingProgressDialog .setMessage ("Checking transaction status. \n Please wait" );
256
+ pollingProgressDialog .setCanceledOnTouchOutside (false );
257
+ pollingProgressDialog .setMessage (Html .fromHtml (validateInstructions ));
190
258
}
191
259
192
260
if (active && !pollingProgressDialog .isShowing ()) {
193
- pollingProgressDialog .setButton (DialogInterface .BUTTON_NEGATIVE , "Cancel " , new DialogInterface .OnClickListener () {
261
+ pollingProgressDialog .setButton (DialogInterface .BUTTON_NEGATIVE , "CANCEL PAYMENT " , new DialogInterface .OnClickListener () {
194
262
@ Override
195
263
public void onClick (DialogInterface dialog , int which ) {
196
264
pollingProgressDialog .dismiss ();
@@ -266,6 +334,8 @@ public void showFetchFeeFailed(String s) {
266
334
267
335
@ Override
268
336
public void onPaymentFailed (String message , String responseAsJSONString ) {
337
+
338
+ if (pollingProgressDialog != null && !pollingProgressDialog .isShowing ()) { pollingProgressDialog .dismiss (); }
269
339
Intent intent = new Intent ();
270
340
intent .putExtra ("response" , responseAsJSONString );
271
341
if (getActivity () != null ) {
0 commit comments