package com.zhaohaoting.framework.abs.adapter;

import android.content.Context;

import com.zhaohaoting.framework.abs.entity.BaseListEntity;

/**
 * Created by zhaoting on 2018/11/11.
 * Desc：分页
 */

public abstract class BasePageListAdapter<DATA,BASE_DATA extends BaseListEntity<DATA>> extends AbsRecyclerAdapter<DATA, BaseListEntity<DATA>> {

    private BaseListEntity<DATA> baseListEntity;

    public BasePageListAdapter(Context context) {
        this(context, new BaseListEntity<DATA>());
    }

    private BasePageListAdapter(Context context, BaseListEntity<DATA> baseListEntity) {
        super(context, baseListEntity.getRows());
        this.baseListEntity = baseListEntity;
    }

    @Override
    public void notifyDataChanged(BaseListEntity<DATA> dataList, boolean isRefresh) {
        if (isRefresh) {
            mDataList.clear();
        }
        if (dataList != null) {
            baseListEntity.setPageSize(dataList.getPageSize());
            mDataList.addAll(dataList.getRows());
        }
        notifyDataSetChanged();
    }

    @Override
    public BaseListEntity<DATA> getData() {
        return baseListEntity;
    }
}
