Search in sources :

Example 1 with Audient

use of com.xinshang.audient.model.entities.Audient 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)

Example 2 with Audient

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

the class PlaylistFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setLoadingIndicator(true);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (mPresenter != null) {
                mPresenter.unSubscribe();
                mPresenter.subscribe();
            }
        }
    });
    mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimaryDark, R.color.colorPrimary);
    mAdapter = new PlaylistAdapter(mContext);
    mAdapter.setEventListener(new PlaylistAdapter.EventListener() {

        @Override
        public void onFavoriteMenuClick(Audient audient) {
            Intent intent = new Intent(mContext, MyFavoritesActivity.class);
            intent.putExtra(Constants.KEY_AUDIENT, audient);
            mContext.startActivity(intent);
        }
    });
    mRecyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.addItemDecoration(new AudientItemDecoration(mContext));
    mRecyclerView.setAdapter(mAdapter);
}
Also used : MyFavoritesActivity(com.xinshang.audient.favorite.MyFavoritesActivity) AudientItemDecoration(com.xinshang.audient.widget.AudientItemDecoration) Intent(android.content.Intent) Audient(com.xinshang.audient.model.entities.Audient) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 3 with Audient

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

the class SearchPresenter method loadSearchResults.

@Override
public void loadSearchResults(String keyword) {
    LogUtils.i(TAG, "loadSearchResults :" + keyword);
    mDisposables.clear();
    if (isInvalid(keyword)) {
        if (mView.isActive()) {
            mView.showEmpty(true);
        }
        return;
    }
    if (mView != null) {
        mView.showProgressBar(true);
    }
    Disposable disposable = mRepository.getSearchReult(keyword).map(new Function<SearchResult, List<Audient>>() {

        @Override
        public List<Audient> apply(SearchResult searchResult) throws Exception {
            return searchResult.dataBean.audients;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Audient>>() {

        @Override
        public void onNext(List<Audient> audients) {
            if (mView.isActive()) {
                mView.showProgressBar(false);
                mView.showAudients(audients);
                mView.showEmpty(audients.isEmpty());
            }
        }

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

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

Example 4 with Audient

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

the class FavoriteDetailFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    LogUtils.i(TAG, "onViewCreated");
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (mPresenter != null) {
                mPresenter.loadData(mFavorite.favoritesId);
            }
        }
    });
    mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimaryDark, R.color.colorPrimary, R.color.colorAccent);
    setLoadingIndicator(true);
    mAdapter = new FavoritesSongAdapter(mContext);
    mAdapter.setEventListener(new FavoritesSongAdapter.EventListener() {

        @Override
        public void onDeleteEventChanged(Favorite.FavoritesSong favoritesSong) {
            if (mPresenter != null) {
                mPresenter.deleteFavoriteSong(favoritesSong);
            }
        }

        @Override
        public void onPlaylistChanged(Audient audient) {
            PaymentDialogFragment.show(getChildFragmentManager(), audient);
        }
    });
    mRecyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.addItemDecoration(new AudientItemDecoration(mContext));
    mRecyclerView.setAdapter(mAdapter);
    if (mPresenter != null) {
        mPresenter.loadData(mFavorite.favoritesId);
    }
}
Also used : Favorite(com.xinshang.audient.model.entities.Favorite) AudientItemDecoration(com.xinshang.audient.widget.AudientItemDecoration) Audient(com.xinshang.audient.model.entities.Audient) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 5 with Audient

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

the class MinePresenter method loadDynamics.

@Override
public void loadDynamics() {
    Disposable disposable = mRepository.getAudientTests().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Audient>>() {

        @Override
        public void onNext(List<Audient> audients) {
            if (mView.isActive()) {
                mView.showUserProgressBar(false);
                mView.showDynamics(audients);
            }
        }

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

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

Aggregations

Audient (com.xinshang.audient.model.entities.Audient)13 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 AudientItemDecoration (com.xinshang.audient.widget.AudientItemDecoration)5 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)5 Disposable (io.reactivex.disposables.Disposable)5 Intent (android.content.Intent)4 MyFavoritesActivity (com.xinshang.audient.favorite.MyFavoritesActivity)4 Function (io.reactivex.functions.Function)4 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)3 AudientAdapter (com.xinshang.audient.base.AudientAdapter)3 List (java.util.List)3 Favorite (com.xinshang.audient.model.entities.Favorite)2 AudientApplication (com.xinshang.audient.AudientApplication)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 SearchResult (com.xinshang.audient.model.entities.SearchResult)1 SongDetailResult (com.xinshang.audient.model.entities.SongDetailResult)1 ToplistDetailResult (com.xinshang.audient.model.entities.ToplistDetailResult)1 Publisher (org.reactivestreams.Publisher)1