Search in sources :

Example 1 with ArtistArt

use of io.hefuyi.listener.mvp.model.ArtistArt in project ListenerMusicPlayer by hefuyicoder.

the class ArtistDetailPresenter method loadArtistArt.

@Override
public void loadArtistArt(long artistID) {
    String artistArtJson = PreferencesUtility.getInstance(mView.getContext()).getArtistArt(artistID);
    if (!TextUtils.isEmpty(artistArtJson)) {
        ArtistArt artistArt = new Gson().fromJson(artistArtJson, ArtistArt.class);
        Glide.with(ListenerApp.getContext()).load(artistArt.getExtralarge()).asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.IMMEDIATE).error(ATEUtil.getDefaultSingerDrawable(mView.getContext())).into(new SimpleTarget<Bitmap>() {

            @Override
            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                super.onLoadFailed(e, errorDrawable);
                mView.showArtistArt(errorDrawable);
            }

            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                mView.showArtistArt(resource);
            }
        });
    }
}
Also used : Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) Gson(com.google.gson.Gson) ArtistArt(io.hefuyi.listener.mvp.model.ArtistArt)

Example 2 with ArtistArt

use of io.hefuyi.listener.mvp.model.ArtistArt in project ListenerMusicPlayer by hefuyicoder.

the class SearchAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ItemHolder itemHolder, int position) {
    switch(getItemViewType(position)) {
        case 0:
            Song song = (Song) searchResults.get(position);
            itemHolder.title.setText(song.title);
            itemHolder.subtitle1.setText(song.artistName);
            itemHolder.subtitle2.setText(song.albumName);
            Glide.with(itemHolder.itemView.getContext()).load(ListenerUtil.getAlbumArtUri(song.albumId).toString()).error(ATEUtil.getDefaultAlbumDrawable(mContext)).placeholder(ATEUtil.getDefaultAlbumDrawable(mContext)).centerCrop().into(itemHolder.image);
            setOnPopupMenuListener(itemHolder, 0, position);
            break;
        case 1:
            Album album = (Album) searchResults.get(position);
            itemHolder.title.setText(album.title);
            itemHolder.subtitle1.setText(album.artistName);
            itemHolder.subtitle2.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, album.songCount));
            Glide.with(itemHolder.itemView.getContext()).load(ListenerUtil.getAlbumArtUri(album.id).toString()).asBitmap().placeholder(ATEUtil.getDefaultAlbumDrawable(mContext)).error(ATEUtil.getDefaultAlbumDrawable(mContext)).centerCrop().into(itemHolder.image);
            if (ListenerUtil.isLollipop())
                itemHolder.image.setTransitionName("transition_album_art" + position);
            setOnPopupMenuListener(itemHolder, 1, position);
            break;
        case 2:
            Artist artist = (Artist) searchResults.get(position);
            itemHolder.title.setText(artist.name);
            itemHolder.subtitle1.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nalbums, artist.albumCount));
            itemHolder.subtitle2.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, artist.songCount));
            String artistArtJson = PreferencesUtility.getInstance(mContext).getArtistArt(artist.id);
            if (!TextUtils.isEmpty(artistArtJson)) {
                ArtistArt artistArt = new Gson().fromJson(artistArtJson, ArtistArt.class);
                Glide.with(mContext).load(artistArt.getLarge()).asBitmap().placeholder(ATEUtil.getDefaultSingerDrawable(mContext)).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(ATEUtil.getDefaultSingerDrawable(mContext)).into(itemHolder.image);
            }
            if (ListenerUtil.isLollipop())
                itemHolder.image.setTransitionName("transition_artist_art" + position);
            setOnPopupMenuListener(itemHolder, 2, position);
            break;
        case 10:
            itemHolder.sectionHeader.setText((String) searchResults.get(position));
        case 3:
            break;
    }
}
Also used : Artist(io.hefuyi.listener.mvp.model.Artist) Song(io.hefuyi.listener.mvp.model.Song) Album(io.hefuyi.listener.mvp.model.Album) Gson(com.google.gson.Gson) ArtistArt(io.hefuyi.listener.mvp.model.ArtistArt)

Example 3 with ArtistArt

use of io.hefuyi.listener.mvp.model.ArtistArt 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)3 ArtistArt (io.hefuyi.listener.mvp.model.ArtistArt)3 Artist (io.hefuyi.listener.mvp.model.Artist)2 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 ArtistInfo (io.hefuyi.listener.api.model.ArtistInfo)1 Album (io.hefuyi.listener.mvp.model.Album)1 Song (io.hefuyi.listener.mvp.model.Song)1 GetArtistInfo (io.hefuyi.listener.mvp.usecase.GetArtistInfo)1 List (java.util.List)1 Func1 (rx.functions.Func1)1