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

import android.graphics.Color;
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.XfsDetaliFragment;
import com.example.administrator.zhapp.weight.AutoRadioGroup;
import com.example.administrator.zhapp.weight.NoscrollViewPager;
import java.util.ArrayList;
import java.util.List;


/**
 * 消防保卫巡查管理-消防栓详情
 */
public class XXfsDetaliActivity extends BaseActivity {

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

    private XfsDetaliFragment xfs;
    private XcjsFragment xcjs;
    private List<Fragment> list;
    private MyFragmentAdapter adapter;

    private ArrayList<XfDjjhRwqy> xfss;
    private int item;

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

    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<>();
        xfss = getIntent().getParcelableArrayListExtra("list");
        item = getIntent().getExtras().getInt("item");
        xfs = XfsDetaliFragment.newInstance(xfss, item);
        xcjs = XcjsFragment.newInstance(true, Contans.XFSFRG);
        list.add(xfs);
        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 = xfs.getItem();
        xcjs.setXfjhdXfid(xfss.get(item).getJHID(), xfss.get(item).getXFID());
    }
}
