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

import android.graphics.Color;
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.TestZkdInfo;
import com.example.administrator.zhapp.fragment.sbxdjgl.SqdFragment;
import com.example.administrator.zhapp.fragment.sbxdjgl.ZqxgdFragment;
import com.example.administrator.zhapp.fragment.sbxdjgl.ZxcjsFragment;
import com.example.administrator.zhapp.weight.AutoRadioGroup;
import com.example.administrator.zhapp.weight.NoscrollViewPager;
import java.util.ArrayList;
import java.util.List;


/**
 * 设备巡点检管理-签点界面
 */
public class SqdActivity extends BaseActivity {

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

    private List<Fragment> list;
    private MyFragmentAdapter adapter;

    private SqdFragment sqd;
    private ZxcjsFragment xcjs;
    private ZqxgdFragment qxgd;

    private ArrayList<TestZkdInfo> lists;

    private boolean isedit;

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

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

    public void initData() {

        setTitle("签点");
        setBack();

        lists = new ArrayList<>();
        for (int i = 1; i < 6; i++) {
            TestZkdInfo info = new TestZkdInfo("专业" + i, "班组" + i, "项目" + i, "工序" + i,
                    "控制分类" + i, "工号" + i, "标准" + i, "备注" + i, null
            );
            lists.add(info);
        }

        isedit = getIntent().getExtras().getBoolean(Contans.KEY_IS_EDIT);
        list = new ArrayList<>();
        sqd = SqdFragment.newInstance(isedit, lists);
        xcjs = ZxcjsFragment.newInstance(isedit);
        qxgd = ZqxgdFragment.newInstance(isedit);

        list.add(sqd);
        list.add(xcjs);
        list.add(qxgd);
        adapter = new MyFragmentAdapter(getSupportFragmentManager(), list);
        vp.setAdapter(adapter);
        vp.setOffscreenPageLimit(3);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if(i==R.id.rb1){
                    rb1.setTextColor(Color.WHITE);
                    rb2.setTextColor(Color.GRAY);
                    rb3.setTextColor(Color.GRAY);
                    vp.setCurrentItem(0, false);
                }else if(i==R.id.rb2){
                    rb1.setTextColor(Color.GRAY);
                    rb2.setTextColor(Color.WHITE);
                    rb3.setTextColor(Color.GRAY);
                    vp.setCurrentItem(1, false);
                }else if(i==R.id.rb3){
                    rb1.setTextColor(Color.GRAY);
                    rb2.setTextColor(Color.GRAY);
                    rb3.setTextColor(Color.WHITE);
                    vp.setCurrentItem(2, false);
                }
            }
        });
    }

    public boolean isEdit() {
        return isedit;
    }
}
