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

import android.graphics.Color;

import androidx.appcompat.widget.AppCompatTextView;
import androidx.fragment.app.Fragment;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.example.administrator.zhapp.DBModel.XwaqgcSc;
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.fragment.ajhxcgl.JsFragment;
import com.example.administrator.zhapp.fragment.ajhxcgl.XwaqgcxgFragment;
import com.example.administrator.zhapp.weight.AutoRadioGroup;
import com.example.administrator.zhapp.weight.NoscrollViewPager;
import org.litepal.crud.DataSupport;
import java.util.ArrayList;
import java.util.List;

public class XwaqgcxgActivity extends BaseActivity {


    AppCompatTextView title;
    NoscrollViewPager vpCentent;
    RadioButton rb1;
    RadioButton rb2;
    AutoRadioGroup rg;

    private XwaqgcxgFragment xwaq;
    //    private XwaqgcxgJsFragment js;
    private JsFragment js;
    private List<Fragment> list;
    private MyFragmentAdapter adapter;
    private XwaqgcSc sc;


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

    @Override
    protected void initView() {
        title = findViewById(R.id.title);
        vpCentent = findViewById(R.id.vp_centent);
        rb1 = findViewById(R.id.rb1);
        rb2 = findViewById(R.id.rb2);
        rg = findViewById(R.id.rg);

        setBack();
        setTitle("行为安全观察记录");
        sc = getIntent().getExtras().getParcelable("xwaqgcsc");

    }

    @Override
    public void initData() {

        xwaq = XwaqgcxgFragment.newInstance(sc);

        List<XwaqgcSc> xwaqgcScs = DataSupport.where("gcid = ?", sc.getGCID()).find(XwaqgcSc.class);

//        js = XwaqgcxgJsFragment.newInstance(sc.getGZDD());
        js = JsFragment.newInstance("", false, true, sc.getGZDD(), xwaqgcScs.size() != 0 ? xwaqgcScs.get(0).getXWJLJSID() : sc.getXWJLJSID());
        list = new ArrayList<>();
        list.add(xwaq);
        list.add(js);
        adapter = new MyFragmentAdapter(getSupportFragmentManager(), list);
        vpCentent.setAdapter(adapter);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if(i==R.id.rb1){
                    vpCentent.setCurrentItem(0, false);
                    title.setText("行为安全观察管理");
                    rb1.setTextColor(Color.WHITE);
                    rb2.setTextColor(Color.GRAY);
                }else if(i==R.id.rb2){
                    vpCentent.setCurrentItem(1, false);
                    title.setText("不安全记录");
                    rb2.setTextColor(Color.WHITE);
                    rb1.setTextColor(Color.GRAY);
                }
            }
        });

    }
}