diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-11-23 22:46:15 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-11-23 22:46:15 -0800 |
commit | 13ad47fa37ea73d25dae39a890ed0149da111607 (patch) | |
tree | 7e400e521d4211e36b5cae13e32741f1d9b99790 /src/github | |
parent | b8e1a579d931e274785f865889b1e395415cb10f (diff) | |
download | dsub-13ad47fa37ea73d25dae39a890ed0149da111607.tar.gz dsub-13ad47fa37ea73d25dae39a890ed0149da111607.tar.bz2 dsub-13ad47fa37ea73d25dae39a890ed0149da111607.zip |
Added playlist sync management logic
Diffstat (limited to 'src/github')
6 files changed, 84 insertions, 8 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 01c9d938..b3bab6e3 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -106,6 +106,14 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV }
else {
inflater.inflate(R.menu.select_playlist_context, menu);
+
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
+ Playlist playlist = (Playlist) list.getItemAtPosition(info.position);
+ if(Util.isSyncedPlaylist(context, playlist.getId())) {
+ menu.removeItem(R.id.playlist_menu_sync);
+ } else {
+ menu.removeItem(R.id.playlist_menu_stop_sync);
+ }
}
}
@@ -125,8 +133,11 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV case R.id.playlist_menu_download:
downloadPlaylist(playlist.getId(), playlist.getName(), false, true, false, false, true);
break;
- case R.id.playlist_menu_pin:
- downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true);
+ case R.id.playlist_menu_sync:
+ syncPlaylist(playlist);
+ break;
+ case R.id.playlist_menu_stop_sync:
+ stopSyncPlaylist(playlist);
break;
case R.id.playlist_menu_play_now:
fragment = new SelectDirectoryFragment();
@@ -217,6 +228,7 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
musicService.deletePlaylist(playlist.getId(), context, null);
+ Util.removeSyncedPlaylist(context, playlist.getId());
return null;
}
@@ -306,4 +318,13 @@ public class SelectPlaylistFragment extends SubsonicFragment implements AdapterV .setNegativeButton(R.string.common_cancel, null)
.show();
}
+
+ private void syncPlaylist(Playlist playlist) {
+ Util.addSyncedPlaylist(context, playlist.getId());
+ downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true);
+ }
+
+ private void stopSyncPlaylist(Playlist playlist) {
+ Util.removeSyncedPlaylist(context, playlist.getId());
+ }
}
diff --git a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java index 54c21f75..680f8e3e 100644 --- a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java @@ -49,10 +49,9 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter { @Override
public void onExecuteSync(Context context, int instance) {
String serverName = Util.getServerName(context, instance);
- String playlistListFile = "sync-playlist-" + (Util.getRestUrl(context, null, instance)).hashCode() + ".ser";
- List<Integer> playlistList = FileUtil.deserialize(context, playlistListFile, ArrayList.class);
+ List<String> playlistList = Util.getSyncedPlaylists(context, instance);
for(int i = 0; i < playlistList.size(); i++) {
- String id = Integer.toString(playlistList.get(i));
+ String id = playlistList.get(i);
try {
MusicDirectory playlist = musicService.getPlaylist(true, id, serverName, context, null);
diff --git a/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java index 106049bb..240231ab 100644 --- a/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java @@ -49,6 +49,7 @@ public class SubsonicSyncAdapter extends AbstractThreadedSyncAdapter { public SubsonicSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); + this.context = context; } @TargetApi(14) public SubsonicSyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) { diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index 9b1b01f0..28b350be 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -80,6 +80,8 @@ import java.lang.reflect.Method; import java.security.MessageDigest; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -104,7 +106,8 @@ public final class Util { public static final String AVRCP_PLAYSTATE_CHANGED = "com.android.music.playstatechanged"; public static final String AVRCP_METADATA_CHANGED = "com.android.music.metachanged"; - + + private static List<String> syncedPlaylists; private static boolean hasFocus = false; private static boolean pauseFocus = false; private static boolean lowerFocus = false; @@ -429,6 +432,51 @@ public final class Util { return name; } + public static boolean isSyncedPlaylist(Context context, String playlistId) { + if(syncedPlaylists == null) { + syncedPlaylists = getSyncedPlaylists(context); + } + return syncedPlaylists.contains(playlistId); + } + public static ArrayList<String> getSyncedPlaylists(Context context) { + return getSyncedPlaylists(context, Util.getActiveServer(context)); + } + public static ArrayList<String> getSyncedPlaylists(Context context, int instance) { + ArrayList<String> playlists = FileUtil.deserialize(context, getPlaylistSyncFile(context, instance), ArrayList.class); + if(playlists == null) { + playlists = new ArrayList<String>(); + } + return playlists; + } + public static void addSyncedPlaylist(Context context, String playlistId) { + String playlistFile = getPlaylistSyncFile(context); + ArrayList<String> playlists = getSyncedPlaylists(context); + if(!playlists.contains(playlistId)) { + playlists.add(playlistId); + } + for(String str: playlists) { + Log.d(TAG, str); + } + FileUtil.serialize(context, playlists, playlistFile); + syncedPlaylists = playlists; + } + public static void removeSyncedPlaylist(Context context, String playlistId) { + String playlistFile = getPlaylistSyncFile(context); + ArrayList<String> playlists = getSyncedPlaylists(context); + if(playlists.contains(playlistId)) { + playlists.remove(playlistId); + FileUtil.serialize(context, playlists, playlistFile); + syncedPlaylists = playlists; + } + } + private static String getPlaylistSyncFile(Context context) { + int instance = Util.getActiveServer(context); + return getPlaylistSyncFile(context, instance); + } + private static String getPlaylistSyncFile(Context context, int instance) { + return "sync-playlist-" + (Util.getRestUrl(context, null, instance)).hashCode() + ".ser"; + } + public static String getContentType(HttpEntity entity) { if (entity == null || entity.getContentType() == null) { return null; diff --git a/src/github/daneren2005/dsub/view/PlaylistView.java b/src/github/daneren2005/dsub/view/PlaylistView.java index c75f8ad7..7a0c1f34 100644 --- a/src/github/daneren2005/dsub/view/PlaylistView.java +++ b/src/github/daneren2005/dsub/view/PlaylistView.java @@ -19,6 +19,7 @@ package github.daneren2005.dsub.view;
import android.content.Context;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
@@ -63,4 +64,9 @@ public class PlaylistView extends UpdateView { this.playlist = (Playlist) obj;
titleView.setText(playlist.getName());
}
+
+ @Override
+ protected void updateBackground() {
+ pinned = Util.isSyncedPlaylist(context, playlist.getId());
+ }
}
diff --git a/src/github/daneren2005/dsub/view/UpdateView.java b/src/github/daneren2005/dsub/view/UpdateView.java index 05b17417..f247137d 100644 --- a/src/github/daneren2005/dsub/view/UpdateView.java +++ b/src/github/daneren2005/dsub/view/UpdateView.java @@ -48,6 +48,7 @@ public class UpdateView extends LinearLayout { protected ImageView moreButton;
protected boolean exists = false;
+ protected boolean pinned = false;
protected boolean shaded = false;
protected boolean starred = false;
protected boolean isStarred = false;
@@ -169,9 +170,9 @@ public class UpdateView extends LinearLayout { }
protected void update() {
if(moreButton != null) {
- if(exists) {
+ if(exists || pinned) {
if(!shaded) {
- moreButton.setImageResource(R.drawable.download_cached);
+ moreButton.setImageResource(exists ? R.drawable.download_cached : R.drawable.download_pinned);
shaded = true;
}
} else {
|