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

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.example.administrator.zhapp.R;
import com.example.administrator.zhapp.adapter.MyFragmentAdapter;
import com.example.administrator.zhapp.contans.Contans;
import com.example.administrator.zhapp.fragment.BaseFragment;
import com.example.administrator.zhapp.fragment.ajhxcgl.Sajhlv2Fragment;
import com.example.administrator.zhapp.fragment.ajhxcgl.YhpcFragment;
import com.example.administrator.zhapp.weight.AutoRadioGroup;
import java.util.ArrayList;
import java.util.List;


/**
 * 设备巡点检管理--安键环
 */
public class Sajhlv1Fragment extends BaseFragment {

    RadioButton rb1;
    RadioButton rb2;
    AutoRadioGroup rg;
    ViewPager vp;

    private Sajhlv2Fragment sajhlv2;
    private YhpcFragment yhpc;
    private MyFragmentAdapter mAdapter;
    private List<Fragment> lists;

    private boolean nfcorewm;
    private String num;


    public Sajhlv1Fragment() {
    }

    public static Sajhlv1Fragment newInstance(boolean nfcorewm,String num) {
        Sajhlv1Fragment fragment = new Sajhlv1Fragment();
        Bundle bundle = new Bundle();
        bundle.putBoolean(Contans.NFCOREWM,nfcorewm);
        bundle.putString(Contans.KEY_BQBM,num);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if ( bundle != null)
        {
            nfcorewm = bundle.getBoolean(Contans.NFCOREWM);
            num = bundle.getString(Contans.KEY_BQBM);
        }
}


    @Override
    public int getContentViewId() {
        return R.layout.fragment_sajh;
    }

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

    public void initData() {
        lists = new ArrayList<>();
        sajhlv2 = Sajhlv2Fragment.newInstance("参数A", "参数B");
        yhpc = YhpcFragment.newInstance("参数A", "参数B");

        lists.add(sajhlv2);
        lists.add(yhpc);

        mAdapter = new MyFragmentAdapter(getChildFragmentManager(), lists);

        vp.setAdapter(mAdapter);
        vp.setOffscreenPageLimit(3);

        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                switch (position) {
                    case 0:
                        rb1.setChecked(true);
                        rb1.setTextColor(getResources().getColor(R.color.btn));
                        rb2.setTextColor(Color.GRAY);
                        break;
                    case 1:
                        rb2.setChecked(true);
                        rb2.setTextColor(getResources().getColor(R.color.btn));
                        rb1.setTextColor(Color.GRAY);
                        break;
                }

            }
            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb1) {
                    rb1.setTextColor(getResources().getColor(R.color.btn));
                    rb2.setTextColor(Color.GRAY);
                    vp.setCurrentItem(0, false);
                }
                if (checkedId == R.id.rb2) {
                    rb2.setTextColor(getResources().getColor(R.color.btn));
                    rb1.setTextColor(Color.GRAY);
                    vp.setCurrentItem(1, false);
                }
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
