Search in sources :

Example 1 with ArtistInfo

use of io.hefuyi.listener.api.model.ArtistInfo in project ListenerMusicPlayer by hefuyicoder.

the class ArtistAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    final Artist localItem = arraylist.get(i);
    itemHolder.name.setText(localItem.name);
    itemHolder.albumCount.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nalbums, localItem.albumCount));
    itemHolder.songCount.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount));
    String artistArtJson = PreferencesUtility.getInstance(mContext).getArtistArt(localItem.id);
    if (TextUtils.isEmpty(artistArtJson)) {
        getArtistInfo.execute(new GetArtistInfo.RequestValues(localItem.name)).getArtistInfo().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).onErrorReturn(new Func1<Throwable, ArtistInfo>() {

            @Override
            public ArtistInfo call(Throwable throwable) {
                Toast.makeText(itemHolder.itemView.getContext(), R.string.load_artist_fail, Toast.LENGTH_SHORT).show();
                return null;
            }
        }).subscribe(new Action1<ArtistInfo>() {

            @Override
            public void call(ArtistInfo artistInfo) {
                if (artistInfo != null && artistInfo.mArtist != null && artistInfo.mArtist.mArtwork != null) {
                    List<Artwork> artworks = artistInfo.mArtist.mArtwork;
                    ArtistArt artistArt = new ArtistArt(artworks.get(0).mUrl, artworks.get(1).mUrl, artworks.get(2).mUrl, artworks.get(3).mUrl);
                    PreferencesUtility.getInstance(mContext).setArtistArt(localItem.id, new Gson().toJson(artistArt));
                    loadArtistArt(artistArt, itemHolder);
                }
            }
        });
    } else {
        ArtistArt artistArt = new Gson().fromJson(artistArtJson, ArtistArt.class);
        loadArtistArt(artistArt, itemHolder);
    }
    if (ListenerUtil.isLollipop())
        itemHolder.artistImage.setTransitionName("transition_artist_art" + i);
    setOnPopupMenuListener(itemHolder, i);
}
Also used : Artist(io.hefuyi.listener.mvp.model.Artist) Gson(com.google.gson.Gson) List(java.util.List) Func1(rx.functions.Func1) ArtistArt(io.hefuyi.listener.mvp.model.ArtistArt) ArtistInfo(io.hefuyi.listener.api.model.ArtistInfo) GetArtistInfo(io.hefuyi.listener.mvp.usecase.GetArtistInfo)

Aggregations

Gson (com.google.gson.Gson)1 ArtistInfo (io.hefuyi.listener.api.model.ArtistInfo)1 Artist (io.hefuyi.listener.mvp.model.Artist)1 ArtistArt (io.hefuyi.listener.mvp.model.ArtistArt)1 GetArtistInfo (io.hefuyi.listener.mvp.usecase.GetArtistInfo)1 List (java.util.List)1 Func1 (rx.functions.Func1)1