aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-03-04 17:33:25 -0800
committerScott Jackson <daneren2005@gmail.com>2016-03-04 17:33:25 -0800
commitaaa3e53d101c966680b2bb19c093cc69c052e793 (patch)
treeca1da8555ffa4eb475c01486ec8e7a58ccc05992
parent8013695207037c65da54daf150bd8a76a3406e14 (diff)
downloaddsub-aaa3e53d101c966680b2bb19c093cc69c052e793.tar.gz
dsub-aaa3e53d101c966680b2bb19c093cc69c052e793.tar.bz2
dsub-aaa3e53d101c966680b2bb19c093cc69c052e793.zip
Fix error handling in artist image loader
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java71
1 files changed, 38 insertions, 33 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
index 85844360..a85141df 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
@@ -524,44 +524,49 @@ public class ImageLoader {
@Override
protected Void doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(mContext);
- ArtistInfo artistInfo = musicService.getArtistInfo(mEntry.getId(), false, true, mContext, null);
- String url = artistInfo.getImageUrl();
-
- // Figure out whether we are going to get a artist image or the standard image
- if(url != null && !"".equals(url.trim())) {
- // 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() {
- // Call loadImage so we can take advantage of all of it's logic checks
- loadImage(mView, mEntry, mSize == imageSizeLarge, mCrossfade);
-
- // Delete subTask so it doesn't get called in done
- subTask = null;
+ try {
+ MusicService musicService = MusicServiceFactory.getMusicService(mContext);
+ ArtistInfo artistInfo = musicService.getArtistInfo(mEntry.getId(), false, true, mContext, null);
+ String url = artistInfo.getImageUrl();
+
+ // Figure out whether we are going to get a artist image or the standard image
+ if (url != null && !"".equals(url.trim())) {
+ // 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() {
+ // Call loadImage so we can take advantage of all of it's logic checks
+ loadImage(mView, mEntry, mSize == imageSizeLarge, mCrossfade);
+
+ // Delete subTask so it doesn't get called in done
+ subTask = null;
+ }
+ };
+ } else {
+ if (mEntry != null && mEntry.getCoverArt() == null && mEntry.isDirectory() && !Util.isOffline(context)) {
+ // Try to lookup child cover art
+ MusicDirectory.Entry firstChild = FileUtil.lookupChild(context, mEntry, true);
+ if (firstChild != null) {
+ mEntry.setCoverArt(firstChild.getCoverArt());
+ }
}
- };
- } else {
- if (mEntry != null && mEntry.getCoverArt() == null && mEntry.isDirectory() && !Util.isOffline(context)) {
- // Try to lookup child cover art
- MusicDirectory.Entry firstChild = FileUtil.lookupChild(context, mEntry, true);
- if (firstChild != null) {
- mEntry.setCoverArt(firstChild.getCoverArt());
+
+ if (mEntry != null && mEntry.getCoverArt() != null) {
+ subTask = new ViewImageTask(mContext, mEntry, mSize, mSaveSize, mIsNowPlaying, mView, mCrossfade);
+ } else {
+ // If entry is null as well, we need to just set as a blank image
+ Bitmap bitmap = getUnknownImage(mEntry, mSize);
+ mDrawable = Util.createDrawableFromBitmap(mContext, bitmap);
+ return null;
}
}
- if (mEntry != null && mEntry.getCoverArt() != null) {
- subTask = new ViewImageTask(mContext, mEntry, mSize, mSaveSize, mIsNowPlaying, mView, mCrossfade);
- } else {
- // If entry is null as well, we need to just set as a blank image
- Bitmap bitmap = getUnknownImage(mEntry, mSize);
- mDrawable = Util.createDrawableFromBitmap(mContext, bitmap);
- return null;
- }
+ // Execute whichever way we decided to go
+ subTask.doInBackground();
+ } catch (Throwable x) {
+ Log.e(TAG, "Failed to get artist info", x);
+ cancelled.set(true);
}
-
- // Execute whichever way we decided to go
- subTask.doInBackground();
return null;
}