package com.example.jourdanrodrigues.controk;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

public abstract class BaseFragmentCreation extends BaseFragment{

    protected abstract Boolean errorInFields();
    protected abstract void initializeFields(View view);

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);

        initializeFields(view);

        return view;
    }

    protected void validateEmptyField(EditText editText) {
        editText.setError(editText.getText().toString().isEmpty() ? "Field cannot be empty!" : null);
    }

    protected void setEmptyFieldValidations(final EditText editText) {
        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) { validateEmptyField(editText); }
        });
        editText.addTextChangedListener(new TextValidator(editText) {
            @Override
            public void validate(EditText innerEditText) { validateEmptyField(innerEditText); }
        });
    }
}

@@ -255,16 +255,17 @@
 Fragment
+ 
 %7B%0A%0A    p
@@ -307,16 +307,17 @@
 elds();%0A
+%0A
     prot
@@ -1030,16 +1030,32 @@
 Focus) %7B
+%0A               
  validat
@@ -1068,32 +1068,44 @@
 Field(editText);
+%0A           
  %7D%0A        %7D);%0A 
@@ -1253,16 +1253,32 @@
 tText) %7B
+%0A               
  validat
@@ -1304,16 +1304,28 @@
 itText);
+%0A           
  %7D%0A     

Reformat base fragment creation file