Search in sources :

Example 1 with BaseResultBean

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

the class CoinListViewModel method getCoinRank.

/**
 * 积分排行榜
 */
public MutableLiveData<CoinBean> getCoinRank() {
    final MutableLiveData<CoinBean> data = new MutableLiveData<>();
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getCoinRank(mPage).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<BaseResultBean<CoinBean>>() {

        @Override
        public void accept(BaseResultBean<CoinBean> bean) throws Exception {
            if (bean != null && bean.getData() != null) {
                data.setValue(bean.getData());
            } else {
                data.setValue(null);
            }
        }
    }, new Consumer<Throwable>() {

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

Example 2 with BaseResultBean

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

the class CoinListViewModel method getCoinLog.

/**
 * 我的积分
 */
public MutableLiveData<CoinBean> getCoinLog() {
    final MutableLiveData<CoinBean> data = new MutableLiveData<>();
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getCoinLog(mPage).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<BaseResultBean<CoinBean>>() {

        @Override
        public void accept(BaseResultBean<CoinBean> bean) throws Exception {
            if (bean != null && bean.getData() != null) {
                data.setValue(bean.getData());
            } else {
                data.setValue(null);
            }
        }
    }, new Consumer<Throwable>() {

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

Example 3 with BaseResultBean

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

the class MainViewModel method getUserInfo.

public void getUserInfo() {
    UserUtil.getUserInfo(new OnUserInfoListener() {

        @Override
        public void onSuccess(User user) {
            if (user != null) {
                execute(HttpClient.Builder.getWanAndroidServer().getCoinUserInfo(), new Observer<BaseResultBean<CoinUserInfoBean>>() {

                    @Override
                    public void onSubscribe(Disposable d) {
                        addDisposable(d);
                    }

                    @Override
                    public void onNext(BaseResultBean<CoinUserInfoBean> bean) {
                        if (bean != null && bean.getData() != null) {
                            CoinUserInfoBean infoBean = bean.getData();
                            infoBean.setUsername(user.getUsername());
                            coin.setValue(infoBean);
                            UserUtil.getUserInfo(new OnUserInfoListener() {

                                @Override
                                public void onSuccess(User user) {
                                    if (user != null) {
                                        user.setCoinCount(infoBean.getCoinCount());
                                        user.setRank(infoBean.getRank());
                                        UserUtil.setUserInfo(user);
                                    }
                                }
                            });
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        coin.setValue(null);
                    }

                    @Override
                    public void onComplete() {
                    }
                });
            } else {
                coin.setValue(null);
            }
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) BaseResultBean(com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean) OnUserInfoListener(com.example.jingbin.cloudreader.data.OnUserInfoListener) User(me.jingbin.bymvvm.room.User) Observer(io.reactivex.Observer) CoinUserInfoBean(com.example.jingbin.cloudreader.bean.wanandroid.CoinUserInfoBean)

Example 4 with BaseResultBean

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

the class WanFindViewModel method getWxArticle.

public void getWxArticle() {
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getWxarticle().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<BaseResultBean<List<WxarticleItemBean>>>() {

        @Override
        public void accept(BaseResultBean<List<WxarticleItemBean>> naviJsonBean) throws Exception {
            if (naviJsonBean != null && naviJsonBean.getData() != null && naviJsonBean.getData().size() > 0) {
                // title
                dataTitle.setValue(naviJsonBean.getData());
            } else {
                dataTitle.setValue(null);
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            dataTitle.setValue(null);
        }
    });
    addDisposable(subscribe);
}
Also used : Disposable(io.reactivex.disposables.Disposable) BaseResultBean(com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean) WxarticleItemBean(com.example.jingbin.cloudreader.bean.wanandroid.WxarticleItemBean) List(java.util.List)

Example 5 with BaseResultBean

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

the class WanFindViewModel method getWxarticleDetail.

public void getWxarticleDetail(int id) {
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getWxarticleDetail(id, mPage).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<BaseResultBean<WxarticleDetailItemBean>>() {

        @Override
        public void accept(BaseResultBean<WxarticleDetailItemBean> naviJsonBean) throws Exception {
            if (naviJsonBean != null && naviJsonBean.getData() != null && naviJsonBean.getData().getDatas() != null && naviJsonBean.getData().getDatas().size() > 0) {
                // detail
                data.setValue(naviJsonBean.getData().getDatas());
            } else {
                data.setValue(null);
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            data.setValue(null);
        }
    });
    addDisposable(subscribe);
}
Also used : Disposable(io.reactivex.disposables.Disposable) BaseResultBean(com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean) WxarticleDetailItemBean(com.example.jingbin.cloudreader.bean.wanandroid.WxarticleDetailItemBean)

Aggregations

BaseResultBean (com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean)5 Disposable (io.reactivex.disposables.Disposable)5 MutableLiveData (androidx.lifecycle.MutableLiveData)2 CoinBean (com.example.jingbin.cloudreader.bean.CoinBean)2 CoinUserInfoBean (com.example.jingbin.cloudreader.bean.wanandroid.CoinUserInfoBean)1 WxarticleDetailItemBean (com.example.jingbin.cloudreader.bean.wanandroid.WxarticleDetailItemBean)1 WxarticleItemBean (com.example.jingbin.cloudreader.bean.wanandroid.WxarticleItemBean)1 OnUserInfoListener (com.example.jingbin.cloudreader.data.OnUserInfoListener)1 Observer (io.reactivex.Observer)1 List (java.util.List)1 User (me.jingbin.bymvvm.room.User)1