From d66a640e877612589ef55be0d563b1abd0b5852c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 31 Mar 2014 20:32:21 -0700 Subject: #318 Try to do lookup for correct albumart on multi disc albums --- src/github/daneren2005/dsub/util/FileUtil.java | 32 ++++++++++++++--------- src/github/daneren2005/dsub/util/ImageLoader.java | 7 +++++ 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java index a1983fde..3b45115b 100644 --- a/src/github/daneren2005/dsub/util/FileUtil.java +++ b/src/github/daneren2005/dsub/util/FileUtil.java @@ -235,18 +235,10 @@ public class FileUtil { File f = new File(fileSystemSafeDir(entry.getPath())); dir = new File(getMusicDirectory(context).getPath() + "/" + (entry.isDirectory() ? f.getPath() : f.getParent())); } else { - // Do a special lookup since 4.7+ doesn't match artist/album to entry.getPath - String s = Util.getRestUrl(context, null, false) + entry.getId(); - String cacheName = (Util.isTagBrowsing(context) ? "album-" : "directory-") + s.hashCode() + ".ser"; - MusicDirectory entryDir = FileUtil.deserialize(context, cacheName, MusicDirectory.class); - - if(entryDir != null) { - List songs = entryDir.getChildren(false, true); - if(songs.size() > 0) { - MusicDirectory.Entry firstSong = songs.get(0); - File songFile = FileUtil.getSongFile(context, firstSong); - dir = songFile.getParentFile(); - } + MusicDirectory.Entry firstSong = lookupChild(context, entry, false); + if(firstSong != null) { + File songFile = FileUtil.getSongFile(context, firstSong); + dir = songFile.getParentFile(); } if(dir == null) { @@ -260,6 +252,22 @@ public class FileUtil { } return dir; } + + public static MusicDirectory.Entry lookupChild(Context context, MusicDirectory.Entry entry, boolean allowDir) { + // Do a special lookup since 4.7+ doesn't match artist/album to entry.getPath + String s = Util.getRestUrl(context, null, false) + entry.getId(); + String cacheName = (Util.isTagBrowsing(context) ? "album-" : "directory-") + s.hashCode() + ".ser"; + MusicDirectory entryDir = FileUtil.deserialize(context, cacheName, MusicDirectory.class); + + if(entryDir != null) { + List songs = entryDir.getChildren(allowDir, true); + if(songs.size() > 0) { + return songs.get(0); + } + } + + return null; + } public static String getPodcastPath(Context context, PodcastEpisode episode) { return fileSystemSafe(episode.getArtist()) + "/" + fileSystemSafe(episode.getTitle()); diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java index 970e1b0e..37727891 100644 --- a/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/src/github/daneren2005/dsub/util/ImageLoader.java @@ -121,6 +121,13 @@ public class ImageLoader { createLargeUnknownImage(view.getContext()); } + if(entry != null && entry.getCoverArt() == null && entry.isDirectory()) { + // Try to lookup child cover art + MusicDirectory.Entry firstChild = FileUtil.lookupChild(context, entry, true); + if(firstChild != null) { + entry.setCoverArt(firstChild.getCoverArt()); + } + } if (entry == null || entry.getCoverArt() == null) { setUnknownImage(view, large); return; -- cgit v1.2.3