package jp.gihyo.mitoma.android.p011login;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //自画面の生成
        setContentView(R.layout.login);
        //データベース初期化
        MemberDAO dao = MemberDAO.getInstance(this);
        ArrayList<MemberDTO> list = dao.select();
        // 初期データ(string-array.xml)を格納
        if(list.size() == 0) {
            String[] stringArray = getResources().getStringArray(R.array.member);
            for(String rec:stringArray) {
                String[] items = rec.split(",");
                MemberDTO dto = new MemberDTO(items[0],items[1],items[2]);
                dao.insert(dto);
            }
        }
        //ボタンへのイベントリスナーの登録
        Button button = findViewById(R.id.btLogin);
        button.setOnClickListener(new LoginListener());
    }

    private class LoginListener implements View.OnClickListener {
        public void onClick(View view) {
            MemberAction action =new MemberAction(LoginActivity.this);
            action.certification();
        }
    }
}