package jp.gihyo.mitoma.android.p014gdpmanagement;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SubActivity extends AppCompatActivity {
    private static final String TAG ="SubActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sub);
        // ボタンにリスナーをセット
        ButtonClick onClick = new ButtonClick();
        Button btReg = findViewById(R.id.btRegister);
        btReg.setOnClickListener(onClick);
        Button btUpd = findViewById(R.id.btUpdate);
        btUpd.setOnClickListener(onClick);
        Button btDel = findViewById(R.id.btDelete);
        btDel.setOnClickListener(onClick);
        // インテント受取との取出し
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            int cNo = bundle.getInt("cNo");
            String name = bundle.getString("name");
            Double gdp = bundle.getDouble("gdp");
            Double pop = bundle.getDouble("pop");
            //Log.d(TAG, "受信DTO:" + cNo + " " + name + " " + gdp);
            EditText etCno = findViewById(R.id.etCno);
            EditText etCname = findViewById(R.id.etCname);
            EditText etGDP = findViewById(R.id.etGDP);
            EditText etPop = findViewById(R.id.etPop);
            etCno.setText(String.valueOf(cNo));
            etCname.setText(name);
            etGDP.setText(String.valueOf(gdp));
            etPop.setText(String.valueOf(pop));
        }
    }
    private class ButtonClick implements View.OnClickListener{
        public void onClick(View view){
            // アクションへの処理依頼
            CountryAction action = new CountryAction(SubActivity.this);
            action.exec(view);
            // アプリ停止
            finish();
        }
    }
}