diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-10-11 18:39:06 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-10-11 18:39:06 -0700 |
commit | b0fcec4826bb211c9723d02730602c344163962a (patch) | |
tree | d5efdd1ef26c43e60f1bf72523c4790a89ca9b98 | |
parent | fbeff2c3a250960c53c6aff67a081feeb7b5368e (diff) | |
download | dsub-b0fcec4826bb211c9723d02730602c344163962a.tar.gz dsub-b0fcec4826bb211c9723d02730602c344163962a.tar.bz2 dsub-b0fcec4826bb211c9723d02730602c344163962a.zip |
#186 Apply same removal logic to tag browsing
-rw-r--r-- | src/github/daneren2005/dsub/service/CachedMusicService.java | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index a13772a9..8e8e120d 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -156,7 +156,6 @@ public class CachedMusicService implements MusicService { @Override public MusicDirectory getMusicDirectory(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { MusicDirectory dir = null; - MusicDirectory cached = FileUtil.deserialize(context, getCacheName(context, "directory", id), MusicDirectory.class); if(!refresh) { dir = cached; @@ -167,22 +166,7 @@ public class CachedMusicService implements MusicService { FileUtil.serialize(context, dir, getCacheName(context, "directory", id)); // If a cached copy exists to check against, look for removes - if(cached != null) { - List<Entry> oldList = new ArrayList<Entry>(); - oldList.addAll(cached.getChildren()); - - // Remove all current items from old list - for(Entry entry: dir.getChildren()) { - oldList.remove(entry); - } - - // Anything remaining has been removed from server - MediaStoreService store = new MediaStoreService(context); - for(Entry entry: oldList) { - File file = FileUtil.getEntryFile(context, entry); - Util.recursiveDelete(file, store); - } - } + deleteRemovedEntries(context, dir, cached); } return dir; @@ -191,14 +175,17 @@ public class CachedMusicService implements MusicService { @Override public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { MusicDirectory dir = null; - + MusicDirectory cached = FileUtil.deserialize(context, getCacheName(context, "artist", id), MusicDirectory.class); if(!refresh) { - dir = FileUtil.deserialize(context, getCacheName(context, "artist", id), MusicDirectory.class); + dir = cached; } if(dir == null) { dir = musicService.getArtist(id, name, refresh, context, progressListener); FileUtil.serialize(context, dir, getCacheName(context, "artist", id)); + + // If a cached copy exists to check against, look for removes + deleteRemovedEntries(context, dir, cached); } return dir; @@ -207,14 +194,17 @@ public class CachedMusicService implements MusicService { @Override public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { MusicDirectory dir = null; - + MusicDirectory cached = FileUtil.deserialize(context, getCacheName(context, "album", id), MusicDirectory.class); if(!refresh) { - dir = FileUtil.deserialize(context, getCacheName(context, "album", id), MusicDirectory.class); + dir = cached; } if(dir == null) { dir = musicService.getAlbum(id, name, refresh, context, progressListener); FileUtil.serialize(context, dir, getCacheName(context, "album", id)); + + // If a cached copy exists to check against, look for removes + deleteRemovedEntries(context, dir, cached); } return dir; @@ -918,6 +908,25 @@ public class CachedMusicService implements MusicService { String s = musicService.getRestUrl(context, null, false); return name + "-" + s.hashCode() + ".ser"; } + + private void deleteRemovedEntries(Context context, MusicDirectory dir, MusicDirectory cached) { + if(cached != null) { + List<Entry> oldList = new ArrayList<Entry>(); + oldList.addAll(cached.getChildren()); + + // Remove all current items from old list + for(Entry entry: dir.getChildren()) { + oldList.remove(entry); + } + + // Anything remaining has been removed from server + MediaStoreService store = new MediaStoreService(context); + for(Entry entry: oldList) { + File file = FileUtil.getEntryFile(context, entry); + Util.recursiveDelete(file, store); + } + } + } private abstract class SerializeUpdater<T> { final Context context; |