Search in sources :

Example 1 with FavoritesResult

use of com.xinshang.audient.model.entities.FavoritesResult in project Audient by komamj.

the class MinePresenter method loadFavorites.

@Override
public void loadFavorites() {
    LogUtils.i(TAG, "loadFavorites");
    Disposable disposable = mRepository.getFavoriteResult().map(new Function<FavoritesResult, List<Favorite>>() {

        @Override
        public List<Favorite> apply(FavoritesResult favoriteResult) throws Exception {
            return favoriteResult.favorites;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Favorite>>() {

        @Override
        public void onNext(List<Favorite> favorites) {
            LogUtils.i(TAG, "loadfavorites " + favorites.toString());
            if (mView.isActive()) {
                mView.showFavorites(favorites);
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadFavorites error " + t.toString());
            if (mView.isActive()) {
                mView.showFavoriteProgressBar(false);
            }
        }

        @Override
        public void onComplete() {
            if (mView.isActive()) {
                mView.showFavoriteProgressBar(false);
            }
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Favorite(com.xinshang.audient.model.entities.Favorite) Function(io.reactivex.functions.Function) FavoritesResult(com.xinshang.audient.model.entities.FavoritesResult) List(java.util.List)

Example 2 with FavoritesResult

use of com.xinshang.audient.model.entities.FavoritesResult in project Audient by komamj.

the class MyFavoritesPresenter method loadMyFavorites.

@Override
public void loadMyFavorites() {
    Disposable disposable = mRepository.getFavoriteResult().map(new Function<FavoritesResult, List<Favorite>>() {

        @Override
        public List<Favorite> apply(FavoritesResult favoriteResult) throws Exception {
            return favoriteResult.favorites;
        }
    }).doOnNext(new Consumer<List<Favorite>>() {

        @Override
        public void accept(List<Favorite> favorites) throws Exception {
            LogUtils.i(TAG, "loadFavorites thread name :" + Thread.currentThread().getName() + "," + favorites.isEmpty());
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Favorite>>() {

        @Override
        public void onNext(List<Favorite> favorites) {
            LogUtils.i(TAG, "loadfavorites " + favorites.toString());
            if (mView.isActive()) {
                mView.setLoadingIndicator(false);
                mView.showFavorites(favorites);
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadFavorites error " + t.toString());
        }

        @Override
        public void onComplete() {
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Favorite(com.xinshang.audient.model.entities.Favorite) Consumer(io.reactivex.functions.Consumer) FavoritesResult(com.xinshang.audient.model.entities.FavoritesResult) List(java.util.List)

Aggregations

Favorite (com.xinshang.audient.model.entities.Favorite)2 FavoritesResult (com.xinshang.audient.model.entities.FavoritesResult)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 List (java.util.List)2 Consumer (io.reactivex.functions.Consumer)1 Function (io.reactivex.functions.Function)1