Fix cache for artist mosaics
This commit is contained in:
parent
dec0832b6e
commit
7b9230f35d
4 changed files with 34 additions and 12 deletions
|
|
@ -33,7 +33,7 @@ import com.kabouzeid.gramophone.util.CustomArtistImageUtil;
|
|||
*/
|
||||
public class ArtistGlideRequest {
|
||||
|
||||
private static final DiskCacheStrategy DEFAULT_DISK_CACHE_STRATEGY = DiskCacheStrategy.SOURCE;
|
||||
private static final DiskCacheStrategy DEFAULT_DISK_CACHE_STRATEGY = DiskCacheStrategy.ALL;
|
||||
private static final int DEFAULT_ERROR_IMAGE = R.drawable.default_artist_image;
|
||||
public static final int DEFAULT_ANIMATION = android.R.anim.fade_in;
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ public class ArtistGlideRequest {
|
|||
}
|
||||
}
|
||||
|
||||
public static Key createSignature(Artist artist) {
|
||||
private static Key createSignature(Artist artist) {
|
||||
return ArtistSignatureUtil.getInstance(App.getInstance()).getArtistSignature(artist.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,12 @@ public class ArtistImage {
|
|||
this.artistName = artistName;
|
||||
this.albumCovers = albumCovers;
|
||||
}
|
||||
|
||||
public String toIdString() {
|
||||
StringBuilder id = new StringBuilder(artistName);
|
||||
for (AlbumCover albumCover: albumCovers) {
|
||||
id.append(albumCover.getYear()).append(albumCover.getFilePath());
|
||||
}
|
||||
return id.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.glide.artistimage;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
@ -18,6 +19,7 @@ import com.bumptech.glide.Priority;
|
|||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.kabouzeid.gramophone.glide.audiocover.AudioFileCoverUtils;
|
||||
import com.kabouzeid.gramophone.util.ImageUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
|
|
@ -28,20 +30,25 @@ public class ArtistImageFetcher implements DataFetcher<InputStream> {
|
|||
|
||||
private InputStream stream;
|
||||
|
||||
public ArtistImageFetcher(final ArtistImage model) {
|
||||
private boolean ignoreMediaStore;
|
||||
|
||||
public ArtistImageFetcher(final ArtistImage model, boolean ignoreMediaStore) {
|
||||
this.model = model;
|
||||
this.ignoreMediaStore = ignoreMediaStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
// makes sure we never ever return null here
|
||||
return String.valueOf(model.artistName);
|
||||
Log.d("MOSAIC", "get id for" + model.artistName);
|
||||
// never return NULL here!
|
||||
// this id is used to determine whether the image is already cached
|
||||
// we use the artist name as well as the album years + file paths
|
||||
return model.toIdString() + "ignoremediastore:" + ignoreMediaStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream loadData(Priority priority) throws Exception {
|
||||
|
||||
Log.d("MOSAIC", "load data for" + model.artistName);
|
||||
return stream = getMosaic(model.albumCovers);
|
||||
}
|
||||
|
||||
|
|
@ -58,9 +65,11 @@ public class ArtistImageFetcher implements DataFetcher<InputStream> {
|
|||
|
||||
try {
|
||||
for (final AlbumCover cover : albumCovers) {
|
||||
|
||||
retriever.setDataSource(cover.getFilePath());
|
||||
byte[] picture = retriever.getEmbeddedPicture();
|
||||
byte[] picture = null;
|
||||
if (!ignoreMediaStore) {
|
||||
retriever.setDataSource(cover.getFilePath());
|
||||
picture = retriever.getEmbeddedPicture();
|
||||
}
|
||||
final InputStream stream;
|
||||
if (picture != null) {
|
||||
stream = new ByteArrayInputStream(picture);
|
||||
|
|
|
|||
|
|
@ -9,25 +9,30 @@ 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.util.PreferenceUtil;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
||||
public class ArtistImageLoader implements StreamModelLoader<ArtistImage> {
|
||||
private Context context;
|
||||
|
||||
public ArtistImageLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(final ArtistImage model, int width, int height) {
|
||||
|
||||
return new ArtistImageFetcher(model);
|
||||
return new ArtistImageFetcher(model, PreferenceUtil.getInstance(context).ignoreMediaStoreArtwork());
|
||||
}
|
||||
|
||||
public static class Factory implements ModelLoaderFactory<ArtistImage, InputStream> {
|
||||
|
||||
@Override
|
||||
public ModelLoader<ArtistImage, InputStream> build(Context context, GenericLoaderFactory factories) {
|
||||
|
||||
return new ArtistImageLoader();
|
||||
return new ArtistImageLoader(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue