package com.unis.sxzcl.ui.basic;

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

import com.unis.model.bean.AnnounceBean;
import com.unis.sxzcl.R;
import com.unis.sxzcl.base.BaseListFragment;
import com.unis.sxzcl.databinding.FragmentBaseListBinding;
import com.unis.sxzcl.ui.announce.AnnounceListAdapter;

/**
 *
 * 包名: com.unis.sxzcl.ui.basic
 * 类名: PolicyListFragment
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/12/9 20:26
 * 更新人:
 * 更新时间: 2020/12/9 20:26
 * 更新说明:
 * 版本号: 1.0
 */
public class PolicyListFragment extends BaseListFragment<FragmentBaseListBinding> {

    private AnnounceListAdapter 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 AnnounceListAdapter();
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            navigation(R.id.announceDetailFragment);
        });

        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 AnnounceBean());
            mAdapter.addData(new AnnounceBean());
            mAdapter.addData(new AnnounceBean());
            mAdapter.addData(new AnnounceBean());

            loadEnd();
        }, 500);
    }
}
