package jp.gihyo.mitoma.android.lesson01_04;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;

public class MemberActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText etMemId;       //ID
    private EditText etMemName;     //氏名
    private EditText etMemBirthday;
    private RadioGroup rdMemGender;
    private RadioButton edMale;
    private RadioButton edFemale;
    private Spinner spMemOccupation;
    private CheckBox cbJustMe;
    private CheckBox cbFamily;
    private CheckBox cbUseless;
    private Button btEntry;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.member_regist);
        //ウィジェットオブジェクト(画面を構成する部品)の取得
        this.etMemId = findViewById(R.id.et_id);
        this.etMemName = findViewById(R.id.et_name);
        this.etMemBirthday = findViewById(R.id.et_birthday);
        this.rdMemGender = findViewById(R.id.radioGroup);
        this.edMale = findViewById(R.id.rb_male);
        this.edFemale = findViewById(R.id.rb_female);
        this.spMemOccupation = findViewById(R.id.sp_occup);
        this.cbJustMe = findViewById(R.id.cb_just_me);
        this.cbFamily = findViewById(R.id.cb_family);
        this.cbUseless = findViewById(R.id.cb_useless);
        this.btEntry = findViewById(R.id.bt_entry);

        //リスナーの登録
        this.btEntry.setOnClickListener(this);

    }
    //登録ボタン押下のリスナー
    @Override
    public void onClick(View view){
        //ガジェット(画面の各部品)からの入力データを取得
        //エジットテキストからの入力
        String memId = this.etMemId.getText().toString();
        String memName = this.etMemName.getText().toString();
        String memBirthday = this.etMemBirthday.getText().toString();
        //ラジオボタンからの入力
        Integer memGender= 0;
        if(this.edMale.isChecked()){
              memGender = 1;
        }else if(this.edFemale.isChecked()){
              memGender = 2;
        }
        //スピナーからの入力
        String memOccupation = this.spMemOccupation.getSelectedItem().toString();
        //チェックボックスからの入力
        String[] memComunication = {"0","0","0"};
        if(this.cbJustMe.isChecked()) memComunication[0] = "1";
        if(this.cbFamily.isChecked()) memComunication[1] = "1";
        if(this.cbUseless.isChecked()) memComunication[2] = "1";
        Toast.makeText(getApplicationContext(),"山田花子さんを登録しました",Toast.LENGTH_LONG).show();
        //確認
        Log.i("入力",memId + "," + memName + "," + memBirthday + "," + memGender + "," +
                memOccupation + "," + memComunication[0]+memComunication[1]+memComunication[2]);

    }
}