99import android .support .design .widget .TextInputLayout ;
1010import android .support .v4 .app .Fragment ;
1111import android .support .v7 .app .AlertDialog ;
12+ import android .text .Html ;
1213import android .util .Log ;
1314import android .view .LayoutInflater ;
1415import android .view .View ;
1516import android .view .ViewGroup ;
17+ import android .widget .AdapterView ;
1618import android .widget .ArrayAdapter ;
1719import android .widget .Button ;
1820import android .widget .Spinner ;
21+ import android .widget .TextView ;
1922import android .widget .Toast ;
2023
2124import com .flutterwave .raveandroid .Payload ;
@@ -42,6 +45,10 @@ public class GhMobileMoneyFragment extends Fragment implements GhMobileMoneyCont
4245 private ProgressDialog pollingProgressDialog ;
4346 GhMobileMoneyPresenter presenter ;
4447 Spinner networkSpinner ;
48+ TextView instructionsTv ;
49+ TextInputEditText voucherEt ;
50+ TextInputLayout voucherTil ;
51+ String validateInstructions ;
4552
4653 @ Override
4754 public View onCreateView (LayoutInflater inflater , ViewGroup container ,
@@ -56,6 +63,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
5663 phoneEt = (TextInputEditText ) v .findViewById (R .id .rave_phoneEt );
5764 phoneTil = (TextInputLayout ) v .findViewById (R .id .rave_phoneTil );
5865 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 );
5969
6070 Button payButton = (Button ) v .findViewById (R .id .rave_payButton );
6171
@@ -80,15 +90,67 @@ public void onClick(View v) {
8090 adapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
8191 networkSpinner .setAdapter (adapter );
8292
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+
83131 return v ;
84132 }
85133
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+
86146 private void clearErrors () {
87147 amountTil .setError (null );
88148 phoneTil .setError (null );
149+ voucherTil .setError (null );
89150
90151 amountTil .setErrorEnabled (false );
91152 phoneTil .setErrorEnabled (false );
153+ voucherTil .setErrorEnabled (false );
92154
93155 }
94156
@@ -100,6 +162,7 @@ private void validate() {
100162
101163 String amount = amountEt .getText ().toString ();
102164 String phone = phoneEt .getText ().toString ();
165+ String voucher = voucherEt .getText ().toString ();
103166
104167 try {
105168 double amnt = Double .parseDouble (amount );
@@ -127,6 +190,11 @@ private void validate() {
127190 showToast ("Select a network" );
128191 }
129192
193+ if (voucherTil .getVisibility () == View .VISIBLE && voucher .length () == 0 ) {
194+ valid = false ;
195+ voucherTil .setError ("Enter a valid voucher code" );
196+ }
197+
130198 if (valid ) {
131199
132200 ravePayInitializer .setAmount (Double .parseDouble (amount ));
@@ -145,6 +213,7 @@ private void validate() {
145213 .setMeta (ravePayInitializer .getMeta ())
146214 .setSubAccount (ravePayInitializer .getSubAccount ())
147215 .setNetwork (network )
216+ .setVoucher (voucher )
148217 .setPhonenumber (phone )
149218 .setPBFPubKey (ravePayInitializer .getPublicKey ())
150219 .setDevice_fingerprint (Utils .getDeviceImei (getActivity ()));
@@ -160,8 +229,6 @@ private void validate() {
160229
161230 }
162231
163-
164-
165232 @ Override
166233 public void showProgressIndicator (boolean active ) {
167234
@@ -186,11 +253,12 @@ public void showPollingIndicator(boolean active) {
186253
187254 if (pollingProgressDialog == null ) {
188255 pollingProgressDialog = new ProgressDialog (getActivity ());
189- pollingProgressDialog .setMessage ("Checking transaction status. \n Please wait" );
256+ pollingProgressDialog .setCanceledOnTouchOutside (false );
257+ pollingProgressDialog .setMessage (Html .fromHtml (validateInstructions ));
190258 }
191259
192260 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 () {
194262 @ Override
195263 public void onClick (DialogInterface dialog , int which ) {
196264 pollingProgressDialog .dismiss ();
@@ -266,6 +334,8 @@ public void showFetchFeeFailed(String s) {
266334
267335 @ Override
268336 public void onPaymentFailed (String message , String responseAsJSONString ) {
337+
338+ if (pollingProgressDialog != null && !pollingProgressDialog .isShowing ()) { pollingProgressDialog .dismiss (); }
269339 Intent intent = new Intent ();
270340 intent .putExtra ("response" , responseAsJSONString );
271341 if (getActivity () != null ) {
0 commit comments