Search in sources :

Example 1 with CoinBean

use of com.example.jingbin.cloudreader.bean.CoinBean 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 CoinBean

use of com.example.jingbin.cloudreader.bean.CoinBean 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)

Aggregations

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