From 6577fa6071794b4dc92b05c703a02be13d427048 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 20 Dec 2013 19:01:51 -0800 Subject: Hacky way to get around albums > 3 deep not being shown as cached --- src/github/daneren2005/dsub/view/AlbumView.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/view/AlbumView.java b/src/github/daneren2005/dsub/view/AlbumView.java index 190c5c9f..b29c2ed5 100644 --- a/src/github/daneren2005/dsub/view/AlbumView.java +++ b/src/github/daneren2005/dsub/view/AlbumView.java @@ -31,6 +31,8 @@ import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.Util; import java.io.File; +import java.util.List; + /** * Used to display albums in a {@code ListView}. * @@ -72,11 +74,31 @@ public class AlbumView extends UpdateView { artistView.setText(album.getArtist()); artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE); ((ImageLoader)obj2).loadImage(coverArtView, album, false, true); - file = FileUtil.getAlbumDirectory(context, album); + file = null; } @Override protected void updateBackground() { + if(file == null) { + String s = Util.getRestUrl(context, null) + album.getId(); + String cacheName = "directory-" + s.hashCode() + ".ser"; + MusicDirectory dir = FileUtil.deserialize(context, cacheName, MusicDirectory.class); + + if(dir != null) { + List songs = dir.getChildren(false, true); + if(songs.size() > 0) { + MusicDirectory.Entry firstSong = songs.get(0); + File songFile = FileUtil.getSongFile(context, firstSong); + file = songFile.getParentFile(); + } + } + + // Backup in case cache is null or can't get dir from it + if(file == null) { + file = FileUtil.getAlbumDirectory(context, album); + } + } + exists = file.exists(); isStarred = album.isStarred(); } -- cgit v1.2.3