aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/menu/select_playlist_context.xml11
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java25
-rw-r--r--src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java5
-rw-r--r--src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java1
-rw-r--r--src/github/daneren2005/dsub/util/Util.java50
-rw-r--r--src/github/daneren2005/dsub/view/PlaylistView.java6
-rw-r--r--src/github/daneren2005/dsub/view/UpdateView.java5
8 files changed, 93 insertions, 12 deletions
diff --git a/res/menu/select_playlist_context.xml b/res/menu/select_playlist_context.xml
index 0ec94e02..7cdc0c79 100644
--- a/res/menu/select_playlist_context.xml
+++ b/res/menu/select_playlist_context.xml
@@ -22,10 +22,13 @@
android:title="@string/common.download"
/>
- <item
- android:id="@+id/playlist_menu_pin"
- android:title="@string/common.pin"
- />
+ <item
+ android:id="@+id/playlist_menu_sync"
+ android:title="@string/menu.keep_synced"/>
+
+ <item
+ android:id="@+id/playlist_menu_stop_sync"
+ android:title="@string/menu.stop_sync"/>
<item
android:id="@+id/playlist_update_info"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1a2068f0..66798cca 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -75,6 +75,8 @@
<string name="menu.set_timer">Set Timer</string>
<string name="menu.check_podcasts">Check For New Episodes</string>
<string name="menu.add_podcast">Add Channel</string>
+ <string name="menu.keep_synced">Keep Synced</string>
+ <string name="menu.stop_sync">Stop syncing</string>
<string name="playlist.label">Playlists</string>
<string name="playlist.update_info">Update Information</string>
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 {