Added option to only download artist images on wifi
This commit is contained in:
parent
2e5b17be38
commit
585fd1013c
9 changed files with 78 additions and 10 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package com.kabouzeid.gramophone.glide.artistimage;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.data.HttpUrlFetcher;
|
||||
|
|
@ -8,6 +10,7 @@ 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 com.kabouzeid.gramophone.util.Util;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
|
@ -15,12 +18,14 @@ import java.io.InputStream;
|
|||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistImageFetcher implements DataFetcher<InputStream> {
|
||||
private Context context;
|
||||
private final LastFMRestClient lastFMRestClient;
|
||||
private final ArtistImageRequest model;
|
||||
private HttpUrlFetcher urlFetcher;
|
||||
private volatile boolean isCancelled;
|
||||
|
||||
public ArtistImageFetcher(LastFMRestClient lastFMRestClient, ArtistImageRequest model) {
|
||||
public ArtistImageFetcher(Context context, LastFMRestClient lastFMRestClient, ArtistImageRequest model) {
|
||||
this.context = context;
|
||||
this.lastFMRestClient = lastFMRestClient;
|
||||
this.model = model;
|
||||
}
|
||||
|
|
@ -32,14 +37,15 @@ public class ArtistImageFetcher implements DataFetcher<InputStream> {
|
|||
|
||||
@Override
|
||||
public InputStream loadData(Priority priority) throws Exception {
|
||||
if (MusicUtil.isArtistNameUnknown(model.artistName)) return null;
|
||||
if (!MusicUtil.isArtistNameUnknown(model.artistName) && Util.isAllowedToAutoDownload(context)) {
|
||||
LastFmArtist lastFmArtist = lastFMRestClient.getApiService().getArtistInfo(model.artistName, model.skipOkHttpCache ? "no-cache" : null).execute().body();
|
||||
|
||||
LastFmArtist lastFmArtist = lastFMRestClient.getApiService().getArtistInfo(model.artistName, model.skipOkHttpCache ? "no-cache" : null).execute().body();
|
||||
if (isCancelled) return null;
|
||||
|
||||
if (isCancelled) return null;
|
||||
|
||||
urlFetcher = new HttpUrlFetcher(new GlideUrl(LastFMUtil.getLargestArtistImageUrl(lastFmArtist.getArtist().getImage())));
|
||||
return urlFetcher.loadData(priority);
|
||||
urlFetcher = new HttpUrlFetcher(new GlideUrl(LastFMUtil.getLargestArtistImageUrl(lastFmArtist.getArtist().getImage())));
|
||||
return urlFetcher.loadData(priority);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,15 +16,17 @@ import java.io.InputStream;
|
|||
*/
|
||||
|
||||
public class ArtistImageLoader implements StreamModelLoader<ArtistImageRequest> {
|
||||
private Context context;
|
||||
private LastFMRestClient lastFMRestClient;
|
||||
|
||||
public ArtistImageLoader(LastFMRestClient lastFMRestClient) {
|
||||
public ArtistImageLoader(Context context, LastFMRestClient lastFMRestClient) {
|
||||
this.context = context;
|
||||
this.lastFMRestClient = lastFMRestClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(ArtistImageRequest model, int width, int height) {
|
||||
return new ArtistImageFetcher(lastFMRestClient, model);
|
||||
return new ArtistImageFetcher(context, lastFMRestClient, model);
|
||||
}
|
||||
|
||||
public static class Factory implements ModelLoaderFactory<ArtistImageRequest, InputStream> {
|
||||
|
|
@ -51,7 +53,7 @@ public class ArtistImageLoader implements StreamModelLoader<ArtistImageRequest>
|
|||
|
||||
@Override
|
||||
public ModelLoader<ArtistImageRequest, InputStream> build(Context context, GenericLoaderFactory factories) {
|
||||
return new ArtistImageLoader(client);
|
||||
return new ArtistImageLoader(context, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue