Search in sources :

Example 1 with LastFmAlbum

use of com.kabouzeid.gramophone.lastfm.rest.model.LastFmAlbum 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();
        }
    });
}
Also used : BitmapPaletteWrapper(com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper) LastFmAlbum(com.kabouzeid.gramophone.lastfm.rest.model.LastFmAlbum) Drawable(android.graphics.drawable.Drawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) BitmapPaletteTranscoder(com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder)

Aggregations

Drawable (android.graphics.drawable.Drawable)1 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 BitmapPaletteTranscoder (com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder)1 BitmapPaletteWrapper (com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper)1 LastFmAlbum (com.kabouzeid.gramophone.lastfm.rest.model.LastFmAlbum)1