Search in sources :

Example 1 with RequestImpl

use of com.example.jingbin.cloudreader.http.RequestImpl in project CloudReader by youlookwhat.

the class WelfareViewModel method loadWelfareData.

public MutableLiveData<GankIoDataBean> loadWelfareData() {
    final MutableLiveData<GankIoDataBean> data = new MutableLiveData<>();
    mModel.setData("Girl", "Girl", mPage, 20);
    mModel.getGankIoData(new RequestImpl() {

        @Override
        public void loadSuccess(Object object) {
            GankIoDataBean gankIoDataBean = (GankIoDataBean) object;
            handleImageList(gankIoDataBean);
            data.setValue(gankIoDataBean);
        }

        @Override
        public void loadFailed() {
            if (mPage > 1) {
                mPage--;
            }
            data.setValue(null);
        }

        @Override
        public void addSubscription(Disposable disposable) {
            addDisposable(disposable);
        }
    });
    return data;
}
Also used : Disposable(io.reactivex.disposables.Disposable) GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) MutableLiveData(androidx.lifecycle.MutableLiveData) RequestImpl(com.example.jingbin.cloudreader.http.RequestImpl)

Example 2 with RequestImpl

use of com.example.jingbin.cloudreader.http.RequestImpl in project CloudReader by youlookwhat.

the class WelfareFragment method loadWelfareData.

private void loadWelfareData() {
    mModel.setData("福利", mPage, HttpUtils.per_page_more);
    mModel.getGankIoData(new RequestImpl() {

        @Override
        public void loadSuccess(Object object) {
            showContentView();
            GankIoDataBean gankIoDataBean = (GankIoDataBean) object;
            if (mPage == 1) {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    imgList.clear();
                    for (int i = 0; i < gankIoDataBean.getResults().size(); i++) {
                        imgList.add(gankIoDataBean.getResults().get(i).getUrl());
                    }
                    setAdapter(gankIoDataBean);
                    aCache.remove(Constants.GANK_MEIZI);
                    aCache.put(Constants.GANK_MEIZI, gankIoDataBean, 30000);
                }
            } else {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    bindingView.xrvWelfare.refreshComplete();
                    mWelfareAdapter.addAll(gankIoDataBean.getResults());
                    mWelfareAdapter.notifyDataSetChanged();
                    for (int i = 0; i < gankIoDataBean.getResults().size(); i++) {
                        imgList.add(gankIoDataBean.getResults().get(i).getUrl());
                    }
                } else {
                    bindingView.xrvWelfare.noMoreLoading();
                }
            }
        }

        @Override
        public void loadFailed() {
            bindingView.xrvWelfare.refreshComplete();
            if (mWelfareAdapter.getItemCount() == 0) {
                showError();
            }
            if (mPage > 1) {
                mPage--;
            }
        }

        @Override
        public void addSubscription(Subscription subscription) {
            WelfareFragment.this.addSubscription(subscription);
        }
    });
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Subscription(rx.Subscription) RequestImpl(com.example.jingbin.cloudreader.http.RequestImpl)

Example 3 with RequestImpl

use of com.example.jingbin.cloudreader.http.RequestImpl in project CloudReader by youlookwhat.

the class AndroidFragment method loadAndroidData.

private void loadAndroidData() {
    mModel.setData(mType, mPage, HttpUtils.per_page_more);
    mModel.getGankIoData(new RequestImpl() {

        @Override
        public void loadSuccess(Object object) {
            showContentView();
            GankIoDataBean gankIoDataBean = (GankIoDataBean) object;
            if (mPage == 1) {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    setAdapter(gankIoDataBean);
                    mACache.remove(Constants.GANK_ANDROID);
                    // 缓存50分钟
                    mACache.put(Constants.GANK_ANDROID, gankIoDataBean, 30000);
                }
            } else {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    bindingView.xrvAndroid.refreshComplete();
                    mAndroidAdapter.addAll(gankIoDataBean.getResults());
                    mAndroidAdapter.notifyDataSetChanged();
                } else {
                    bindingView.xrvAndroid.noMoreLoading();
                }
            }
        }

        @Override
        public void loadFailed() {
            bindingView.xrvAndroid.refreshComplete();
            // 注意:这里不能写成 mPage == 1,否则会一直显示错误页面
            if (mAndroidAdapter.getItemCount() == 0) {
                showError();
            }
            if (mPage > 1) {
                mPage--;
            }
        }

        @Override
        public void addSubscription(Subscription subscription) {
            AndroidFragment.this.addSubscription(subscription);
        }
    });
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Subscription(rx.Subscription) RequestImpl(com.example.jingbin.cloudreader.http.RequestImpl)

Example 4 with RequestImpl

use of com.example.jingbin.cloudreader.http.RequestImpl in project CloudReader by youlookwhat.

the class CustomFragment method loadCustomData.

private void loadCustomData() {
    mModel.setData(mType, mPage, HttpUtils.per_page_more);
    mModel.getGankIoData(new RequestImpl() {

        @Override
        public void loadSuccess(Object object) {
            showContentView();
            GankIoDataBean gankIoDataBean = (GankIoDataBean) object;
            if (mPage == 1) {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    setAdapter(gankIoDataBean);
                    mACache.remove(Constants.GANK_CUSTOM);
                    // 缓存50分钟
                    mACache.put(Constants.GANK_CUSTOM, gankIoDataBean, 30000);
                }
            } else {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    bindingView.xrvCustom.refreshComplete();
                    mAndroidAdapter.addAll(gankIoDataBean.getResults());
                    mAndroidAdapter.notifyDataSetChanged();
                } else {
                    bindingView.xrvCustom.noMoreLoading();
                }
            }
        }

        @Override
        public void loadFailed() {
            showContentView();
            bindingView.xrvCustom.refreshComplete();
            if (mAndroidAdapter.getItemCount() == 0) {
                showError();
            }
            if (mPage > 1) {
                mPage--;
            }
        }

        @Override
        public void addSubscription(Subscription subscription) {
            CustomFragment.this.addSubscription(subscription);
        }
    });
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Subscription(rx.Subscription) RequestImpl(com.example.jingbin.cloudreader.http.RequestImpl)

Example 5 with RequestImpl

use of com.example.jingbin.cloudreader.http.RequestImpl in project CloudReader by youlookwhat.

the class GankViewModel method loadGankData.

public MutableLiveData<GankIoDataBean> loadGankData() {
    final MutableLiveData<GankIoDataBean> data = new MutableLiveData<>();
    mModel.setData("GanHuo", mType, mPage, 20);
    mModel.getGankIoData(new RequestImpl() {

        @Override
        public void loadSuccess(Object object) {
            data.setValue(DataUtil.getTrueData((GankIoDataBean) object));
        }

        @Override
        public void loadFailed() {
            if (mPage > 1) {
                mPage--;
            }
            data.setValue(null);
        }

        @Override
        public void addSubscription(Disposable disposable) {
            addDisposable(disposable);
        }
    });
    return data;
}
Also used : Disposable(io.reactivex.disposables.Disposable) GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) MutableLiveData(androidx.lifecycle.MutableLiveData) RequestImpl(com.example.jingbin.cloudreader.http.RequestImpl)

Aggregations

GankIoDataBean (com.example.jingbin.cloudreader.bean.GankIoDataBean)5 RequestImpl (com.example.jingbin.cloudreader.http.RequestImpl)5 Subscription (rx.Subscription)3 MutableLiveData (androidx.lifecycle.MutableLiveData)2 Disposable (io.reactivex.disposables.Disposable)2