Example #1
0
  @Override
  public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    final Artist localItem = arraylist.get(i);

    itemHolder.name.setText(localItem.name);
    String albumNmber = TimberUtils.makeLabel(mContext, R.plurals.Nalbums, localItem.albumCount);
    String songCount = TimberUtils.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount);
    itemHolder.albums.setText(TimberUtils.makeCombinedString(mContext, albumNmber, songCount));

    LastFmClient.getInstance(mContext)
        .getArtistInfo(
            new ArtistQuery(localItem.name),
            new ArtistInfoListener() {
              @Override
              public void artistInfoSucess(LastfmArtist artist) {
                ImageLoader.getInstance()
                    .displayImage(
                        artist.mArtwork.get(1).mUrl,
                        itemHolder.artistImage,
                        new DisplayImageOptions.Builder()
                            .cacheInMemory(true)
                            .cacheOnDisk(true)
                            .showImageOnFail(R.drawable.ic_empty_music2)
                            .resetViewBeforeLoading(true)
                            .displayer(new FadeInBitmapDisplayer(400))
                            .build());
              }

              @Override
              public void artistInfoFailed() {}
            });
  }
Example #2
0
  @Override
  public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    Album localItem = arraylist.get(i);

    itemHolder.title.setText(localItem.title);
    itemHolder.artist.setText(localItem.artistName);

    ImageLoader.getInstance()
        .displayImage(
            TimberUtils.getAlbumArtUri(localItem.id).toString(),
            itemHolder.albumArt,
            new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .showImageOnFail(R.drawable.ic_empty_music2)
                .resetViewBeforeLoading(true)
                .displayer(new FadeInBitmapDisplayer(400))
                .build(),
            new SimpleImageLoadingListener() {
              @Override
              public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                if (isGrid) {
                  new Palette.Builder(loadedImage)
                      .generate(
                          new Palette.PaletteAsyncListener() {
                            @Override
                            public void onGenerated(Palette palette) {
                              Palette.Swatch swatch = palette.getVibrantSwatch();
                              if (swatch != null) {
                                int color = swatch.getRgb();
                                itemHolder.footer.setBackgroundColor(color);
                                int textColor =
                                    TimberUtils.getBlackWhiteColor(swatch.getTitleTextColor());
                                itemHolder.title.setTextColor(textColor);
                                itemHolder.artist.setTextColor(textColor);
                              } else {
                                Palette.Swatch mutedSwatch = palette.getMutedSwatch();
                                if (mutedSwatch != null) {
                                  int color = mutedSwatch.getRgb();
                                  itemHolder.footer.setBackgroundColor(color);
                                  int textColor =
                                      TimberUtils.getBlackWhiteColor(
                                          mutedSwatch.getTitleTextColor());
                                  itemHolder.title.setTextColor(textColor);
                                  itemHolder.artist.setTextColor(textColor);
                                }
                              }
                            }
                          });
                }
              }

              @Override
              public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                if (isGrid) {
                  itemHolder.footer.setBackgroundColor(0);
                  if (mContext != null) {
                    int textColorPrimary =
                        Config.textColorPrimary(mContext, Helpers.getATEKey(mContext));
                    itemHolder.title.setTextColor(textColorPrimary);
                    itemHolder.artist.setTextColor(textColorPrimary);
                  }
                }
              }
            });

    if (TimberUtils.isLollipop()) itemHolder.albumArt.setTransitionName("transition_album_art" + i);
  }