Skip to content

Commit 0d6e92e

Browse files
committed
refactor of codes and code uniformity
1 parent 61010f1 commit 0d6e92e

File tree

11 files changed

+479
-461
lines changed

11 files changed

+479
-461
lines changed

raveandroid/src/main/java/com/flutterwave/raveandroid/OTPFragment.java

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,75 @@
1515
/**
1616
* A simple {@link Fragment} subclass.
1717
*/
18-
public class OTPFragment extends Fragment {
18+
public class OTPFragment extends Fragment implements View.OnClickListener {
19+
1920
public static final String EXTRA_OTP = "extraOTP";
20-
public static final String EXTRA_CHARGE_MESSAGE = "extraChargeMessage";
21-
String otp;
21+
TextInputEditText otpEt;
22+
TextInputLayout otpTil;
23+
TextView chargeMessage;
2224
Button otpButton;
2325

26+
public static final String EXTRA_CHARGE_MESSAGE = "extraChargeMessage";
27+
View v;
28+
String otp;
2429

2530
public OTPFragment() {
2631
// Required empty public constructor
2732
}
2833

29-
3034
@Override
3135
public View onCreateView(LayoutInflater inflater, ViewGroup container,
3236
Bundle savedInstanceState) {
33-
// Inflate the layout for this fragment
34-
final View v = inflater.inflate(R.layout.fragment_ot, container, false);
35-
final TextInputLayout otpTil = (TextInputLayout) v.findViewById(R.id.otpTil);
36-
final TextInputEditText otpEt = (TextInputEditText) v.findViewById(R.id.otpEv);
37-
otpButton = (Button) v.findViewById(R.id.otpButton);
38-
TextView chargeMessage = (TextView) v.findViewById(R.id.otpChargeMessage);
39-
if(getArguments().containsKey(EXTRA_CHARGE_MESSAGE)){
40-
chargeMessage.setText(getArguments().getString(EXTRA_CHARGE_MESSAGE));
41-
}
42-
otpButton.setOnClickListener(new View.OnClickListener() {
43-
@Override
44-
public void onClick(View view) {
45-
otp = otpEt.getText().toString();
46-
47-
otpTil.setError(null);
48-
otpTil.setErrorEnabled(false);
49-
50-
if (otp.length() < 1) {
51-
otpTil.setError("Enter a valid one time password");
52-
} else {
53-
goBack();
54-
}
55-
}
56-
});
37+
38+
v = inflater.inflate(R.layout.fragment_ot, container, false);
39+
40+
initializeViews();
41+
42+
setChargeMessage();
43+
44+
setListeners();
5745

5846
return v;
5947
}
6048

49+
private void setListeners() {
50+
otpButton.setOnClickListener(this);
51+
}
52+
53+
private void initializeViews() {
54+
otpTil = v.findViewById(R.id.otpTil);
55+
otpEt = v.findViewById(R.id.otpEv);
56+
otpButton = v.findViewById(R.id.otpButton);
57+
chargeMessage = v.findViewById(R.id.otpChargeMessage);
58+
}
59+
60+
@Override
61+
public void onClick(View view) {
62+
int i = view.getId();
63+
if (i == R.id.otpButton) {
64+
clearErrors();
65+
otp = otpEt.getText().toString();
66+
if (otp.length() < 1) {
67+
otpTil.setError("Enter a valid one time password");
68+
} else {
69+
goBack();
70+
}
71+
}
72+
}
73+
74+
private void clearErrors() {
75+
otpTil.setErrorEnabled(false);
76+
otpTil.setError(null);
77+
}
78+
79+
private void setChargeMessage() {
80+
if (getArguments() != null) {
81+
if (getArguments().containsKey(EXTRA_CHARGE_MESSAGE)) {
82+
chargeMessage.setText(getArguments().getString(EXTRA_CHARGE_MESSAGE));
83+
}
84+
}
85+
}
86+
6187
public void goBack(){
6288
Intent intent = new Intent();
6389
intent.putExtra(EXTRA_OTP, otp);
@@ -68,5 +94,4 @@ public void goBack(){
6894
}
6995

7096

71-
7297
}

raveandroid/src/main/java/com/flutterwave/raveandroid/account/AccountContract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface View {
3333

3434
void onPaymentFailed(String status, String responseAsJSONString);
3535

36-
void onValidateSuccessful(String flwRef, String responseAsJSONString);
36+
void onValidationSuccessful(String flwRef, String responseAsJSONString);
3737

3838
void onValidateError(String message, String responseAsJSONString);
3939

0 commit comments

Comments
 (0)