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

import android.graphics.Color;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.example.administrator.zhapp.DBModel.XfDjjhRwqy;
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.XcjsFragment;
import com.example.administrator.zhapp.fragment.xfbwxcgl.FhmaqckDetaliFragment;
import com.example.administrator.zhapp.weight.AutoRadioGroup;
import com.example.administrator.zhapp.weight.NoscrollViewPager;
import java.util.ArrayList;
import java.util.List;

/**
 * 消防保卫巡查管理-防火门及安全出口灯详情
 */
public class XfhmAqckdDetaliActivity extends BaseActivity {

    NoscrollViewPager vp;
    RadioButton rb1;
    RadioButton rb2;
    AutoRadioGroup rg;

    private ArrayList<XfDjjhRwqy> fhms;
    private int item;

    private FhmaqckDetaliFragment fhm;
    private XcjsFragment xcjs;
    private List<Fragment> list;
    private MyFragmentAdapter adapter;

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();
    }

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

    public void initData() {

        setTitle("防火门及安全出口灯");
        setBack();

        list = new ArrayList<>();
        fhms = new ArrayList<>();
        fhms = getIntent().getParcelableArrayListExtra("list");
        item = getIntent().getExtras().getInt("item");

        fhm = FhmaqckDetaliFragment.newInstance(fhms,item);
        xcjs = XcjsFragment.newInstance(true, Contans.FHMFRG);
        list.add(fhm);
        list.add(xcjs);

        adapter = new MyFragmentAdapter(getSupportFragmentManager(), list);
        vp.setAdapter(adapter);
        vp.setOffscreenPageLimit(2);

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.rb1) {
                    vp.setCurrentItem(0, false);
                    rb1.setTextColor(Color.WHITE);
                    rb2.setTextColor(Color.GRAY);
                } else if (i == R.id.rb2) {
                    vp.setCurrentItem(1, false);
                    rb2.setTextColor(Color.WHITE);
                    rb1.setTextColor(Color.GRAY);
                }
            }
        });
    }
    public void setXcjs() {
        int item = fhm.getItem();
        xcjs.setXfjhdXfid(fhms.get(item).getJHID(), fhms.get(item).getXFID());
    }
}
