diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-08-28 15:30:51 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-08-28 15:30:51 -0700 |
commit | 40093c5fec1ca53208e5b6834f22bae5d04290bc (patch) | |
tree | cfa877946e575bd63d0e023c1ea42541a85d45be /src/github | |
parent | c8d6607ecc3a7e2dcdd4c5356325b91b54a4b2ed (diff) | |
download | dsub-40093c5fec1ca53208e5b6834f22bae5d04290bc.tar.gz dsub-40093c5fec1ca53208e5b6834f22bae5d04290bc.tar.bz2 dsub-40093c5fec1ca53208e5b6834f22bae5d04290bc.zip |
#251 Update PlaylistSyncAdapter to keep playlists more up to date
Diffstat (limited to 'src/github')
-rw-r--r-- | src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java index bd6d056b..71d9dfdd 100644 --- a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java @@ -43,6 +43,8 @@ import github.daneren2005.dsub.util.Util; public class PlaylistSyncAdapter extends SubsonicSyncAdapter {
private static String TAG = PlaylistSyncAdapter.class.getSimpleName();
+ // Update playlists at least once a week
+ private static int MAX_PLAYLIST_AGE = 24 * 7;
public PlaylistSyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);
@@ -56,9 +58,10 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter { public void onExecuteSync(Context context, int instance) {
String serverName = Util.getServerName(context, instance);
+ List<Playlist> remainder;
try {
// Just update playlist listings so user doesn't have to
- musicService.getPlaylists(true, context, null);
+ remainder = musicService.getPlaylists(true, context, null);
} catch(Exception e) {
Log.e(TAG, "Failed to refresh playlist list for " + serverName);
}
@@ -69,6 +72,9 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter { for(int i = 0; i < playlistList.size(); i++) {
SyncSet cachedPlaylist = playlistList.get(i);
String id = cachedPlaylist.id;
+
+ // Remove playlist from remainder list
+ remainder.remove(id);
try {
MusicDirectory playlist = musicService.getPlaylist(true, id, serverName, context, null);
@@ -121,6 +127,15 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter { SyncUtil.setSyncedPlaylists(context, instance, playlistList);
}
}
+
+ // For remaining playlists, check to make sure they have been updated recently
+ for(Playlist playlist: remainder) {
+ String cacheName = "playlist" + (Util.getRestUrl(context, null, instance, false) + playlist.getId()).hashCode() + ".ser";
+ MusicDirectory dir = FileUtil.deserialize(context, cacheName, MusicDirectory.class, MAX_PLAYLIST_AGE);
+ if(dir == null) {
+ musicService.getPlaylist(true, playlist.getId(), serverName, context, null);
+ }
+ }
if(updated.size() > 0) {
Notifications.showSyncNotification(context, R.string.sync_new_playlists, SyncUtil.joinNames(updated));
|