aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-08-28 15:30:51 -0700
committerScott Jackson <daneren2005@gmail.com>2014-08-28 15:30:51 -0700
commit40093c5fec1ca53208e5b6834f22bae5d04290bc (patch)
treecfa877946e575bd63d0e023c1ea42541a85d45be
parentc8d6607ecc3a7e2dcdd4c5356325b91b54a4b2ed (diff)
downloaddsub-40093c5fec1ca53208e5b6834f22bae5d04290bc.tar.gz
dsub-40093c5fec1ca53208e5b6834f22bae5d04290bc.tar.bz2
dsub-40093c5fec1ca53208e5b6834f22bae5d04290bc.zip
#251 Update PlaylistSyncAdapter to keep playlists more up to date
-rw-r--r--src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java17
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));