package com.example.shengwutanzhen;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class PhoneActivity extends AppCompatActivity {

    private TextView show_uuid_phone;

    private TextView show_gesture;

    private Button confirm_btn_phone;

    private RadioGroup radioGroup_phone;

    private String uuid;
    private String gesture;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone);
        initView();
        Bundle bundle = getIntent().getExtras();
        assert bundle != null;
        uuid = bundle.getString("uuid");
        gesture = bundle.getString("gesture");
        show_uuid_phone.setText(uuid);
        show_uuid_phone.setTextSize(25);
        show_uuid_phone.setTextColor(getResources().getColor(R.color.text_color));
        show_gesture.setText(gesture);
        show_gesture.setTextSize(25);
        show_gesture.setTextColor(getResources().getColor(R.color.text_color));
        if (gesture.equals("行走")) {
            findViewById(R.id.phone_laid_one_hand).setVisibility(View.GONE);
            findViewById(R.id.phone_laid_two_hand).setVisibility(View.GONE);
        }
        setListener();
    }

    private void initView(){
        show_uuid_phone = findViewById(R.id.show_uuid_phone);
        show_gesture = findViewById(R.id.show_gesture);
        confirm_btn_phone = findViewById(R.id.confirm_btn_phone);
        radioGroup_phone = findViewById(R.id.radioGroup_phone);
    }

    private void setListener(){
        confirm_btn_phone.setOnClickListener(view -> {
            int checkedId = radioGroup_phone.getCheckedRadioButtonId();
            RadioButton radioButton = findViewById(checkedId);
            String gesture_phone = radioButton.getText().toString();
            new AlertDialog.Builder(PhoneActivity.this)
                    .setTitle("提示")
                    .setMessage("您选择的动作是:"+gesture_phone)
                    .setPositiveButton("确定", (dialogInterface, i) -> {
                        Bundle bundle = new Bundle();
                        bundle.putString("gesture", gesture);
                        bundle.putString("uuid",uuid);
                        bundle.putString("gesture_phone", gesture_phone);
                        Intent intent = new Intent(PhoneActivity.this, ConfirmActivity.class);
                        intent.putExtras(bundle);
                        startActivity(intent);
                    })
                    .setNegativeButton("取消", (dialogInterface, i) -> {

                    })
                    .show();
        });
    }
}