use of io.hefuyi.listener.mvp.usecase.GetArtistInfo 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);
}
Aggregations