diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-07-24 13:26:14 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-07-24 13:26:14 -0700 |
commit | ee93fca7860d8d964d46ee8c61fae2880fb98fa1 (patch) | |
tree | 5c8104ecd8d9915de2876c00be4d3b46bfa859e9 | |
parent | b5cb29304cdbe2ae3ce2c903ea5ff8a408399cd9 (diff) | |
download | dsub-ee93fca7860d8d964d46ee8c61fae2880fb98fa1.tar.gz dsub-ee93fca7860d8d964d46ee8c61fae2880fb98fa1.tar.bz2 dsub-ee93fca7860d8d964d46ee8c61fae2880fb98fa1.zip |
Move indexes cache to CachedMusicService
-rw-r--r-- | src/github/daneren2005/dsub/service/RESTMusicService.java | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 295711e2..51a8a2a6 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -223,58 +223,22 @@ public class RESTMusicService implements MusicService { @Override public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - Indexes cachedIndexes = readCachedIndexes(context, musicFolderId); - if (cachedIndexes != null && !refresh) { - return cachedIndexes; - } - - long lastModified = (cachedIndexes == null || refresh) ? 0L : cachedIndexes.getLastModified(); - List<String> parameterNames = new ArrayList<String>(); List<Object> parameterValues = new ArrayList<Object>(); - if(lastModified != 0L) { - parameterNames.add("ifModifiedSince"); - parameterValues.add(lastModified); - } - - if (musicFolderId != null) { + if (musicFolderId != null) { parameterNames.add("musicFolderId"); parameterValues.add(musicFolderId); } Reader reader = getReader(context, progressListener, Util.isTagBrowsing(context, getInstance(context)) ? "getArtists" : "getIndexes", null, parameterNames, parameterValues); try { - Indexes indexes = new IndexesParser(context, getInstance(context)).parse(reader, progressListener); - if (indexes != null) { - writeCachedIndexes(context, indexes, musicFolderId); - return indexes; - } - if(cachedIndexes != null) { - return cachedIndexes; - } else { - return new Indexes(0, new ArrayList<Artist>(), new ArrayList<Artist>()); - } + return new IndexesParser(context, getInstance(context)).parse(reader, progressListener); } finally { Util.close(reader); } } - private Indexes readCachedIndexes(Context context, String musicFolderId) { - String filename = getCachedIndexesFilename(context, musicFolderId); - return FileUtil.deserialize(context, filename, Indexes.class); - } - - private void writeCachedIndexes(Context context, Indexes indexes, String musicFolderId) { - String filename = getCachedIndexesFilename(context, musicFolderId); - FileUtil.serialize(context, indexes, filename); - } - - private String getCachedIndexesFilename(Context context, String musicFolderId) { - String s = getRestUrl(context, null) + musicFolderId; - return (Util.isTagBrowsing(context, getInstance(context)) ? "artists-" : "indexes-") + Math.abs(s.hashCode()) + ".ser"; - } - @Override public MusicDirectory getMusicDirectory(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { SharedPreferences prefs = Util.getPreferences(context); |