package jp.gihyo.mitoma.android.p026menu;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RadioGroup radioGroup = findViewById(R.id.rgApply);
        radioGroup.setOnCheckedChangeListener(new RadioButtonOnListener());
    }
    private class RadioButtonOnListener implements RadioGroup.OnCheckedChangeListener{
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            RadioButton rb = findViewById(checkedId);
            String tag = (String)rb.getTag();
            Toast.makeText(MainActivity.this,"選択: " + tag,Toast.LENGTH_SHORT).show();
            String actionString=null;
            switch(tag){
                case "T101":
                    actionString = "jp.gihyo.mitoma.hello_world.MAIN_VIEW";
                    break;
                case "T102":
                    actionString = "jp.gihyo.mitoma.login.MAIN_VIEW";
                    break;
                case "T103":
                    actionString = "jp.gihyo.mitoma.watchword.MAIN_VIEW";
                    break;
                case "T104":
                    actionString = "jp.gihyo.mitoma.gdplist_by_stub.MAIN_VIEW";
                    break;
                case "T105":
                    actionString = "jp.gihyo.mitoma.gdp_management.MAIN_VIEW";
                    break;
                case "T201":
                    actionString = "jp.gihyo.mitoma.widzets_test.MAIN_VIEW";
                    break;
                default:
                    break;

            }
            if(actionString != null){
                Intent intent = new Intent();
                intent.setAction(actionString);
                try{
                    startActivity(intent);
                }catch(ActivityNotFoundException e){
                    Toast.makeText(MainActivity.this,"遷移エラー " + tag,Toast.LENGTH_SHORT).show();
                }

            }
        }
    }
}