aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-12-09 21:40:32 -0800
committerScott Jackson <daneren2005@gmail.com>2013-12-09 21:40:32 -0800
commit94aa2684ca472ef5743e1e5c6cad75819cf39fea (patch)
tree81adac16945ea95c691a0d915016e78c266f6f22 /src
parentad66a9397d5d1541fd47b4122daf955538d93c63 (diff)
downloaddsub-94aa2684ca472ef5743e1e5c6cad75819cf39fea.tar.gz
dsub-94aa2684ca472ef5743e1e5c6cad75819cf39fea.tar.bz2
dsub-94aa2684ca472ef5743e1e5c6cad75819cf39fea.zip
#204 Fix Recently Added sync
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java48
-rw-r--r--src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java6
-rw-r--r--src/github/daneren2005/dsub/util/SyncUtil.java4
3 files changed, 32 insertions, 26 deletions
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<String> 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<String> 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<String> getSyncedStarred(Context context, int instance) {
+ public static ArrayList<String> getSyncedStarred(Context context, int instance) {
ArrayList<String> list = FileUtil.deserialize(context, getStarredSyncFile(context, instance), ArrayList.class);
if(list == null) {
list = new ArrayList<String>();
@@ -115,7 +115,7 @@ public final class SyncUtil {
}
// Most Recently Added
- public static List<String> getSyncedMostRecent(Context context, int instance) {
+ public static ArrayList<String> getSyncedMostRecent(Context context, int instance) {
ArrayList<String> list = FileUtil.deserialize(context, getMostRecentSyncFile(context, instance), ArrayList.class);
if(list == null) {
list = new ArrayList<String>();