package jp.gihyo.mitoma.android.s010901transition;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.ArrayList;

public class SubActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sub);
        ButtonClick onClick = new ButtonClick();
        Button btReg = findViewById(R.id.btRegist);
        btReg.setOnClickListener(onClick);
        Button btUpd = findViewById(R.id.btUpdate);
        btUpd.setOnClickListener(onClick);
        Button btDel = findViewById(R.id.btDelete);
        btDel.setOnClickListener(onClick);

        // 遷移元からの添付データ取得と表示
        Intent intent = getIntent();
        FriendsDTO dto = (FriendsDTO)intent.getSerializableExtra("dto");
        EditText etId = findViewById(R.id.etId);
        EditText etName = findViewById(R.id.etName);
        EditText etPhone = findViewById(R.id.etPhone);
        etId.setText(dto.id);
        etName.setText(dto.name);
        etPhone.setText(dto.phone);
    }
    private class ButtonClick implements View.OnClickListener{
        public void onClick(View view){
            // アクションに処理依頼
            FriendsAction action = new FriendsAction(SubActivity.this);
            action.exec(view);
            // アクティビティ消滅
            finish();
        }
    }
}