package com.example.administrator.zhapp.activity.ajhxcgl;

import android.content.DialogInterface;
import android.graphics.Color;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AlertDialog;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.example.administrator.zhapp.R;
import com.example.administrator.zhapp.activity.BaseActivity;
import com.example.administrator.zhapp.adapter.MyFragmentAdapter;
import com.example.administrator.zhapp.contans.Contans;
import com.example.administrator.zhapp.fragment.ajhxcgl.JsFragment;
import com.example.administrator.zhapp.fragment.ajhxcgl.XwaqgcglFragment;
import com.example.administrator.zhapp.utils.SPUtils;
import com.example.administrator.zhapp.weight.AutoRadioGroup;
import com.example.administrator.zhapp.weight.NoscrollViewPager;
import java.util.ArrayList;
import java.util.List;

/**
 * 安健环巡查管理-行为安全观察管理详情
 */

public class AxwaqgcglDetaliActivity extends BaseActivity {

    NoscrollViewPager vp_centent;
    RadioButton rb1;
    RadioButton rb2;
    AutoRadioGroup rg;
    private XwaqgcglFragment xwaq;
    private JsFragment js;
    private List<Fragment> list;
    private MyFragmentAdapter adapter;

    private String code;
    private boolean nfcorewm;

    private String xwjljsid;


    @Override
    public int getContentViewID() {
        return R.layout.activity_axwaqgcgl_detali;
    }

    protected void initView() {
        vp_centent = findViewById(R.id.vp_centent);
        rb1 = findViewById(R.id.rb1);
        rb2 = findViewById(R.id.rb2);
        rg = findViewById(R.id.rg);
    }

    public void initData() {

        code = getIntent().getExtras().getString(Contans.KEY_BQBM);
        nfcorewm = getIntent().getExtras().getBoolean(Contans.NFCOREWM);

        setTitle("行为安全观察管理");
//        setBack();

        setBackl();

        xwjljsid = (String) SPUtils.get(context, Contans.USERNAME, "") + System.currentTimeMillis();


        xwaq = XwaqgcglFragment.newInstance(code, nfcorewm,xwjljsid);
        js = JsFragment.newInstance(code, nfcorewm, false, "",xwjljsid);
        list = new ArrayList<>();
        list.add(xwaq);
        list.add(js);
        adapter = new MyFragmentAdapter(getSupportFragmentManager(), list);
        vp_centent.setAdapter(adapter);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.rb1) {
                    vp_centent.setCurrentItem(0, false);
                    title.setText("行为安全观察管理");
                    rb1.setTextColor(Color.WHITE);
                    rb2.setTextColor(Color.GRAY);
                } else if (i == R.id.rb2) {
                    vp_centent.setCurrentItem(1, false);
                    title.setText("不安全记录");
                    rb2.setTextColor(Color.WHITE);
                    rb1.setTextColor(Color.GRAY);
                }
            }
        });
    }

    private void setBackl() {

        mToolbar.setNavigationIcon(R.mipmap.back);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setTitle("警告");
                builder.setMessage("退出之后需要重新扫描区域，你确定退出吗？");
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                });
                builder.create().show();
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {

            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("警告");
            builder.setMessage("退出之后需要重新扫描区域，你确定退出吗？");
            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
            builder.create().show();

            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


}
