diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-01-21 20:02:21 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-01-21 20:02:21 -0800 |
commit | c1cec1751a6b476cae29379be249c88d667eef6d (patch) | |
tree | ed66cb6b097a4558abea95af36963d26c73380eb /subsonic-android | |
parent | 4e04a4f0ed6298cf5fd69fd87abba5c2fa7dd6cb (diff) | |
download | dsub-c1cec1751a6b476cae29379be249c88d667eef6d.tar.gz dsub-c1cec1751a6b476cae29379be249c88d667eef6d.tar.bz2 dsub-c1cec1751a6b476cae29379be249c88d667eef6d.zip |
Always download full size cover art and cache it, then resize it if needed
Diffstat (limited to 'subsonic-android')
6 files changed, 21 insertions, 16 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index fe9b6b45..cdd9a879 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -196,8 +196,8 @@ public class CachedMusicService implements MusicService { } @Override - public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception { - return musicService.getCoverArt(context, entry, size, saveToFile, progressListener); + public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, int saveSize, ProgressListener progressListener) throws Exception { + return musicService.getCoverArt(context, entry, size, saveSize, progressListener); } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java index 0f322817..59f78252 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java @@ -330,7 +330,7 @@ public class DownloadFile { if (song.getCoverArt() != null) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); int size = Math.min(metrics.widthPixels, metrics.heightPixels); - musicService.getCoverArt(context, song, size, true, null); + musicService.getCoverArt(context, song, size, size, null); } } catch (Exception x) { Log.e(TAG, "Failed to get cover art.", x); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index 15075d02..1ccc2cdf 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -77,7 +77,7 @@ public interface MusicService { MusicDirectory getRandomSongs(int size, String folder, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception; - Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception; + Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, int saveSize, ProgressListener progressListener) throws Exception; HttpResponse getDownloadInputStream(Context context, MusicDirectory.Entry song, long offset, int maxBitrate, CancellableTask task) throws Exception; diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index 5f55df6d..fbb62e67 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -152,7 +152,7 @@ public class OfflineMusicService extends RESTMusicService { } @Override - public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception { + public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, int saveSize, ProgressListener progressListener) throws Exception { InputStream in = new FileInputStream(entry.getCoverArt()); try { byte[] bytes = Util.toByteArray(in); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index 9d77026c..ff2183ea 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -554,7 +554,7 @@ public class RESTMusicService implements MusicService { } @Override - public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception { + public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, int saveSize, ProgressListener progressListener) throws Exception { // Synchronize on the entry so that we don't download concurrently for the same song. synchronized (entry) { @@ -570,7 +570,7 @@ public class RESTMusicService implements MusicService { InputStream in = null; try { List<String> parameterNames = Arrays.asList("id", "size"); - List<Object> parameterValues = Arrays.<Object>asList(entry.getCoverArt(), size); + List<Object> parameterValues = Arrays.<Object>asList(entry.getCoverArt(), saveSize); HttpEntity entity = getEntityForURL(context, url, null, parameterNames, parameterValues, progressListener); in = entity.getContent(); @@ -584,7 +584,7 @@ public class RESTMusicService implements MusicService { byte[] bytes = Util.toByteArray(in); File albumDir = FileUtil.getAlbumDirectory(context, entry); - if (saveToFile && albumDir.exists()) { + if (albumDir.exists()) { OutputStream out = null; try { out = new FileOutputStream(FileUtil.getAlbumArtFile(albumDir)); @@ -594,7 +594,11 @@ public class RESTMusicService implements MusicService { } } - return BitmapFactory.decodeByteArray(bytes, 0, bytes.length); + bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); + if(size != saveSize) { + bitmap = Bitmap.createScaledBitmap(bitmap, size, size, true); + } + return bitmap; } finally { Util.close(in); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java index 06b837e4..9586e24d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java @@ -36,6 +36,7 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; +import java.io.File; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -115,8 +116,8 @@ public class ImageLoader implements Runnable { if (!large) { setUnknownImage(view, large); } - queue.offer(new Task(view.getContext(), entry, size, large, new ViewTaskHandler(view, crossfade))); - } + queue.offer(new Task(view.getContext(), entry, size, imageSizeLarge, new ViewTaskHandler(view, crossfade))); + } public void loadImage(Context context, RemoteControlClient remoteControl, MusicDirectory.Entry entry) { if (entry == null || entry.getCoverArt() == null) { @@ -132,7 +133,7 @@ public class ImageLoader implements Runnable { } setUnknownImage(remoteControl); - queue.offer(new Task(context, entry, imageSizeLarge, false, new RemoteControlClientTaskHandler(remoteControl))); + queue.offer(new Task(context, entry, imageSizeLarge, imageSizeLarge, new RemoteControlClientTaskHandler(remoteControl))); } private String getKey(String coverArtId, int size) { @@ -218,14 +219,14 @@ public class ImageLoader implements Runnable { private final MusicDirectory.Entry mEntry; private final Handler mHandler; private final int mSize; - private final boolean mSaveToFile; + private final int mSaveSize; private ImageLoaderTaskHandler mTaskHandler; - public Task(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ImageLoaderTaskHandler taskHandler) { + public Task(Context context, MusicDirectory.Entry entry, int size, int saveSize, ImageLoaderTaskHandler taskHandler) { mContext = context; mEntry = entry; mSize = size; - mSaveToFile = saveToFile; + mSaveSize = saveSize; mTaskHandler = taskHandler; mHandler = new Handler(); } @@ -242,7 +243,7 @@ public class ImageLoader implements Runnable { public void loadImage() { try { MusicService musicService = MusicServiceFactory.getMusicService(mContext); - Bitmap bitmap = musicService.getCoverArt(mContext, mEntry, mSize, mSaveToFile, null); + Bitmap bitmap = musicService.getCoverArt(mContext, mEntry, mSize, mSaveSize, null); cache.put(getKey(mEntry.getCoverArt(), mSize), bitmap); final Drawable drawable = Util.createDrawableFromBitmap(mContext, bitmap); |