package com.rehome.sgbaxj.activity.sbxdj;

import android.graphics.Color;
import androidx.fragment.app.Fragment;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.rehome.sgbaxj.R;
import com.rehome.sgbaxj.adapter.MyFragmentAdapter;
import com.rehome.sgbaxj.base.BaseActivity;
import com.rehome.sgbaxj.weight.AutoRadioGroup;
import com.rehome.sgbaxj.weight.NoscrollViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * 设备巡点检管理--现场点检
 */
public class SxcdjActivity extends BaseActivity {

    NoscrollViewPager vp;

    RadioButton rb1;

    RadioButton rb2;

    RadioButton rb3;

    AutoRadioGroup rg;

    private List<Fragment> list;
    private MyFragmentAdapter adapter;

    private XzjhFragment xzjh;
    private DjdscFragment djdsc;

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

    protected void initView() {
        vp = findViewById(R.id.vp_centent);
        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();
        xzjh = XzjhFragment.newInstance();
        djdsc = DjdscFragment.newInstance();
        list = new ArrayList<>();
        list.add(xzjh);
        list.add(djdsc);
        adapter = new MyFragmentAdapter(getSupportFragmentManager(), list);
        vp.setAdapter(adapter);


        vp.setOffscreenPageLimit(2);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {

                switch (i) {
                    case R.id.rb1:
                        rb1.setTextColor(Color.WHITE);
                        rb2.setTextColor(Color.GRAY);
                        rb3.setTextColor(Color.GRAY);
                        vp.setCurrentItem(0, false);
                        break;
                    case R.id.rb2:
                        rb1.setTextColor(Color.GRAY);
                        rb2.setTextColor(Color.WHITE);
                        rb3.setTextColor(Color.GRAY);
                        vp.setCurrentItem(1, false);
                        break;

                }
            }
        });
    }

    public void updataDjdsc() {
        djdsc.getDataInSQL();
    }
}