Search in sources :

Example 1 with HomeListBean

use of com.example.jingbin.cloudreader.bean.wanandroid.HomeListBean in project CloudReader by youlookwhat.

the class SearchViewModel method searchWan.

/**
 * 搜索
 */
public MutableLiveData<HomeListBean> searchWan(String keyWord) {
    final MutableLiveData<HomeListBean> data = new MutableLiveData<>();
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().searchWan(mPage, keyWord).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<HomeListBean>() {

        @Override
        public void accept(HomeListBean bean) throws Exception {
            if (bean == null || bean.getData() == null || bean.getData().getDatas() == null || bean.getData().getDatas().size() <= 0) {
                data.setValue(null);
            } else {
                data.setValue(bean);
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            if (mPage > 0) {
                mPage--;
            }
            data.setValue(null);
        }
    });
    addDisposable(subscribe);
    return data;
}
Also used : Disposable(io.reactivex.disposables.Disposable) HomeListBean(com.example.jingbin.cloudreader.bean.wanandroid.HomeListBean) MutableLiveData(androidx.lifecycle.MutableLiveData)

Example 2 with HomeListBean

use of com.example.jingbin.cloudreader.bean.wanandroid.HomeListBean in project CloudReader by youlookwhat.

the class ArticleListViewModel method getCollectList.

/**
 * 我的收藏
 */
public MutableLiveData<HomeListBean> getCollectList() {
    final MutableLiveData<HomeListBean> data = new MutableLiveData<>();
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getCollectList(mPage).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<HomeListBean>() {

        @Override
        public void accept(HomeListBean bean) throws Exception {
            data.setValue(bean);
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            if (mPage > 0) {
                mPage--;
            }
            data.setValue(null);
        }
    });
    addDisposable(subscribe);
    return data;
}
Also used : Disposable(io.reactivex.disposables.Disposable) HomeListBean(com.example.jingbin.cloudreader.bean.wanandroid.HomeListBean) MutableLiveData(androidx.lifecycle.MutableLiveData)

Aggregations

MutableLiveData (androidx.lifecycle.MutableLiveData)2 HomeListBean (com.example.jingbin.cloudreader.bean.wanandroid.HomeListBean)2 Disposable (io.reactivex.disposables.Disposable)2