package org.deke.risk.riskahead.helper;

import android.content.Context;
import com.google.android.material.textfield.TextInputLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.TextView;

/**
 *
 * (C) Copyright 2016 RiskAhead (http://www.riskahead.net)
 * Developer & Contributor: Dennis Thießen (dennis.thiessen@riskahead.net)
 * Date of Release: 10.02.2016
 *
 */
public abstract class TextValidator implements TextWatcher {
    private final TextView textView;
    private final TextInputLayout textLayout;

    public TextValidator(TextView textView, TextInputLayout textLayout, Context context) {
        this.textView = textView;
        this.textLayout = textLayout;
    }

    public abstract void validate(TextView textView, TextInputLayout textLayout, String text);

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        String text = textView.getText().toString();
        validate(textView, textLayout, text);
    }
}
