aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-12-17 17:21:25 -0800
committerScott Jackson <daneren2005@gmail.com>2015-12-17 17:21:25 -0800
commitfeb544c6bda05ea0bbfe6f53ddf14188d1e30881 (patch)
tree2e01aa902d9525ef2d5e3aceb0aefb58e4de8275
parent4c7d1f25ecb6b0c1a1a5245acfad406fc4bffe8e (diff)
downloaddsub-feb544c6bda05ea0bbfe6f53ddf14188d1e30881.tar.gz
dsub-feb544c6bda05ea0bbfe6f53ddf14188d1e30881.tar.bz2
dsub-feb544c6bda05ea0bbfe6f53ddf14188d1e30881.zip
Make getArtist/getAlbum auto refresh entries as well
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java70
1 files changed, 64 insertions, 6 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
index e85e73c5..53433f5c 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
@@ -175,6 +175,7 @@ public class CachedMusicService implements MusicService {
refreshed = musicService.getMusicDirectory(id, name, true, context, null);
updateAllSongs(context, refreshed);
cached.updateMetadata(refreshed);
+ deleteRemovedEntries(context, refreshed, cached);
FileUtil.serialize(context, refreshed, getCacheName(context, "directory", id));
return null;
}
@@ -210,11 +211,39 @@ public class CachedMusicService implements MusicService {
}
@Override
- public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ public MusicDirectory getArtist(final String id, final String name, final boolean refresh, final Context context, final ProgressListener progressListener) throws Exception {
MusicDirectory dir = null;
- MusicDirectory cached = FileUtil.deserialize(context, getCacheName(context, "artist", id), MusicDirectory.class);
- if(!refresh) {
+ final MusicDirectory cached = FileUtil.deserialize(context, getCacheName(context, "artist", id), MusicDirectory.class);
+ if(!refresh && cached != null) {
dir = cached;
+
+ new SilentBackgroundTask<Void>(context) {
+ MusicDirectory refreshed;
+
+ @Override
+ protected Void doInBackground() throws Throwable {
+ refreshed = musicService.getArtist(id, name, refresh, context, null);
+ cached.updateMetadata(refreshed);
+ deleteRemovedEntries(context, refreshed, cached);
+ FileUtil.serialize(context, refreshed, getCacheName(context, "artist", id));
+ return null;
+ }
+
+ // Update which entries exist
+ @Override
+ public void done(Void result) {
+ if(progressListener != null) {
+ if(cached.updateEntriesList(context, musicService.getInstance(context), refreshed)) {
+ progressListener.updateCache();
+ }
+ }
+ }
+
+ @Override
+ public void error(Throwable error) {
+ Log.e(TAG, "Failed to refresh getArtist", error);
+ }
+ }.execute();
}
if(dir == null) {
@@ -230,11 +259,40 @@ public class CachedMusicService implements MusicService {
}
@Override
- public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ public MusicDirectory getAlbum(final String id, final String name, final boolean refresh, final Context context, final ProgressListener progressListener) throws Exception {
MusicDirectory dir = null;
- MusicDirectory cached = FileUtil.deserialize(context, getCacheName(context, "album", id), MusicDirectory.class);
- if(!refresh) {
+ final MusicDirectory cached = FileUtil.deserialize(context, getCacheName(context, "album", id), MusicDirectory.class);
+ if(!refresh && cached != null) {
dir = cached;
+
+ new SilentBackgroundTask<Void>(context) {
+ MusicDirectory refreshed;
+
+ @Override
+ protected Void doInBackground() throws Throwable {
+ refreshed = musicService.getAlbum(id, name, refresh, context, null);
+ updateAllSongs(context, refreshed);
+ cached.updateMetadata(refreshed);
+ deleteRemovedEntries(context, refreshed, cached);
+ FileUtil.serialize(context, refreshed, getCacheName(context, "album", id));
+ return null;
+ }
+
+ // Update which entries exist
+ @Override
+ public void done(Void result) {
+ if(progressListener != null) {
+ if(cached.updateEntriesList(context, musicService.getInstance(context), refreshed)) {
+ progressListener.updateCache();
+ }
+ }
+ }
+
+ @Override
+ public void error(Throwable error) {
+ Log.e(TAG, "Failed to refresh getAlbum", error);
+ }
+ }.execute();
}
if(dir == null) {