From 40093c5fec1ca53208e5b6834f22bae5d04290bc Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 28 Aug 2014 15:30:51 -0700 Subject: #251 Update PlaylistSyncAdapter to keep playlists more up to date --- .../dsub/service/sync/PlaylistSyncAdapter.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 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)); -- cgit v1.2.3