package info.knacki.pass.ui.alertPrompt.views;

import android.content.Context;
import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.widget.LinearLayout;

public class TextEditAndCheckbox extends LinearLayout {
    private final AppCompatEditText fTextEdit;
    private final AppCompatCheckBox fCheckbox;

    public TextEditAndCheckbox(Context c) {
        super(c);
        setOrientation(VERTICAL);

        fTextEdit = new AppCompatEditText(c);
        addView(fTextEdit);

        fCheckbox = new AppCompatCheckBox(c);
        addView(fCheckbox);
    }

    public TextEditAndCheckbox setText(String str) {
        fTextEdit.setText(str);
        fTextEdit.setSelection(str.length());
        fTextEdit.requestFocus();
        return this;
    }

    public TextEditAndCheckbox setChecked(boolean value) {
        fCheckbox.setChecked(value);
        return this;
    }

    public TextEditAndCheckbox setCheckboxCaption(int textId) {
        fCheckbox.setText(textId);
        return this;
    }

    public String getStr() {
        Editable text = fTextEdit.getText();
        return null == text ? "" : text.toString().trim();
    }

    public boolean isChecked() {
        return fCheckbox.isChecked();
    }
}