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

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.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.entity.DjjhInfo;
import com.example.administrator.zhapp.fragment.sbxdjgl.Sajhlv1Fragment;
import com.example.administrator.zhapp.fragment.sbxdjgl.SsbdjFragment;
import com.example.administrator.zhapp.weight.AutoRadioGroup;
import com.example.administrator.zhapp.weight.NoscrollViewPager;
import java.util.ArrayList;
import java.util.List;

/**
 * 设备巡点检管理-采集数据
 */
public class ScjsjActivity extends BaseActivity {

    NoscrollViewPager vp;
    RadioButton rb1;
    RadioButton rb2;
    AutoRadioGroup rg;
    private MyFragmentAdapter adapter;
    private List<Fragment> list;
    private Sajhlv1Fragment ajh;
    private SsbdjFragment sbdj;
    private int item;

    private ArrayList<DjjhInfo.Djjh> djjhs;

    private boolean isEdit = true;

    private boolean nfcorewm;
    private String num;

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

    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() {

        setBack();
        setTitle("设备点检");
        djjhs = new ArrayList<>();

        Bundle bundle = getIntent().getExtras();
        isEdit = bundle.getBoolean("edit");
        djjhs = bundle.getParcelableArrayList(Contans.KEY_DJJHRWQY);
        item = bundle.getInt(Contans.KEY_ITEM);
        nfcorewm  = bundle.getBoolean(Contans.NFCOREWM);
        num = bundle.getString(Contans.KEY_BQBM);

        list = new ArrayList<>();
        ajh = Sajhlv1Fragment.newInstance(nfcorewm,num);
        sbdj = SsbdjFragment.newInstance(isEdit, djjhs, item);
        list.add(sbdj);
        list.add(ajh);
        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){
                                                  title.setText("设备点检");
                                                  rb1.setTextColor(Color.WHITE);
                                                  rb2.setTextColor(Color.GRAY);
                                                  vp.setCurrentItem(0, false);
                                              }else if(i==R.id.rb2){
                                                  title.setText("安健环巡查");
                                                  rb1.setTextColor(Color.GRAY);
                                                  rb2.setTextColor(Color.WHITE);
                                                  vp.setCurrentItem(1, false);
                                              }
                                          }
                                      }
        );
    }

    public void getJhPoint() {
        sbdj.setXcjs();
    }

    public void getSjcjNext() {
        sbdj.sjcjNext();
    }
}
