Search in sources :

Example 1 with StoreSong

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

the class PlaylistAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(PlaylistViewHolder holder, int position) {
    StoreSong storePlaylist = mData.get(position);
    mGlideRequest.load(storePlaylist).into(holder.mAlbum);
    holder.mName.setText(storePlaylist.mediaName);
    if (storePlaylist.isPlaying) {
        holder.mName.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
    } else {
        holder.mName.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryText));
    }
    holder.mArtistName.setText(storePlaylist.artistName);
}
Also used : StoreSong(com.xinshang.audient.model.entities.StoreSong)

Example 2 with StoreSong

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

the class PlaylistPresenter method loadStorePlaylist.

@Override
public void loadStorePlaylist() {
    String storeId = mRepository.getStoreId();
    mRepository.getStorePlaylist(storeId).map(new Function<ApiResponse<List<StoreSong>>, List<StoreSong>>() {

        @Override
        public List<StoreSong> apply(ApiResponse<List<StoreSong>> listApiResponse) throws Exception {
            return listApiResponse.data;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<StoreSong>>() {

        @Override
        public void onNext(List<StoreSong> storePlaylists) {
            mPlaylist = storePlaylists;
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadStorePlaylist error : " + t.getMessage());
            if (mView.isActive()) {
                mView.setLoadingIndicator(false);
            }
        }

        @Override
        public void onComplete() {
            if (mView.isActive()) {
                mView.setLoadingIndicator(false);
            }
            sendCommand(COMMAND_BIND);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) ArrayList(java.util.ArrayList) List(java.util.List) ByteString(okio.ByteString) StoreSong(com.xinshang.audient.model.entities.StoreSong) ApiResponse(com.xinshang.audient.model.entities.ApiResponse)

Example 3 with StoreSong

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

the class PlaylistPresenter method loadNowPlaying.

@Override
public void loadNowPlaying(String id) {
    Disposable disposable = Flowable.just(id).flatMap(new Function<String, Publisher<List<StoreSong>>>() {

        @Override
        public Publisher<List<StoreSong>> apply(String s) throws Exception {
            List<StoreSong> storePlaylists = new ArrayList<>();
            for (StoreSong storePlaylist : mPlaylist) {
                StoreSong playlist = new StoreSong();
                playlist.id = storePlaylist.id;
                playlist.mediaName = storePlaylist.mediaName;
                playlist.mediaId = storePlaylist.mediaId;
                playlist.storeId = storePlaylist.storeId;
                playlist.albumId = storePlaylist.albumId;
                playlist.albumName = storePlaylist.albumName;
                playlist.artistId = storePlaylist.artistId;
                playlist.artistName = storePlaylist.artistName;
                playlist.demandId = storePlaylist.demandId;
                playlist.demandTime = storePlaylist.demandTime;
                playlist.mediaInterval = storePlaylist.mediaInterval;
                playlist.mediaSource = storePlaylist.mediaSource;
                playlist.joinedDate = storePlaylist.joinedDate;
                playlist.userId = storePlaylist.userId;
                if (TextUtils.equals(s, storePlaylist.id)) {
                    playlist.isPlaying = true;
                    mNowPlaying = storePlaylist;
                } else {
                    playlist.isPlaying = false;
                }
                storePlaylists.add(playlist);
            }
            return Flowable.just(storePlaylists);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<StoreSong>>() {

        @Override
        public void onNext(List<StoreSong> storePlaylists) {
            if (mView.isActive()) {
                mView.showNowPlaying(mNowPlaying);
                mView.showPlaylist(storePlaylists);
            }
        }

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

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

Aggregations

StoreSong (com.xinshang.audient.model.entities.StoreSong)3 Function (io.reactivex.functions.Function)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ByteString (okio.ByteString)2 ApiResponse (com.xinshang.audient.model.entities.ApiResponse)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1