use of com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder in project Phonograph by kabouzeid.
the class AlbumTagEditorActivity method getImageFromLastFM.
@Override
protected void getImageFromLastFM() {
String albumTitleStr = albumTitle.getText().toString();
String albumArtistNameStr = albumArtist.getText().toString();
if (albumArtistNameStr.trim().equals("") || albumTitleStr.trim().equals("")) {
Toast.makeText(this, getResources().getString(R.string.album_or_artist_empty), Toast.LENGTH_SHORT).show();
return;
}
lastFMRestClient.getApiService().getAlbumInfo(albumTitleStr, albumArtistNameStr, null).enqueue(new Callback<LastFmAlbum>() {
@Override
public void onResponse(Call<LastFmAlbum> call, Response<LastFmAlbum> response) {
LastFmAlbum lastFmAlbum = response.body();
if (lastFmAlbum.getAlbum() != null) {
String url = LastFMUtil.getLargestAlbumImageUrl(lastFmAlbum.getAlbum().getImage());
if (!TextUtils.isEmpty(url) && url.trim().length() > 0) {
Glide.with(AlbumTagEditorActivity.this).load(url).asBitmap().transcode(new BitmapPaletteTranscoder(AlbumTagEditorActivity.this), BitmapPaletteWrapper.class).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(R.drawable.default_album_art).into(new SimpleTarget<BitmapPaletteWrapper>() {
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
e.printStackTrace();
Toast.makeText(AlbumTagEditorActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
albumArtBitmap = ImageUtil.resizeBitmap(resource.getBitmap(), 2048);
setImageBitmap(albumArtBitmap, PhonographColorUtil.getColor(resource.getPalette(), ATHUtil.resolveColor(AlbumTagEditorActivity.this, R.attr.defaultFooterColor)));
deleteAlbumArt = false;
dataChanged();
setResult(RESULT_OK);
}
});
return;
}
}
toastLoadingFailed();
}
@Override
public void onFailure(Call<LastFmAlbum> call, Throwable t) {
toastLoadingFailed();
}
private void toastLoadingFailed() {
Toast.makeText(AlbumTagEditorActivity.this, R.string.could_not_download_album_cover, Toast.LENGTH_SHORT).show();
}
});
}
Aggregations