aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-10-11 18:39:06 -0700
committerScott Jackson <daneren2005@gmail.com>2014-10-11 18:39:06 -0700
commitb0fcec4826bb211c9723d02730602c344163962a (patch)
treed5efdd1ef26c43e60f1bf72523c4790a89ca9b98 /src
parentfbeff2c3a250960c53c6aff67a081feeb7b5368e (diff)
downloaddsub-b0fcec4826bb211c9723d02730602c344163962a.tar.gz
dsub-b0fcec4826bb211c9723d02730602c344163962a.tar.bz2
dsub-b0fcec4826bb211c9723d02730602c344163962a.zip
#186 Apply same removal logic to tag browsing
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java51
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;