Made some progress with glide.
This commit is contained in:
parent
0146676dbc
commit
3393136f2e
20 changed files with 361 additions and 186 deletions
|
|
@ -12,7 +12,7 @@ import android.widget.ImageView;
|
|||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.misc.CustomFragmentStatePagerAdapter;
|
||||
|
|
@ -134,7 +134,7 @@ public class AlbumCoverPagerAdapter extends CustomFragmentStatePagerAdapter {
|
|||
.transcode(new BitmapPaletteTranscoder(getActivity()), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredImageViewTarget(albumCover) {
|
||||
.into(new PhonographColoredTarget(albumCover) {
|
||||
@Override
|
||||
public void onColorReady(int color) {
|
||||
setColor(color);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.bumptech.glide.Glide;
|
|||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.base.MediaEntryViewHolder;
|
||||
import com.kabouzeid.gramophone.glide.artistimage.ArtistImageRequest;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.helper.menu.SongMenuHelper;
|
||||
import com.kabouzeid.gramophone.loader.AlbumLoader;
|
||||
|
|
@ -98,26 +99,19 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
|||
.loadFromMediaStore(MusicUtil.getAlbumArtUri(album.id))
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.into(holder.image);
|
||||
break;
|
||||
case ARTIST:
|
||||
final Artist artist = (Artist) results.get(position);
|
||||
holder.title.setText(artist.name);
|
||||
holder.text.setText(MusicUtil.getArtistInfoString(activity, artist));
|
||||
if (MusicUtil.isArtistNameUnknown(artist.name)) {
|
||||
holder.image.setImageResource(R.drawable.default_artist_image);
|
||||
break;
|
||||
}
|
||||
// TODO Glide
|
||||
// ImageLoader.getInstance().displayImage(MusicUtil.getArtistImageLoaderString(artist, false),
|
||||
// holder.image,
|
||||
// new DisplayImageOptions.Builder()
|
||||
// .cacheInMemory(true)
|
||||
// .cacheOnDisk(true)
|
||||
// .resetViewBeforeLoading(true)
|
||||
// .showImageOnFail(R.drawable.default_artist_image)
|
||||
// .build()
|
||||
// );
|
||||
Glide.with(activity)
|
||||
.load(new ArtistImageRequest(artist.name, false))
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.into(holder.image);
|
||||
break;
|
||||
case SONG:
|
||||
final Song song = (Song) results.get(position);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import com.kabouzeid.gramophone.adapter.base.AbsMultiSelectAdapter;
|
|||
import com.kabouzeid.gramophone.adapter.base.MediaEntryViewHolder;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
|
|
@ -38,7 +38,6 @@ import java.util.List;
|
|||
public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder, Album> {
|
||||
|
||||
public static final String TAG = AlbumAdapter.class.getSimpleName();
|
||||
private static final int FADE_IN_TIME = 500;
|
||||
|
||||
protected final AppCompatActivity activity;
|
||||
protected List<Album> dataSet;
|
||||
|
|
@ -86,10 +85,6 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
return album.artistName;
|
||||
}
|
||||
|
||||
protected String getAlbumImageLoaderUri(Album album) {
|
||||
return MusicUtil.getAlbumImageLoaderString(album);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||
final Album album = dataSet.get(position);
|
||||
|
|
@ -133,7 +128,8 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
.transcode(new BitmapPaletteTranscoder(activity), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredImageViewTarget(holder.image) {
|
||||
.animate(android.R.anim.fade_in)
|
||||
.into(new PhonographColoredTarget(holder.image) {
|
||||
@Override
|
||||
public void onColorReady(int color) {
|
||||
if (usePalette)
|
||||
|
|
|
|||
|
|
@ -10,11 +10,17 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.base.AbsMultiSelectAdapter;
|
||||
import com.kabouzeid.gramophone.adapter.base.MediaEntryViewHolder;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.artistimage.ArtistImageRequest;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.loader.ArtistSongLoader;
|
||||
|
|
@ -112,39 +118,20 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
|
||||
protected void loadArtistImage(Artist artist, final ViewHolder holder) {
|
||||
if (holder.image == null) return;
|
||||
//TODO Glide
|
||||
// ImageLoader.getInstance().displayImage(MusicUtil.getArtistImageLoaderString(artist, false),
|
||||
// holder.image,
|
||||
// new DisplayImageOptions.Builder()
|
||||
// .cacheInMemory(true)
|
||||
// .cacheOnDisk(true)
|
||||
// .resetViewBeforeLoading(true)
|
||||
// .showImageOnFail(R.drawable.default_artist_image)
|
||||
// .postProcessor(new BitmapProcessor() {
|
||||
// @Override
|
||||
// public Bitmap process(Bitmap bitmap) {
|
||||
// holder.paletteColor = ColorUtil.generateColor(activity, bitmap);
|
||||
// return bitmap;
|
||||
// }
|
||||
// })
|
||||
// .displayer(new FadeInBitmapDisplayer(FADE_IN_TIME, true, true, false) {
|
||||
// @Override
|
||||
// public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
|
||||
// super.display(bitmap, imageAware, loadedFrom);
|
||||
// if (usePalette)
|
||||
// setColors(holder.paletteColor, holder);
|
||||
// }
|
||||
// })
|
||||
// .build(),
|
||||
// new SimpleImageLoadingListener() {
|
||||
// @Override
|
||||
// public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
// FadeInBitmapDisplayer.animate(view, FADE_IN_TIME);
|
||||
// if (usePalette)
|
||||
// setColors(ColorUtil.resolveColor(activity, R.attr.default_bar_color), holder);
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
Glide.with(activity)
|
||||
.load(new ArtistImageRequest(artist.name, false))
|
||||
.asBitmap()
|
||||
.transcode(new BitmapPaletteTranscoder(activity), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.error(R.drawable.default_album_art)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.into(new PhonographColoredTarget(holder.image) {
|
||||
@Override
|
||||
public void onColorReady(int color) {
|
||||
if (usePalette)
|
||||
setColors(color, holder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -41,11 +41,6 @@ public class AlbumSongAdapter extends SongAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSongImageLoaderUri(Song song) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSongText(Song song) {
|
||||
return MusicUtil.getReadableDurationString(song.duration);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import com.kabouzeid.gramophone.adapter.base.AbsMultiSelectAdapter;
|
|||
import com.kabouzeid.gramophone.adapter.base.MediaEntryViewHolder;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
|
|
@ -128,7 +128,8 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
.transcode(new BitmapPaletteTranscoder(activity), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredImageViewTarget(holder.image) {
|
||||
.animate(android.R.anim.fade_in)
|
||||
.into(new PhonographColoredTarget(holder.image) {
|
||||
@Override
|
||||
public void onColorReady(int color) {
|
||||
if (usePalette)
|
||||
|
|
@ -145,10 +146,6 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
return song.artistName;
|
||||
}
|
||||
|
||||
protected String getSongImageLoaderUri(Song song) {
|
||||
return MusicUtil.getSongImageLoaderString(song);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return dataSet.size();
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
package com.kabouzeid.gramophone.glide;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.util.ColorUtil;
|
||||
|
||||
public abstract class PhonographColoredImageViewTarget extends BitmapPaletteImageViewTarget {
|
||||
public PhonographColoredImageViewTarget(ImageView view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
super.onLoadFailed(e, errorDrawable);
|
||||
onColorReady(getDefaultBarColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
super.onResourceReady(resource, glideAnimation);
|
||||
onColorReady(ColorUtil.getColor(resource.getPalette(), getDefaultBarColor()));
|
||||
}
|
||||
|
||||
private int getDefaultBarColor() {
|
||||
return ColorUtil.resolveColor(getView().getContext(), R.attr.default_bar_color);
|
||||
}
|
||||
|
||||
public abstract void onColorReady(int color);
|
||||
}
|
||||
|
|
@ -1,32 +1,17 @@
|
|||
package com.kabouzeid.gramophone.glide;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.util.ColorUtil;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class PhonographColoredTarget extends SimpleTarget<BitmapPaletteWrapper> {
|
||||
private Context context;
|
||||
|
||||
public PhonographColoredTarget(Context context) {
|
||||
super();
|
||||
init(context);
|
||||
}
|
||||
|
||||
public PhonographColoredTarget(Context context, int width, int height) {
|
||||
super(width, height);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
this.context = context;
|
||||
public abstract class PhonographColoredTarget extends BitmapPaletteTarget {
|
||||
public PhonographColoredTarget(ImageView view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -37,11 +22,12 @@ public abstract class PhonographColoredTarget extends SimpleTarget<BitmapPalette
|
|||
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
super.onResourceReady(resource, glideAnimation);
|
||||
onColorReady(ColorUtil.getColor(resource.getPalette(), getDefaultBarColor()));
|
||||
}
|
||||
|
||||
private int getDefaultBarColor() {
|
||||
return ColorUtil.resolveColor(context, R.attr.default_bar_color);
|
||||
return ColorUtil.resolveColor(getView().getContext(), R.attr.default_bar_color);
|
||||
}
|
||||
|
||||
public abstract void onColorReady(int color);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,12 @@ import android.content.Context;
|
|||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.GlideBuilder;
|
||||
import com.bumptech.glide.module.GlideModule;
|
||||
import com.kabouzeid.gramophone.glide.artistimage.ArtistImageLoader;
|
||||
import com.kabouzeid.gramophone.glide.artistimage.ArtistImageRequest;
|
||||
import com.kabouzeid.gramophone.glide.audiocover.SongCoverLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
|
|
@ -17,6 +23,7 @@ public class PhonographGlideModule implements GlideModule {
|
|||
|
||||
@Override
|
||||
public void registerComponents(Context context, Glide glide) {
|
||||
|
||||
glide.register(Song.class, InputStream.class, new SongCoverLoader.Factory());
|
||||
glide.register(ArtistImageRequest.class, InputStream.class, new ArtistImageLoader.Factory(context));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package com.kabouzeid.gramophone.glide.artistimage;
|
||||
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.data.HttpUrlFetcher;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
import com.kabouzeid.gramophone.lastfm.rest.LastFMRestClient;
|
||||
import com.kabouzeid.gramophone.lastfm.rest.model.LastFmArtist;
|
||||
import com.kabouzeid.gramophone.util.LastFMUtil;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistImageFetcher implements DataFetcher<InputStream> {
|
||||
private final LastFMRestClient lastFMRestClient;
|
||||
private final ArtistImageRequest model;
|
||||
private HttpUrlFetcher urlFetcher;
|
||||
private volatile boolean isCancelled;
|
||||
|
||||
public ArtistImageFetcher(LastFMRestClient lastFMRestClient, ArtistImageRequest model) {
|
||||
this.lastFMRestClient = lastFMRestClient;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return model.artistName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream loadData(Priority priority) throws Exception {
|
||||
if (MusicUtil.isArtistNameUnknown(model.artistName)) return null;
|
||||
|
||||
LastFmArtist lastFmArtist = lastFMRestClient.getApiService().getArtistInfo(model.artistName, model.forceDownload ? "no-cache" : null).execute().body();
|
||||
|
||||
if (isCancelled) return null;
|
||||
|
||||
urlFetcher = new HttpUrlFetcher(new GlideUrl(LastFMUtil.getLargestArtistImageUrl(lastFmArtist.getArtist().getImage())));
|
||||
return urlFetcher.loadData(priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
if (urlFetcher != null) {
|
||||
urlFetcher.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
isCancelled = true;
|
||||
if (urlFetcher != null) {
|
||||
urlFetcher.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.kabouzeid.gramophone.glide.artistimage;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.model.GenericLoaderFactory;
|
||||
import com.bumptech.glide.load.model.ModelLoader;
|
||||
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
||||
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
||||
import com.kabouzeid.gramophone.lastfm.rest.LastFMRestClient;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
||||
public class ArtistImageLoader implements StreamModelLoader<ArtistImageRequest> {
|
||||
private LastFMRestClient lastFMRestClient;
|
||||
|
||||
public ArtistImageLoader(LastFMRestClient lastFMRestClient) {
|
||||
this.lastFMRestClient = lastFMRestClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(ArtistImageRequest model, int width, int height) {
|
||||
return new ArtistImageFetcher(lastFMRestClient, model);
|
||||
}
|
||||
|
||||
public static class Factory implements ModelLoaderFactory<ArtistImageRequest, InputStream> {
|
||||
private static volatile LastFMRestClient internalClient;
|
||||
private LastFMRestClient client;
|
||||
|
||||
private static LastFMRestClient getInternalClient(Context context) {
|
||||
if (internalClient == null) {
|
||||
synchronized (Factory.class) {
|
||||
if (internalClient == null) {
|
||||
internalClient = new LastFMRestClient(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return internalClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a new Factory that runs requests using a static singleton client.
|
||||
*/
|
||||
public Factory(Context context) {
|
||||
client = getInternalClient(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelLoader<ArtistImageRequest, InputStream> build(Context context, GenericLoaderFactory factories) {
|
||||
return new ArtistImageLoader(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teardown() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.kabouzeid.gramophone.glide.artistimage;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistImageRequest {
|
||||
public final String artistName;
|
||||
public final boolean forceDownload;
|
||||
|
||||
public ArtistImageRequest(String artistName, boolean forceDownload) {
|
||||
this.artistName = artistName;
|
||||
this.forceDownload = forceDownload;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package com.kabouzeid.gramophone.glide.audiocover;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class AudioFileCoverFetcher implements DataFetcher<InputStream> {
|
||||
private final Song model;
|
||||
private FileInputStream stream;
|
||||
private Context context;
|
||||
|
||||
public AudioFileCoverFetcher(Context context, Song model) {
|
||||
this.context = context;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return model.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream loadData(Priority priority) throws Exception {
|
||||
// MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
||||
// try {
|
||||
// retriever.setDataSource(model.data);
|
||||
// byte[] picture = retriever.getEmbeddedPicture();
|
||||
// if (picture != null) {
|
||||
// return new ByteArrayInputStream(picture);
|
||||
// } else {
|
||||
// return fallback(model.data);
|
||||
// }
|
||||
// } finally {
|
||||
// retriever.release();
|
||||
// }
|
||||
return context.getContentResolver().openInputStream(MusicUtil.getAlbumArtUri(model.albumId));
|
||||
}
|
||||
|
||||
private static final String[] FALLBACKS = {"cover.jpg", "album.jpg", "folder.jpg"};
|
||||
|
||||
private InputStream fallback(String path) throws FileNotFoundException {
|
||||
File parent = new File(path).getParentFile();
|
||||
for (String fallback : FALLBACKS) {
|
||||
// TODO make it smarter by enumerating folder contents and filtering for files
|
||||
// example algorithm for that: http://askubuntu.com/questions/123612/how-do-i-set-album-artwork
|
||||
File cover = new File(parent, fallback);
|
||||
if (cover.exists()) {
|
||||
return stream = new FileInputStream(cover);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// already cleaned up in loadData and ByteArrayInputStream will be GC'd
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ignore) {
|
||||
// can't do much about it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
// cannot cancel
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.kabouzeid.gramophone.glide.audiocover;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.model.GenericLoaderFactory;
|
||||
import com.bumptech.glide.load.model.ModelLoader;
|
||||
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
||||
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
||||
public class SongCoverLoader implements StreamModelLoader<Song> {
|
||||
private Context context;
|
||||
|
||||
public SongCoverLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(Song model, int width, int height) {
|
||||
return new AudioFileCoverFetcher(context, model);
|
||||
}
|
||||
|
||||
public static class Factory implements ModelLoaderFactory<Song, InputStream> {
|
||||
@Override
|
||||
public ModelLoader<Song, InputStream> build(Context context, GenericLoaderFactory factories) {
|
||||
return new SongCoverLoader(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teardown() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4,8 +4,8 @@ import android.widget.ImageView;
|
|||
|
||||
import com.bumptech.glide.request.target.ImageViewTarget;
|
||||
|
||||
public class BitmapPaletteImageViewTarget extends ImageViewTarget<BitmapPaletteWrapper> {
|
||||
public BitmapPaletteImageViewTarget(ImageView view) {
|
||||
public class BitmapPaletteTarget extends ImageViewTarget<BitmapPaletteWrapper> {
|
||||
public BitmapPaletteTarget(ImageView view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView;
|
|||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.song.AlbumSongAdapter;
|
||||
import com.kabouzeid.gramophone.dialogs.SleepTimerDialog;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredImageViewTarget;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
|
|
@ -163,7 +163,7 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
.transcode(new BitmapPaletteTranscoder(this), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredImageViewTarget(albumArtImageView) {
|
||||
.into(new PhonographColoredTarget(albumArtImageView) {
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
super.onResourceReady(resource, glideAnimation);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.kabouzeid.gramophone.ui.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
|
@ -21,11 +22,18 @@ import android.widget.Toast;
|
|||
import com.afollestad.materialcab.MaterialCab;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.afollestad.materialdialogs.util.DialogUtils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.github.ksoichiro.android.observablescrollview.ObservableListView;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.album.HorizontalAlbumAdapter;
|
||||
import com.kabouzeid.gramophone.adapter.song.ArtistSongAdapter;
|
||||
import com.kabouzeid.gramophone.dialogs.SleepTimerDialog;
|
||||
import com.kabouzeid.gramophone.glide.PhonographColoredTarget;
|
||||
import com.kabouzeid.gramophone.glide.artistimage.ArtistImageRequest;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
|
||||
|
|
@ -242,53 +250,37 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
}
|
||||
|
||||
private void setUpArtistImageAndApplyPalette(final boolean forceDownload) {
|
||||
// TODO Glide
|
||||
// ImageLoader.getInstance().displayImage(MusicUtil.getArtistImageLoaderString(artist, forceDownload),
|
||||
// artistImage,
|
||||
// new DisplayImageOptions.Builder()
|
||||
// .cacheInMemory(true)
|
||||
// .cacheOnDisk(true)
|
||||
// .showImageOnFail(R.drawable.default_artist_image)
|
||||
// .resetViewBeforeLoading(true)
|
||||
// .postProcessor(new BitmapProcessor() {
|
||||
// @Override
|
||||
// public Bitmap process(Bitmap bitmap) {
|
||||
// final int color = ColorUtil.generateColor(ArtistDetailActivity.this, bitmap);
|
||||
// runOnUiThread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// setColors(color);
|
||||
// }
|
||||
// });
|
||||
// return bitmap;
|
||||
// }
|
||||
// })
|
||||
// .build(),
|
||||
// new SimpleImageLoadingListener() {
|
||||
// @Override
|
||||
// public void onLoadingFailed(String imageUri, View view, @Nullable FailReason failReason) {
|
||||
// setColors(ColorUtil.resolveColor(ArtistDetailActivity.this, R.attr.default_bar_color));
|
||||
//
|
||||
// toastUpdatedArtistImageIfDownloadWasForced();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
|
||||
// if (loadedImage == null) {
|
||||
// onLoadingFailed(imageUri, view, null);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// toastUpdatedArtistImageIfDownloadWasForced();
|
||||
// }
|
||||
//
|
||||
// private void toastUpdatedArtistImageIfDownloadWasForced() {
|
||||
// if (forceDownload) {
|
||||
// Toast.makeText(ArtistDetailActivity.this, getString(R.string.updated_artist_image), Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
Glide.with(this)
|
||||
.load(new ArtistImageRequest(artist.name, forceDownload))
|
||||
.asBitmap()
|
||||
.transcode(new BitmapPaletteTranscoder(this), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.error(R.drawable.default_album_art)
|
||||
.into(new PhonographColoredTarget(artistImage) {
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
super.onLoadFailed(e, errorDrawable);
|
||||
toastUpdatedArtistImageIfDownloadWasForced();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
|
||||
super.onResourceReady(resource, glideAnimation);
|
||||
toastUpdatedArtistImageIfDownloadWasForced();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorReady(int color) {
|
||||
setColors(color);
|
||||
}
|
||||
|
||||
private void toastUpdatedArtistImageIfDownloadWasForced() {
|
||||
if (forceDownload) {
|
||||
Toast.makeText(ArtistDetailActivity.this, getString(R.string.updated_artist_image), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -278,6 +278,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
.loadFromMediaStore(MusicUtil.getAlbumArtUri(song.albumId))
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.default_album_art)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.into(((ImageView) navigationDrawerHeader.findViewById(R.id.image)));
|
||||
} else {
|
||||
if (navigationDrawerHeader != null) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import com.kabouzeid.gramophone.util.ColorUtil;
|
|||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
import org.jaudiotagger.audio.AudioFileIO;
|
||||
|
|
@ -387,14 +386,11 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
progressDialog.setContent(getString(R.string.rescanning_media));
|
||||
if (deleteArtwork) {
|
||||
MusicUtil.deleteAlbumArt(AbsTagEditorActivity.this, getId());
|
||||
ImageLoader.getInstance().clearMemoryCache();
|
||||
} else if (artwork != null) {
|
||||
ImageLoader.getInstance().clearMemoryCache();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (deleteArtwork) {
|
||||
MusicUtil.deleteAlbumArt(AbsTagEditorActivity.this, getId());
|
||||
}
|
||||
rescanMediaAndQuitOnFinish();
|
||||
}
|
||||
}).start();
|
||||
|
|
|
|||
|
|
@ -14,16 +14,16 @@
|
|||
android:id="@android:id/empty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/empty_text_size"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:layout_gravity="center"
|
||||
android:fontFamily="sans-serif-light"
|
||||
android:text="@string/empty"
|
||||
android:layout_gravity="center" />
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/empty_text_size" />
|
||||
|
||||
<com.kabouzeid.gramophone.views.FastScroller
|
||||
android:id="@+id/fast_scroller"
|
||||
android:layout_gravity="end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end" />
|
||||
|
||||
</FrameLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue