码迷,mamicode.com
首页 > Web开发 > 详细

BaseLoadDataForNetFragment

时间:2018-05-08 14:37:12      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:err   bsp   lse   state   creat   cte   初始化   ase   load   

/**
 * Fragment 加载网络请求
 */
public abstract class BaseLoadDataForNetFragment extends Fragment {

    // 视图是否初始化完成
    protected boolean isViewInitiated;
    // 界面是否可见
    protected boolean isVisibleToUser;
    // 数据是否加载
    protected boolean isDataInitiated;


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        WLog.d("onActivityCreated");

        isViewInitiated = true;
        prepareFetchData();
    }


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        WLog.d("setUserVisibleHint:" + isVisibleToUser);

        this.isVisibleToUser = isVisibleToUser;
        prepareFetchData();
    }


    private boolean prepareFetchData() {
        WLog.d("prepareFetchData");

        return prepareFetchData(false);
    }

    /**
     * 设置true,可强制刷新界面
     *
     * @param forceUpdate 是否强制刷新界面
     * @return
     */
    protected boolean prepareFetchData(boolean forceUpdate) {
        if (isVisibleToUser && isViewInitiated && (!isDataInitiated || forceUpdate)) {
            fetchDataForNet();
            isDataInitiated = true;
            return true;
        }
        return false;
    }

    /**
     * 刷新数据,网络刷新数据
     */
    public abstract void fetchDataForNet();

 

BaseLoadDataForNetFragment

标签:err   bsp   lse   state   creat   cte   初始化   ase   load   

原文地址:https://www.cnblogs.com/H-BolinBlog/p/9007340.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!