diff options
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r-- | src/github/daneren2005/dsub/service/CachedMusicService.java | 21 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/FileUtil.java | 8 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 17c9e722..a13772a9 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -157,13 +157,32 @@ 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) { + File file = FileUtil.getEntryFile(context, entry); + Util.recursiveDelete(file, store); + } + } } return dir; diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java index ed8468b9..54888b59 100644 --- a/src/github/daneren2005/dsub/util/FileUtil.java +++ b/src/github/daneren2005/dsub/util/FileUtil.java @@ -105,6 +105,14 @@ public class FileUtil { return null; } + + public static File getEntryFile(Context context, MusicDirectory.Entry entry) { + if(entry.isDirectory()) { + return getAlbumDirectory(context, entry); + } else { + return getSongFile(context, entry); + } + } public static File getSongFile(Context context, MusicDirectory.Entry song) { File dir = getAlbumDirectory(context, song); |