aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorowner <owner@DeeDee-Laptop>2012-11-23 13:24:37 -0800
committerowner <owner@DeeDee-Laptop>2012-11-23 13:24:37 -0800
commit2e3820f52ddf5720053db60b2d9fa251e0089149 (patch)
tree56829f840667ed9447cc59f1940c782cd745056e
parent64a92b7d8243ac376385c8ed0ba65f84179e4e5e (diff)
downloaddsub-2e3820f52ddf5720053db60b2d9fa251e0089149.tar.gz
dsub-2e3820f52ddf5720053db60b2d9fa251e0089149.tar.bz2
dsub-2e3820f52ddf5720053db60b2d9fa251e0089149.zip
Added options to remove songs from playlists
-rw-r--r--subsonic-android/res/menu/select_song.xml4
-rw-r--r--subsonic-android/res/menu/select_song_context.xml4
-rw-r--r--subsonic-android/res/values/strings.xml2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java82
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java5
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/MusicService.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java5
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java19
8 files changed, 112 insertions, 11 deletions
diff --git a/subsonic-android/res/menu/select_song.xml b/subsonic-android/res/menu/select_song.xml
index cd49e44f..3a55fee0 100644
--- a/subsonic-android/res/menu/select_song.xml
+++ b/subsonic-android/res/menu/select_song.xml
@@ -47,6 +47,10 @@
android:title="@string/menu.add_playlist"/>
<item
+ android:id="@+id/menu_remove_playlist"
+ android:title="@string/menu.remove_playlist"/>
+
+ <item
android:id="@+id/menu_play_last"
android:icon="@drawable/action_play_all"
android:title="@string/menu.play_last"
diff --git a/subsonic-android/res/menu/select_song_context.xml b/subsonic-android/res/menu/select_song_context.xml
index b4e81799..95cf5eb3 100644
--- a/subsonic-android/res/menu/select_song_context.xml
+++ b/subsonic-android/res/menu/select_song_context.xml
@@ -35,6 +35,10 @@
android:title="@string/menu.add_playlist"/>
<item
+ android:id="@+id/song_menu_remove_playlist"
+ android:title="@string/menu.remove_playlist"/>
+
+ <item
android:id="@+id/song_menu_star"
android:title="@string/common.star"/>
diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml
index 12e93949..dc02569a 100644
--- a/subsonic-android/res/values/strings.xml
+++ b/subsonic-android/res/values/strings.xml
@@ -52,6 +52,7 @@
<string name="menu.settings">Settings</string>
<string name="menu.help">Help</string>
<string name="menu.add_playlist">Add To Playlist</string>
+ <string name="menu.remove_playlist">Remove From Playlist</string>
<string name="menu.deleted_playlist">Deleted playlist %s</string>
<string name="menu.deleted_playlist_error">Failed to delete playlist %s</string>
@@ -145,6 +146,7 @@
<string name="playlist_error">Failed to grab list of playlists</string>
<string name="updated_playlist">Added %1$s songs to \"%2$s\"</string>
<string name="updated_playlist_error">Failed to update \"%s\", please try later.</string>
+ <string name="removed_playlist">Removed %1$s songs from \"%2$s\"</string>
<string name="song_details.all">%1$s %2$s</string>
<string name="song_details.kbps">%d kbps</string>
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java
index fea1cfd0..891c2edd 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java
@@ -34,16 +34,11 @@ import android.widget.*;
import com.actionbarsherlock.view.Menu;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.service.DownloadFile;
-import github.daneren2005.dsub.service.MusicService;
-import github.daneren2005.dsub.service.MusicServiceFactory;
+import github.daneren2005.dsub.service.*;
import github.daneren2005.dsub.util.*;
import java.io.File;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
public class SelectAlbumActivity extends SubsonicTabActivity {
@@ -115,10 +110,17 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
inflater.inflate(R.menu.select_album, menu);
hideButtons = false;
} else {
- if(Util.isOffline(this))
+ if(Util.isOffline(this)) {
inflater.inflate(R.menu.select_song_offline, menu);
- else
+ }
+ else {
inflater.inflate(R.menu.select_song, menu);
+
+ String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
+ if(playlistId == null) {
+ menu.removeItem(R.id.menu_remove_playlist);
+ }
+ }
}
return true;
}
@@ -157,6 +159,11 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
case R.id.menu_add_playlist:
addToPlaylist(getSelectedSongs());
return true;
+ case R.id.menu_remove_playlist:
+ String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
+ String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME);
+ removeFromPlaylist(playlistId, playlistName, getSelectedIndexes());
+ return true;
case R.id.menu_exit:
intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -226,10 +233,16 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
inflater.inflate(R.menu.select_album_context, menu);
} else if(!entry.isVideo()) {
MenuInflater inflater = getMenuInflater();
- if(Util.isOffline(this))
+ if(Util.isOffline(this)) {
inflater.inflate(R.menu.select_song_context_offline, menu);
- else
+ }
+ else {
inflater.inflate(R.menu.select_song_context, menu);
+ String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
+ if(playlistId == null) {
+ menu.removeItem(R.id.song_menu_remove_playlist);
+ }
+ }
} else {
MenuInflater inflater = getMenuInflater();
if(Util.isOffline(this))
@@ -298,6 +311,11 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
case R.id.song_menu_play_external:
playExternalPlayer(entry);
break;
+ case R.id.song_menu_remove_playlist:
+ String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
+ String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME);
+ removeFromPlaylist(playlistId, playlistName, Arrays.<Integer>asList(info.position - 1));
+ break;
default:
return super.onContextItemSelected(menuItem);
}
@@ -425,6 +443,19 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
}
return songs;
}
+
+ private List<Integer> getSelectedIndexes() {
+ List<Integer> indexes = new ArrayList<Integer>();
+
+ int count = entryList.getCount();
+ for (int i = 0; i < count; i++) {
+ if (entryList.isItemChecked(i)) {
+ indexes.add(i - 1);
+ }
+ }
+
+ return indexes;
+ }
private void download(final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) {
if (getDownloadService() == null) {
@@ -651,4 +682,33 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
return header;
}
+
+ public void removeFromPlaylist(final String id, final String name, final List<Integer> indexes) {
+ new LoadingTask<Void>(this, true) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this);
+ musicService.removeFromPlaylist(id, indexes, SelectAlbumActivity.this, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ refresh();
+ Util.toast(SelectAlbumActivity.this, getResources().getString(R.string.removed_playlist, indexes.size(), name));
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = getResources().getString(R.string.updated_playlist_error, name) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(SelectAlbumActivity.this, msg, false);
+ }
+ }.execute();
+ }
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java
index 42fd8e57..c9233d01 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -161,6 +161,11 @@ public class CachedMusicService implements MusicService {
}
@Override
+ public void removeFromPlaylist(String id, List<Integer> toRemove, Context context, ProgressListener progressListener) throws Exception {
+ musicService.removeFromPlaylist(id, toRemove, context, progressListener);
+ }
+
+ @Override
public void updatePlaylist(String id, String name, String comment, Context context, ProgressListener progressListener) throws Exception {
musicService.updatePlaylist(id, name, comment, context, progressListener);
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java
index ebcfe9aa..67e4bed5 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java
@@ -65,6 +65,8 @@ public interface MusicService {
void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception;
+ void removeFromPlaylist(String id, List<Integer> toRemove, Context context, ProgressListener progressListener) throws Exception;
+
void updatePlaylist(String id, String name, String comment, Context context, ProgressListener progressListener) throws Exception;
Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception;
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
index 135a1e12..ce353740 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -295,6 +295,11 @@ public class OfflineMusicService extends RESTMusicService {
}
@Override
+ public void removeFromPlaylist(String id, List<Integer> toRemove, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Removing from playlist not available in offline mode");
+ }
+
+ @Override
public void updatePlaylist(String id, String name, String comment, Context context, ProgressListener progressListener) throws Exception {
throw new OfflineException("Updating playlist not available in offline mode");
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java
index 25bacb61..00e9f2b1 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java
@@ -423,6 +423,25 @@ public class RESTMusicService implements MusicService {
}
@Override
+ public void removeFromPlaylist(String id, List<Integer> toRemove, Context context, ProgressListener progressListener) throws Exception {
+ checkServerVersion(context, "1.8", "Updating playlists is not supported.");
+ List<String> names = new ArrayList<String>();
+ List<Object> values = new ArrayList<Object>();
+ names.add("playlistId");
+ values.add(id);
+ for(Integer song: toRemove) {
+ names.add("songIndexToRemove");
+ values.add(song);
+ }
+ Reader reader = getReader(context, progressListener, "updatePlaylist", null, names, values);
+ try {
+ new ErrorParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
public void updatePlaylist(String id, String name, String comment, Context context, ProgressListener progressListener) throws Exception {
checkServerVersion(context, "1.8", "Updating playlists is not supported.");
Reader reader = getReader(context, progressListener, "updatePlaylist", null, Arrays.asList("playlistId", "name", "comment"), Arrays.<Object>asList(id, name, comment));