package jp.gihyo.mitoma.android.p011login;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

public class MemberAction {
    private Activity act;
    private MemberDAO dao;
    public MemberAction(Activity act){
        this.act = act;
        this.dao = MemberDAO.getInstance((Context)act);
    }
    public boolean certification(){
        boolean ret = true;
        String message = "";
        EditText etId = act.findViewById(R.id.etId);
        EditText etPw = act.findViewById(R.id.etPw);
        TextView tvResult = act.findViewById(R.id.tvResult);
        String id = etId.getText().toString();
        String psw = etPw.getText().toString();
        MemberDTO dto = this.dao.select(id);
        if (dto == null) {
            message = act.getString(R.string.srcLoginFailure1);
            ret = false;
        }else if(!psw.equals(dto.password))   {
            message = act.getString(R.string.srcLoginFailure2);
            ret = false;
        }else{
            message = dto.memberName+"さん　"+act.getString(R.string.srcLoginSuccess);
        }
        tvResult.setText(message);
        //Toast.makeText(act, "承認完了 "+ message, Toast.LENGTH_LONG).show();
        return ret;
    }
}

