aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-01-04 18:50:06 -0800
committerScott Jackson <daneren2005@gmail.com>2014-01-04 18:50:06 -0800
commitec5cd33e92c2aed0026d6df7d08b1c3313a3afdf (patch)
tree2759198e2af180285b4f43511a30c39350cf92a4
parent3e77b0dd428b757f121a883ad8e33a9b559c425a (diff)
downloaddsub-ec5cd33e92c2aed0026d6df7d08b1c3313a3afdf.tar.gz
dsub-ec5cd33e92c2aed0026d6df7d08b1c3313a3afdf.tar.bz2
dsub-ec5cd33e92c2aed0026d6df7d08b1c3313a3afdf.zip
#217 Added back a separate album art cache
-rw-r--r--src/github/daneren2005/dsub/service/RESTMusicService.java18
-rw-r--r--src/github/daneren2005/dsub/util/FileUtil.java24
2 files changed, 30 insertions, 12 deletions
diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java
index 951a182d..c5438267 100644
--- a/src/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/src/github/daneren2005/dsub/service/RESTMusicService.java
@@ -654,17 +654,13 @@ public class RESTMusicService implements MusicService {
}
byte[] bytes = Util.toByteArray(in);
-
- File albumDir = FileUtil.getAlbumDirectory(context, entry);
- if (albumDir.exists()) {
- OutputStream out = null;
- try {
- out = new FileOutputStream(FileUtil.getAlbumArtFile(albumDir));
- out.write(bytes);
- } finally {
- Util.close(out);
- }
- }
+ OutputStream out = null;
+ try {
+ out = new FileOutputStream(FileUtil.getAlbumArtFile(context, entry));
+ out.write(bytes);
+ } finally {
+ Util.close(out);
+ }
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
if(size != saveSize) {
diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java
index 87ec571b..524cfe70 100644
--- a/src/github/daneren2005/dsub/util/FileUtil.java
+++ b/src/github/daneren2005/dsub/util/FileUtil.java
@@ -139,21 +139,43 @@ public class FileUtil {
public static File getAlbumArtFile(Context context, MusicDirectory.Entry entry) {
File albumDir = getAlbumDirectory(context, entry);
- return getAlbumArtFile(albumDir);
+ File artFile;
+ File albumFile = getAlbumArtFile(albumDir);
+ File hexFile = getHexAlbumArtFile(albumDir);
+ if(albumDir.exists()) {
+ if(hexFile.exists()) {
+ hexFile.renameTo(albumFile);
+ }
+ artFile = albumFile;
+ } else {
+ artFile = hexFile;
+ }
+ return artFile;
}
public static File getAlbumArtFile(File albumDir) {
return new File(albumDir, Constants.ALBUM_ART_FILE);
}
+ public static File getHexAlbumArtFile(File albumDir) {
+ return new File(getAlbumArtDirectory(), Util.md5Hex(albumDir.getPath()) + ".jpeg");
+ }
public static Bitmap getAlbumArtBitmap(Context context, MusicDirectory.Entry entry, int size) {
File albumArtFile = getAlbumArtFile(context, entry);
+ Log.d(TAG, albumArtFile.toString());
if (albumArtFile.exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(albumArtFile.getPath());
return (bitmap == null) ? null : Bitmap.createScaledBitmap(bitmap, size, size, true);
}
return null;
}
+
+ public static File getAlbumArtDirectory() {
+ File albumArtDir = new File(getSubsonicDirectory(), "artwork");
+ ensureDirectoryExistsAndIsReadWritable(albumArtDir);
+ ensureDirectoryExistsAndIsReadWritable(new File(albumArtDir, ".nomedia"));
+ return albumArtDir;
+ }
public static File getArtistDirectory(Context context, Artist artist) {
File dir = new File(getMusicDirectory(context).getPath() + "/" + fileSystemSafe(artist.getName()));