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 {
|
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;
|
private static final int DEFAULT_ERROR_IMAGE = R.drawable.default_artist_image;
|
||||||
public static final int DEFAULT_ANIMATION = android.R.anim.fade_in;
|
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());
|
return ArtistSignatureUtil.getInstance(App.getInstance()).getArtistSignature(artist.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,12 @@ public class ArtistImage {
|
||||||
this.artistName = artistName;
|
this.artistName = artistName;
|
||||||
this.albumCovers = albumCovers;
|
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.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.media.MediaMetadataRetriever;
|
import android.media.MediaMetadataRetriever;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
@ -18,6 +19,7 @@ import com.bumptech.glide.Priority;
|
||||||
import com.bumptech.glide.load.data.DataFetcher;
|
import com.bumptech.glide.load.data.DataFetcher;
|
||||||
import com.kabouzeid.gramophone.glide.audiocover.AudioFileCoverUtils;
|
import com.kabouzeid.gramophone.glide.audiocover.AudioFileCoverUtils;
|
||||||
import com.kabouzeid.gramophone.util.ImageUtil;
|
import com.kabouzeid.gramophone.util.ImageUtil;
|
||||||
|
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
|
|
@ -28,20 +30,25 @@ public class ArtistImageFetcher implements DataFetcher<InputStream> {
|
||||||
|
|
||||||
private InputStream stream;
|
private InputStream stream;
|
||||||
|
|
||||||
public ArtistImageFetcher(final ArtistImage model) {
|
private boolean ignoreMediaStore;
|
||||||
|
|
||||||
|
public ArtistImageFetcher(final ArtistImage model, boolean ignoreMediaStore) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
this.ignoreMediaStore = ignoreMediaStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
// makes sure we never ever return null here
|
Log.d("MOSAIC", "get id for" + model.artistName);
|
||||||
return String.valueOf(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
|
@Override
|
||||||
public InputStream loadData(Priority priority) throws Exception {
|
public InputStream loadData(Priority priority) throws Exception {
|
||||||
|
Log.d("MOSAIC", "load data for" + model.artistName);
|
||||||
return stream = getMosaic(model.albumCovers);
|
return stream = getMosaic(model.albumCovers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,9 +65,11 @@ public class ArtistImageFetcher implements DataFetcher<InputStream> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (final AlbumCover cover : albumCovers) {
|
for (final AlbumCover cover : albumCovers) {
|
||||||
|
byte[] picture = null;
|
||||||
|
if (!ignoreMediaStore) {
|
||||||
retriever.setDataSource(cover.getFilePath());
|
retriever.setDataSource(cover.getFilePath());
|
||||||
byte[] picture = retriever.getEmbeddedPicture();
|
picture = retriever.getEmbeddedPicture();
|
||||||
|
}
|
||||||
final InputStream stream;
|
final InputStream stream;
|
||||||
if (picture != null) {
|
if (picture != null) {
|
||||||
stream = new ByteArrayInputStream(picture);
|
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.ModelLoader;
|
||||||
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
import com.bumptech.glide.load.model.ModelLoaderFactory;
|
||||||
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
||||||
|
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ArtistImageLoader implements StreamModelLoader<ArtistImage> {
|
public class ArtistImageLoader implements StreamModelLoader<ArtistImage> {
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public ArtistImageLoader(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataFetcher<InputStream> getResourceFetcher(final ArtistImage model, int width, int height) {
|
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> {
|
public static class Factory implements ModelLoaderFactory<ArtistImage, InputStream> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelLoader<ArtistImage, InputStream> build(Context context, GenericLoaderFactory factories) {
|
public ModelLoader<ArtistImage, InputStream> build(Context context, GenericLoaderFactory factories) {
|
||||||
|
return new ArtistImageLoader(context);
|
||||||
return new ArtistImageLoader();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue