From 95055d8b0b07d74cda72d2773c805ccef59a3a7a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 8 Oct 2014 16:14:50 -0700 Subject: #186 Start of logic to delete cached files when removed from server --- .../daneren2005/dsub/service/CachedMusicService.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 oldList = new ArrayList(); + 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; -- cgit v1.2.3