aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-09-24 15:36:12 -0700
committerdaneren2005 <daneren2005@gmail.com>2013-09-24 15:36:12 -0700
commit16b85acf0d3878ed25dedcc2536b9ed339d6be60 (patch)
tree01332213e2e0eaaf65285eaba94a3bbe74ff1c25 /src
parent1a42162b42fae5d7d2a793aee0c1bbae13c7913c (diff)
downloaddsub-16b85acf0d3878ed25dedcc2536b9ed339d6be60.tar.gz
dsub-16b85acf0d3878ed25dedcc2536b9ed339d6be60.tar.bz2
dsub-16b85acf0d3878ed25dedcc2536b9ed339d6be60.zip
#159: Serialize genres, podcasts, playlist lists
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index 75552ada..8c888d81 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -123,17 +123,15 @@ public class CachedMusicService implements MusicService {
if (dir == null) {
if(!refresh) {
dir = FileUtil.deserialize(context, getCacheName(context, "directory", id), MusicDirectory.class);
-
- if(dir != null) {
- return dir;
- }
}
- dir = musicService.getMusicDirectory(id, name, refresh, context, progressListener);
+ if(dir == null) {
+ dir = musicService.getMusicDirectory(id, name, refresh, context, progressListener);
+ FileUtil.serialize(context, dir, getCacheName(context, "directory", id));
+ }
cache = new TimeLimitedCache<MusicDirectory>(TTL_MUSIC_DIR, TimeUnit.SECONDS);
cache.set(dir);
cachedMusicDirectories.put(id, cache);
- FileUtil.serialize(context, dir, getCacheName(context, "directory", id));
}
return dir;
}
@@ -153,7 +151,14 @@ public class CachedMusicService implements MusicService {
checkSettingsChanged(context);
List<Playlist> result = refresh ? null : cachedPlaylists.get();
if (result == null) {
- result = musicService.getPlaylists(refresh, context, progressListener);
+ if(!refresh) {
+ result = FileUtil.deserialize(context, getCacheName(context, "playlist"), ArrayList.class);
+ }
+
+ if(result == null) {
+ result = musicService.getPlaylists(refresh, context, progressListener);
+ FileUtil.serialize(context, result, getCacheName(context, "playlist"));
+ }
cachedPlaylists.set(result);
}
return result;
@@ -162,11 +167,13 @@ public class CachedMusicService implements MusicService {
@Override
public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception {
cachedPlaylists.clear();
+ Util.delete(new File(context.getCacheDir(), getCacheName(context, "playlist"));
musicService.createPlaylist(id, name, entries, context, progressListener);
}
@Override
public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception {
+ Util.delete(new File(context.getCacheDir(), getCacheName(context, "playlist")));
musicService.deletePlaylist(id, context, progressListener);
}
@@ -306,7 +313,14 @@ public class CachedMusicService implements MusicService {
List<Genre> result = refresh ? null : cachedGenres.get();
if (result == null) {
- result = musicService.getGenres(refresh, context, progressListener);
+ if(!refresh) {
+ result = FileUtil.deserialize(context, getCacheName(context, "genre"), List.class);
+ }
+
+ if(result == null) {
+ result = musicService.getGenres(refresh, context, progressListener);
+ FileUtil.serialize(context, result, getCacheName(context, "genre"));
+ }
cachedGenres.set(result);
}
@@ -324,7 +338,14 @@ public class CachedMusicService implements MusicService {
List<PodcastChannel> result = refresh ? null : cachedPodcastChannels.get();
if (result == null) {
- result = musicService.getPodcastChannels(refresh, context, progressListener);
+ if(!refresh) {
+ result = FileUtil.deserialize(context, getCacheName(context, "podcast"), List.class);
+ }
+
+ if(result == null) {
+ result = musicService.getPodcastChannels(refresh, context, progressListener);
+ FileUtil.serialize(context, result, getCacheName(context, "podcast"));
+ }
cachedPodcastChannels.set(result);
}
@@ -343,11 +364,15 @@ public class CachedMusicService implements MusicService {
@Override
public void createPodcastChannel(String url, Context context, ProgressListener progressListener) throws Exception{
+ Util.delete(new File(context.getCacheDir(), getCacheName(context, "podcast")));
+ cachedPodcastChannels.clear();
musicService.createPodcastChannel(url, context, progressListener);
}
@Override
public void deletePodcastChannel(String id, Context context, ProgressListener progressListener) throws Exception{
+ Util.delete(new File(context.getCacheDir(), getCacheName(context, "podcast")));
+ cachedPodcastChannels.clear();
musicService.deletePodcastChannel(id, context, progressListener);
}
@@ -370,6 +395,10 @@ public class CachedMusicService implements MusicService {
String s = Util.getRestUrl(context, null) + id;
return name + "-" + s.hashCode() + ".ser";
}
+ private String getCacheName(Context context, String name) {
+ String s = Util.getRestUrl(context, null);
+ return name + "-" + s.hashCode() + ".ser";
+ }
private void checkSettingsChanged(Context context) {
String newUrl = Util.getRestUrl(context, null);