package com.sheep.gamegroup.absBase;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.sheep.jiuyan.samllsheep.base.BaseFragment;

/**
 * Created by realicing on 2018/11/5.
 * realicing@sina.com
 */
public abstract class BaseRefreshLoadMoreFragment extends BaseFragment implements IRefresh, ILoadMore{

    protected SmartRefreshLayout smartRefreshLayout;

    public SmartRefreshLayout getSmartRefreshLayout() {
        return smartRefreshLayout;
    }

    public void setSmartRefreshLayout(SmartRefreshLayout smartRefreshLayout) {
        this.smartRefreshLayout = smartRefreshLayout;
    }

    protected boolean noMore = false;

    public boolean isNoMore() {
        return noMore;
    }
    //设置是否还有更多数据
    public void setNoMore(boolean noMore) {
        this.noMore = noMore;
        setSmartRefreshLayoutNoMore(noMore);
    }
    //加载完成时更新header或footer
    protected void refreshOrLoadMoreComplete() {
        if (smartRefreshLayout != null && getUserVisibleHint()) {
            smartRefreshLayout.finishRefresh();
            smartRefreshLayout.finishLoadMore();
        }
    }
    //设置是否还有更多数据
    protected void setSmartRefreshLayoutNoMore(boolean noMore) {
        if (smartRefreshLayout != null && getUserVisibleHint()) {
            smartRefreshLayout.setNoMoreData(noMore);
        }
    }
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        setSmartRefreshLayoutNoMore(noMore);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        smartRefreshLayout = null;
    }
}
