package br.com.bloder.blormlib;

import android.view.View;

import java.util.ArrayList;
import java.util.List;

import br.com.bloder.blormlib.validation.Validate;
import br.com.bloder.blormlib.validation.Validation;

/**
 * Created by bloder on 05/06/16.
 */
public class Blorm {

  public static class Builder {

    private List<Validate> validations;
    private View field;

    public Builder() {
      validations = new ArrayList<>();
    }

    public Builder field(View field) {
      this.field = field;
      return this;
    }

    public Builder is(Validate validation) {
      this.validations.add(validation);
      return this;
    }

    public Builder is(Validation validation) {
      validation.field = this.field;
      this.validations.add(validation.validate());
      return this;
    }

    public Builder is(String errorMessgae, Validation validation) {
      validation.field = this.field;
      validation.errorMessage = errorMessgae;
      this.validations.add(validation.validate());
      return this;
    }

    public void onSubmit(View submittedItem) {
      new Blorm(this.validations).onSubmitted();
    }
  }

  private List<Validate> validations;
  
  public Blorm(List<Validate> validations) {
    this.validations = validations;
  }

  private void onSubmitted() {
    for(Validate validate : validations) {
      if(!validate.validate()) {
        validate.onError();
      }
    }
  }
}

@@ -1075,24 +1075,152 @@
 ttedItem) %7B%0A
+      submittedItem.setOnClickListener(new View.OnClickListener() %7B%0A        @Override%0A        public void onClick(View v) %7B%0A    
       new Bl
@@ -1223,21 +1223,16 @@
 w Blorm(
-this.
 validati
@@ -1247,24 +1247,44 @@
 ubmitted();%0A
+        %7D%0A      %7D);%0A
     %7D%0A  %7D%0A%0A 

Add on click listener in on submit function