aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github
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 /subsonic-android/src/github
parent64a92b7d8243ac376385c8ed0ba65f84179e4e5e (diff)
downloaddsub-2e3820f52ddf5720053db60b2d9fa251e0089149.tar.gz
dsub-2e3820f52ddf5720053db60b2d9fa251e0089149.tar.bz2
dsub-2e3820f52ddf5720053db60b2d9fa251e0089149.zip
Added options to remove songs from playlists
Diffstat (limited to 'subsonic-android/src/github')
-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
5 files changed, 102 insertions, 11 deletions
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));