package com.qhclh.ytzh.work.productiondaily;

import android.widget.TextView;

import com.qhclh.ytzh.R;
import com.qhclh.ytzh.base.BaseFragment;
import com.qhclh.ytzh.bean.WriteBean;

import java.util.List;

import butterknife.BindView;

/**
 * Created by 青花瓷 on 2017/12/20.
 */

public class ShowInfoFragment extends BaseFragment {
    @BindView(R.id.frag_death_info)
    TextView frag_death_info;
    @BindView(R.id.frag_eliminate_info)
    TextView frag_eliminate_info;
    @BindView(R.id.frag_water_info)
    TextView frag_water_info;
    @BindView(R.id.frag_weight_info)
    TextView frag_weight;
    @BindView(R.id.frag_mint_info)
    TextView frag_mint_info;
    @BindView(R.id.frag_maxt_info)
    TextView frag_maxt_info;
    @BindView(R.id.frag_minh_info)
    TextView frag_minh_info;
    @BindView(R.id.frag_maxh_info)
    TextView frag_maxh_info;
    @BindView(R.id.frag_minw_info)
    TextView frag_minw_info;
    @BindView(R.id.frag_maxw_info)
    TextView frag_maxw_info;
    @BindView(R.id.frag_pressure_info)
    TextView frag_pressure_info;

//    private List<WriteBean> list;
    private ShowInfoActivity activity;

    //Fragment的View加载完毕的标记
    private boolean isViewCreated;

    //Fragment对用户可见的标记
    private boolean isUIVisible;

//    public ShowInfoFragment(List<WriteBean> list) {
//        this.list = list;
//    }

    @Override
    protected int setLayout() {
        return R.layout.frag_dailyinfo;
    }

    @Override
    protected void initView() {
        activity = (ShowInfoActivity) getActivity();
        isViewCreated = true;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initOper() {

    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            isUIVisible = true;
            lazyLoad();
        } else {
            isUIVisible = false;
        }

    }

    private void lazyLoad() {
        //这里进行双重标记判断,是因为setUserVisibleHint会多次回调,并且会在onCreateView执行前回调,必须确保onCreateView加载完毕且页面可见,才加载数据
        if (isViewCreated && isUIVisible) {

            frag_death_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getSiwang());
            frag_eliminate_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getTaotai());
            frag_water_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getYinshuiliang());
            frag_weight.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getTizhong());
            frag_mint_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuidiwendu());
            frag_maxt_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuigaowendu());
            frag_minh_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuidishidu());
            frag_maxh_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuigaoshidu());
            frag_minw_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuixiaotongfeng());
            frag_maxw_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuidatongfeng());
            frag_pressure_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getFuya());
            //数据加载完毕,恢复标记,防止重复加载
            isViewCreated = false;
            isUIVisible = false;

        }
    }

    @Override
    public void onResume() {
        super.onResume();
        frag_death_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getSiwang());
        frag_eliminate_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getTaotai());
        frag_water_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getYinshuiliang());
        frag_weight.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getTizhong());
        frag_mint_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuidiwendu());
        frag_maxt_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuigaowendu());
        frag_minh_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuidishidu());
        frag_maxh_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuigaoshidu());
        frag_minw_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuixiaotongfeng());
        frag_maxw_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getZuidatongfeng());
        frag_pressure_info.setText(ShowInfoActivity.list.get(activity.mViewPager.getCurrentItem()).getFuya());
    }
}
