From ba093211085e586380d89c9213a4a59c8de9aa81 Mon Sep 17 00:00:00 2001 From: daneren2005 Date: Mon, 9 Dec 2013 16:07:01 -0800 Subject: #204 Add Recently Added sync logic --- .../dsub/service/sync/MostRecentSyncAdapter.java | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java index 19637fcc..24cb23e8 100644 --- a/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java @@ -52,6 +52,31 @@ public class MostRecentSyncAdapter extends SubsonicSyncAdapter { @Override public void onExecuteSync(Context context, int instance) { - + List syncedList = SyncUtil.getSyncedMostRecent(context, instance); + MusicDirectory albumList = service.getAlbumList("recent", 20, 0, context, null); + boolean updated = false; + if(syncedList.size() == 0) { + // Get the initial set of albums on first run, don't sync any of these! + for(MusicDirectory.Entry album: albumList.getChildren()) { + syncedList.add(album.getId()); + } + updated = true; + } else { + for(MusicDirectory.Entry album: albumList.getChildren()) { + if(!syncedList.contains(album.getId()) { + try { + downloadRecursively(album, context); + syncedList.add(album.getId()); + updated = true; + } catch(Exception e) { + Log.w(TAG, "Failed to get songs for " + id + " on " + Util.getServerName(context, instance)); + } + } + } + } + + if(updated) { + FileUtil.serialize(context, podcastList, SyncUtil.getMostRecentSyncFile(context, instance)); + } } } -- cgit v1.2.3