Search in sources :

Example 1 with NowPlayingResponse

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

the class NowPlayingPresenter method loadNowPlaying.

@Override
public void loadNowPlaying() {
    mDisposables.clear();
    Disposable disposable = mRepository.getNowPlayingResult().map(new Function<NowPlayingResponse, Audient>() {

        @Override
        public Audient apply(NowPlayingResponse nowPlayingResult) throws Exception {
            return nowPlayingResult.audient;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnNext(new Consumer<Audient>() {

        @Override
        public void accept(Audient audient) throws Exception {
            if (mView.isActive()) {
                mView.showNowPlaying(audient);
            }
        }
    }).observeOn(Schedulers.io()).flatMap(new Function<Audient, Publisher<Lyric>>() {

        @Override
        public Publisher<Lyric> apply(Audient audient) throws Exception {
            return mRepository.getLyricResult(audient.mediaId).map(new Function<LyricResult, Lyric>() {

                @Override
                public Lyric apply(LyricResult lyricResult) throws Exception {
                    return lyricResult.lyric;
                }
            });
        }
    }).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<Lyric>() {

        @Override
        public void onNext(Lyric lyric) {
            if (mView.isActive()) {
                mView.showLyric(lyric);
            }
        }

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

        @Override
        public void onComplete() {
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) NowPlayingResponse(com.xinshang.audient.model.entities.NowPlayingResponse) Publisher(org.reactivestreams.Publisher) Function(io.reactivex.functions.Function) LyricResult(com.xinshang.audient.model.entities.LyricResult) Lyric(com.xinshang.audient.model.entities.Lyric) Audient(com.xinshang.audient.model.entities.Audient)

Aggregations

Audient (com.xinshang.audient.model.entities.Audient)1 Lyric (com.xinshang.audient.model.entities.Lyric)1 LyricResult (com.xinshang.audient.model.entities.LyricResult)1 NowPlayingResponse (com.xinshang.audient.model.entities.NowPlayingResponse)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Function (io.reactivex.functions.Function)1 Publisher (org.reactivestreams.Publisher)1