aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-10-08 16:14:50 -0700
committerScott Jackson <daneren2005@gmail.com>2014-10-08 16:14:50 -0700
commit95055d8b0b07d74cda72d2773c805ccef59a3a7a (patch)
tree1076610d8b89e83c47e913601e42fed5319776b4
parentb27d4036927e14943054dfac305f6db3046bfa0d (diff)
downloaddsub-95055d8b0b07d74cda72d2773c805ccef59a3a7a.tar.gz
dsub-95055d8b0b07d74cda72d2773c805ccef59a3a7a.tar.bz2
dsub-95055d8b0b07d74cda72d2773c805ccef59a3a7a.zip
#186 Start of logic to delete cached files when removed from server
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index 17c9e722..aa96dc22 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -157,13 +157,31 @@ public class CachedMusicService implements MusicService {
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 = FileUtil.deserialize(context, getCacheName(context, "directory", id), MusicDirectory.class);
+ dir = cached;
}
if(dir == null) {
dir = musicService.getMusicDirectory(id, name, refresh, context, progressListener);
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) {
+ Util.recursiveDelete(entry, store);
+ }
+ }
}
return dir;