aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/github/daneren2005/dsub/domain/Playlist.java2
-rw-r--r--src/github/daneren2005/dsub/fragments/MainFragment.java2
-rw-r--r--src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java23
-rw-r--r--src/github/daneren2005/dsub/util/Util.java15
4 files changed, 33 insertions, 9 deletions
diff --git a/src/github/daneren2005/dsub/domain/Playlist.java b/src/github/daneren2005/dsub/domain/Playlist.java
index 5bf6753a..7cd820c0 100644
--- a/src/github/daneren2005/dsub/domain/Playlist.java
+++ b/src/github/daneren2005/dsub/domain/Playlist.java
@@ -123,6 +123,6 @@ public class Playlist implements Serializable {
}
Playlist playlist = (Playlist) o;
- return o.id.equals(this.id);
+ return playlist.id.equals(this.id);
}
}
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java
index 7485da71..91902b52 100644
--- a/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -469,7 +469,7 @@ public class MainFragment extends SubsonicFragment {
new SilentBackgroundTask<Integer>(context) {
@Override
public Integer doInBackground() throws Exception {
- String recentAddedFile = "recent_count" + (Util.getRestUrl(context, null, false)).hashCode() + ".ser";
+ String recentAddedFile = Util.getCacheName(context, "recent_count");
ArrayList<String> recents = FileUtil.deserialize(context, recentAddedFile, ArrayList.class);
if(recents == null) {
recents = new ArrayList<String>();
diff --git a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
index 71d9dfdd..c0aecfa2 100644
--- a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
+++ b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
@@ -29,6 +29,7 @@ import java.util.List;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.parser.SubsonicRESTException;
import github.daneren2005.dsub.util.FileUtil;
@@ -58,7 +59,7 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter {
public void onExecuteSync(Context context, int instance) {
String serverName = Util.getServerName(context, instance);
- List<Playlist> remainder;
+ List<Playlist> remainder = null;
try {
// Just update playlist listings so user doesn't have to
remainder = musicService.getPlaylists(true, context, null);
@@ -74,7 +75,10 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter {
String id = cachedPlaylist.id;
// Remove playlist from remainder list
- remainder.remove(id);
+ if(remainder != null) {
+ remainder.remove(new Playlist(id, ""));
+ }
+
try {
MusicDirectory playlist = musicService.getPlaylist(true, id, serverName, context, null);
@@ -129,11 +133,16 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter {
}
// 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(remainder != null) {
+ for (Playlist playlist : remainder) {
+ MusicDirectory dir = FileUtil.deserialize(context, Util.getCacheName(context, instance, "playlist", playlist.getId()), MusicDirectory.class, MAX_PLAYLIST_AGE);
+ if (dir == null) {
+ try {
+ musicService.getPlaylist(true, playlist.getId(), serverName, context, null);
+ } catch(Exception e) {
+ Log.w(TAG, "Failed to update playlist for " + playlist.getName());
+ }
+ }
}
}
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index 56a66b8a..c1d026d4 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -430,6 +430,21 @@ public final class Util {
editor.putString(Constants.OFFLINE_SYNC_DEFAULT, defaultValue);
editor.commit();
}
+
+ public static String getCacheName(Context context, String name, String id) {
+ return getCacheName(context, getActiveServer(context), name, id);
+ }
+ public static String getCacheName(Context context, int instance, String name, String id) {
+ String s = getRestUrl(context, null, instance, false) + id;
+ return name + "-" + s.hashCode() + ".ser";
+ }
+ public static String getCacheName(Context context, String name) {
+ return getCacheName(context, getActiveServer(context), name);
+ }
+ public static String getCacheName(Context context, int instance, String name) {
+ String s = getRestUrl(context, null, instance, false);
+ return name + "-" + s.hashCode() + ".ser";
+ }
public static int offlineScrobblesCount(Context context) {
SharedPreferences offline = getOfflineSync(context);