diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-01-17 16:00:55 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-01-17 16:00:55 -0800 |
commit | dd7b96daca111c45610895a78bbed1a53b5f531c (patch) | |
tree | 91839dfab1937d7101416be0300e762eafae1145 /src/github/daneren2005 | |
parent | 8924cfb4e18e9e591f96fd488cb7a27676a31aa0 (diff) | |
download | dsub-dd7b96daca111c45610895a78bbed1a53b5f531c.tar.gz dsub-dd7b96daca111c45610895a78bbed1a53b5f531c.tar.bz2 dsub-dd7b96daca111c45610895a78bbed1a53b5f531c.zip |
#436 On starred images, try to load artist image instead of a sub-album
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r-- | src/github/daneren2005/dsub/util/ImageLoader.java | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java index 5adf5e34..9a790b7a 100644 --- a/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/src/github/daneren2005/dsub/util/ImageLoader.java @@ -41,7 +41,9 @@ import android.view.View; import android.widget.ImageView; import android.widget.TextView; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.ArtistInfo; import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.ServerInfo; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; @@ -181,8 +183,14 @@ public class ImageLoader { return bitmap; } - public ImageTask loadImage(View view, MusicDirectory.Entry entry, boolean large, boolean crossfade) { - if(entry != null && entry.getCoverArt() == null && entry.isDirectory() && !Util.isOffline(context)) { + public SilentBackgroundTask loadImage(View view, MusicDirectory.Entry entry, boolean large, boolean crossfade) { + // TODO: If we know this a artist, try to load artist info instead + int size = large ? imageSizeLarge : imageSizeDefault; + if(entry != null && !entry.isAlbum() && ServerInfo.checkServerVersion(context, "1.11") && !Util.isOffline(context)) { + SilentBackgroundTask task = new ArtistImageTask(view.getContext(), entry, size, imageSizeLarge, large, view, crossfade); + task.execute(); + return task; + } else if(entry != null && entry.getCoverArt() == null && entry.isDirectory() && !Util.isOffline(context)) { // Try to lookup child cover art MusicDirectory.Entry firstChild = FileUtil.lookupChild(context, entry, true); if(firstChild != null) { @@ -191,7 +199,6 @@ public class ImageLoader { } Bitmap bitmap; - int size = large ? imageSizeLarge : imageSizeDefault; if (entry == null || entry.getCoverArt() == null) { bitmap = getUnknownImage(entry, size); setImage(view, Util.createDrawableFromBitmap(context, bitmap), crossfade); @@ -411,6 +418,61 @@ public class ImageLoader { } } + private class ArtistImageTask extends SilentBackgroundTask<Void> { + private final Context mContext; + private final MusicDirectory.Entry mEntry; + private final int mSize; + private final int mSaveSize; + private final boolean mIsNowPlaying; + private Drawable mDrawable; + private boolean mCrossfade; + private View mView; + + private SilentBackgroundTask subTask; + + public ArtistImageTask(Context context, MusicDirectory.Entry entry, int size, int saveSize, boolean isNowPlaying, View view, boolean crossfade) { + super(context); + mContext = context; + mEntry = entry; + mSize = size; + mSaveSize = saveSize; + mIsNowPlaying = isNowPlaying; + mView = view; + mCrossfade = crossfade; + } + + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(mContext); + ArtistInfo artistInfo = musicService.getArtistInfo(mEntry.getId(), false, mContext, null); + String url = artistInfo.getImageUrl(); + + // Figure out whether we are going to get a artist image or the standard image + if(url != null) { + // If getting the artist image fails for any reason, retry for the standard version + subTask = new ViewUrlTask(mContext, mView, url, mSize) { + @Override + protected void failedToDownload() { + new ViewImageTask(mContext, mEntry, mSize, mSaveSize, mIsNowPlaying, mView, mCrossfade).execute(); + } + }; + } else { + subTask = new ViewImageTask(mContext, mEntry, mSize, mSaveSize, mIsNowPlaying, mView, mCrossfade); + } + + // Execute whichever way we decided to go + subTask.doInBackground(); + return null; + } + + @Override + public void done(Void result) { + if(subTask != null) { + subTask.done(result); + } + } + } + private class ViewUrlTask extends SilentBackgroundTask<Void> { private final Context mContext; private final String mUrl; @@ -451,8 +513,14 @@ public class ImageLoader { protected void done(Void result) { if(mDrawable != null) { mView.setImageDrawable(mDrawable); + } else { + failedToDownload(); } } + + protected void failedToDownload() { + + } } private class AvatarTask extends SilentBackgroundTask<Void> { |