aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-10-21 14:42:16 -0700
committerScott Jackson <daneren2005@gmail.com>2012-10-21 14:42:16 -0700
commit61c5c2f08724e9e2b55fcb2cd7a36dbabb6cbce8 (patch)
treeed435a50d2a44cc65f9c31f5f7fffea94a6135cc /subsonic-android/src
parent5f2096d02bb0a0743294bb80f2ff00305838f9fb (diff)
downloaddsub-61c5c2f08724e9e2b55fcb2cd7a36dbabb6cbce8.tar.gz
dsub-61c5c2f08724e9e2b55fcb2cd7a36dbabb6cbce8.tar.bz2
dsub-61c5c2f08724e9e2b55fcb2cd7a36dbabb6cbce8.zip
Get a list of playlists to return and let user choose one to add the selected songs to
Diffstat (limited to 'subsonic-android/src')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java67
1 files changed, 49 insertions, 18 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java
index 306882a1..0aed7575 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java
@@ -29,12 +29,11 @@ import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.widget.AdapterView;
-import android.widget.Button;
-import android.widget.ListView;
+import android.widget.*;
import com.actionbarsherlock.view.Menu;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.service.OfflineException;
@@ -43,8 +42,6 @@ import github.daneren2005.dsub.util.*;
import java.util.ArrayList;
import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
public class SelectAlbumActivity extends SubsonicTabActivity {
@@ -461,31 +458,65 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
getDownloadService().delete(getSelectedSongs());
}
}
-
- private void unpin() {
- if (getDownloadService() != null) {
- getDownloadService().unpin(getSelectedSongs());
- }
- }
private void addToPlaylist() {
- addToPlaylist("Test");
- }
-
- private void addToPlaylist(final String playlist) {
final List<MusicDirectory.Entry> songs = getSelectedSongs();
+ if(songs.isEmpty()) {
+ Util.toast(this, "No songs selected");
+ return;
+ }
+ new SilentBackgroundTask<List<Playlist>>(this) {
+ @Override
+ protected List<Playlist> doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this);
+ return musicService.getPlaylists(false, SelectAlbumActivity.this, this);
+ }
+
+ @Override
+ protected void done(final List<Playlist> playlists) {
+ List<String> names = new ArrayList<String>();
+ for(Playlist playlist: playlists) {
+ names.add(playlist.getName());
+ }
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(SelectAlbumActivity.this);
+ builder.setTitle("Add to Playlist")
+ .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ addToPlaylist(playlists.get(which), songs);
+ }
+ });
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(SelectAlbumActivity.this, msg, false);
+ }
+ }.execute();
+ }
+
+ private void addToPlaylist(final Playlist playlist, final List<MusicDirectory.Entry> songs) {
new SilentBackgroundTask<Void>(this) {
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this);
- musicService.addToPlaylist(playlist, songs, SelectAlbumActivity.this, null);
+ musicService.addToPlaylist(playlist.getId(), songs, SelectAlbumActivity.this, null);
return null;
}
@Override
protected void done(Void result) {
- Util.toast(SelectAlbumActivity.this, getResources().getString(R.string.updated_playlist, playlist));
+ Util.toast(SelectAlbumActivity.this, getResources().getString(R.string.updated_playlist, songs.size(), playlist.getName()));
}
@Override
@@ -494,7 +525,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
} else {
- msg = getResources().getString(R.string.updated_playlist_error, playlist) + " " + getErrorMessage(error);
+ msg = getResources().getString(R.string.updated_playlist_error, playlist.getName()) + " " + getErrorMessage(error);
}
Util.toast(SelectAlbumActivity.this, msg, false);