package com.unis.sxzcl.ui.audit;

import android.os.Handler;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.unis.model.bean.AuditBean;
import com.unis.sxzcl.base.BaseListFragment;
import com.unis.sxzcl.databinding.FragmentBaseListBinding;

/**
 * 包名: com.unis.sxzcl.ui.audit
 * 类名: AuditListFragment
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/11/25 20:33
 * 更新人:
 * 更新时间: 2020/11/25 20:33
 * 更新说明:
 * 版本号: 1.0
 */
public class AuditListFragment extends BaseListFragment<FragmentBaseListBinding> {

    private AuditListAdapter mAdapter;

    @Override
    public void onRefreshData() {
        getData(true);
    }

    @Override
    public void onMoreData() {
        super.onMoreData();
        getData(false);
    }

    @Override
    protected FragmentBaseListBinding getViewBinding(LayoutInflater inflater, ViewGroup container) {
        return FragmentBaseListBinding.inflate(inflater,container,false);
    }

    @Override
    protected void init() {
        mAdapter = new AuditListAdapter();
        initBaseListView(mBinding.refreshLayout, mBinding.recyclerView, mAdapter, true);
    }

    @Override
    protected void onFirstShow() {
        onRefresh();
    }

    private void getData(boolean refresh) {
        new Handler().postDelayed(() -> {
//            //大于30到结尾
//            if (mAdapter.getData().size() == 20) {
//                loadEnd();
//                return;
//            }
            if (refresh) {
                mAdapter.getData().clear();
                mAdapter.notifyDataSetChanged();
            }

            //模拟数据
            mAdapter.addData(new AuditBean(null));
            mAdapter.addData(new AuditBean("0"));
            mAdapter.addData(new AuditBean("1"));

            loadEnd();
        }, 500);
    }
}
