11package com.oneclickaway.opensource.validation.model
22
33import android.os.AsyncTask
4+ import android.util.Log
45import android.view.View
56import android.view.ViewGroup
67import android.widget.EditText
78import com.oneclickaway.opensource.validation.interfaces.OnResponseListener
9+ import java.util.stream.IntStream
810
911class FormValidator {
1012
1113 /* optional arrays*/
12- fun isFormValidated (showErrors : Boolean , onResponseListener : OnResponseListener , viewGroup : ViewGroup , optionalParams : Array < Int > ? ){
14+ fun isFormValidated (showErrors : Boolean , onResponseListener : OnResponseListener , viewGroup : ViewGroup , optionalParams : IntArray = intArrayOf() ){
1315 ValidateForm (optionalParams = optionalParams, showErrors = showErrors, onResponseListener = onResponseListener).execute(viewGroup)
1416 }
1517}
1618
17- private class ValidateForm (var optionalParams : Array < Int > ? , var showErrors : Boolean , var onResponseListener : OnResponseListener ) : AsyncTask<ViewGroup, View, Void>() {
19+ private class ValidateForm (var showErrors : Boolean , var onResponseListener : OnResponseListener , var optionalParams : IntArray ) : AsyncTask<ViewGroup, View, Void>() {
1820
1921 var isFormFilled: Boolean = true
2022
@@ -29,7 +31,6 @@ private class ValidateForm (var optionalParams:Array<Int>? , var showErrors: Bo
2931 isFormFilled = false
3032 }
3133
32-
3334 override fun onPostExecute (aVoid : Void ? ) {
3435 super .onPostExecute(aVoid)
3536 onResponseListener.onResponse(isFormFilled)
@@ -38,9 +39,18 @@ private class ValidateForm (var optionalParams:Array<Int>? , var showErrors: Bo
3839 fun checkIfFieldLeftBlank (v : ViewGroup ) {
3940 for (i in 0 until v.childCount) {
4041 if (v.getChildAt(i) is EditText ) {
41- // v.getChildAt(i).id != optionalParams.
42- if ((v.getChildAt(i) as EditText ). text.toString().isEmpty() ) {
42+ if (( v.getChildAt(i) as EditText ).text.toString().isEmpty() && ! ( optionalParams.contains(v.getChildAt(i).id))) {
43+ /* edit text is empty */
4344 publishProgress(v.getChildAt(i))
45+ /* for(j in 0 until optionalParams!!.size){
46+ if (v.getChildAt(i).id == optionalParams!![j]){
47+ isOptional = true
48+ }
49+ if (!isOptional){
50+ isOptional = false
51+
52+ }
53+ }*/
4454 }
4555 } else if (v.getChildAt(i) is ViewGroup ) {
4656 checkIfFieldLeftBlank(v.getChildAt(i) as ViewGroup )
0 commit comments