From 94aa2684ca472ef5743e1e5c6cad75819cf39fea Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 9 Dec 2013 21:40:32 -0800 Subject: #204 Fix Recently Added sync --- .../dsub/service/sync/MostRecentSyncAdapter.java | 48 ++++++++++++---------- .../dsub/service/sync/SubsonicSyncAdapter.java | 6 ++- src/github/daneren2005/dsub/util/SyncUtil.java | 4 +- 3 files changed, 32 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java index 24cb23e8..1b3780a3 100644 --- a/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java @@ -52,31 +52,35 @@ 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)); + try { + ArrayList syncedList = SyncUtil.getSyncedMostRecent(context, instance); + MusicDirectory albumList = musicService.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(musicService.getMusicDirectory(album.getId(), album.getTitle(), true, context, null), context); + syncedList.add(album.getId()); + updated = true; + } catch(Exception e) { + Log.w(TAG, "Failed to get songs for " + album.getId() + " on " + Util.getServerName(context, instance)); + } } } } - } - - if(updated) { - FileUtil.serialize(context, podcastList, SyncUtil.getMostRecentSyncFile(context, instance)); + + if(updated) { + FileUtil.serialize(context, syncedList, SyncUtil.getMostRecentSyncFile(context, instance)); + } + } catch(Exception e) { + Log.e(TAG, "Failed to get most recent list for " + Util.getServerName(context, instance)); } } } diff --git a/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java index 27ecbb2c..6eb22be0 100644 --- a/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java @@ -34,6 +34,8 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.RESTMusicService; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.Util; @@ -115,8 +117,8 @@ public class SubsonicSyncAdapter extends AbstractThreadedSyncAdapter { } - protected void downloadRecursively(MusicDirectory.Entry parent, Context context) { - for (MusicDirectory.Entry parent: album.getChildren(false, true)) { + protected void downloadRecursively(MusicDirectory parent, Context context) throws Exception { + for (MusicDirectory.Entry song: parent.getChildren(false, true)) { if (!song.isVideo()) { DownloadFile file = new DownloadFile(context, song, true); while(!file.isSaved() && !file.isFailedMax()) { diff --git a/src/github/daneren2005/dsub/util/SyncUtil.java b/src/github/daneren2005/dsub/util/SyncUtil.java index 698d4e78..4c5c0203 100644 --- a/src/github/daneren2005/dsub/util/SyncUtil.java +++ b/src/github/daneren2005/dsub/util/SyncUtil.java @@ -103,7 +103,7 @@ public final class SyncUtil { } // Starred - public static List getSyncedStarred(Context context, int instance) { + public static ArrayList getSyncedStarred(Context context, int instance) { ArrayList list = FileUtil.deserialize(context, getStarredSyncFile(context, instance), ArrayList.class); if(list == null) { list = new ArrayList(); @@ -115,7 +115,7 @@ public final class SyncUtil { } // Most Recently Added - public static List getSyncedMostRecent(Context context, int instance) { + public static ArrayList getSyncedMostRecent(Context context, int instance) { ArrayList list = FileUtil.deserialize(context, getMostRecentSyncFile(context, instance), ArrayList.class); if(list == null) { list = new ArrayList(); -- cgit v1.2.3