From a0504c6185434789ebed8f67808b069a9c1bfbc7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 4 Jun 2013 21:52:15 -0700 Subject: Added ability to create new playlist from add to playlist menu --- .../dsub/fragments/SubsonicFragment.java | 55 +++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 2fcdc00f..0ff795e2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -627,6 +627,7 @@ public class SubsonicFragment extends SherlockFragment { @Override protected void done(final List playlists) { List names = new ArrayList(); + names.add("Create New"); for(Playlist playlist: playlists) { names.add(playlist.getName()); } @@ -635,7 +636,12 @@ public class SubsonicFragment extends SherlockFragment { 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); + + if(which > 0) { + addToPlaylist(playlists.get(which - 1), songs); + } else { + createNewPlaylist(songs); + } } }); AlertDialog dialog = builder.create(); @@ -683,6 +689,53 @@ public class SubsonicFragment extends SherlockFragment { } }.execute(); } + + private void createNewPlaylist(final List songs) { + View layout = context.getLayoutInflater().inflate(R.layout.save_playlist, null); + final EditText playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.download_playlist_title) + .setMessage(R.string.download_playlist_name) + .setView(layout) + .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + createNewPlaylist(songs, String.valueOf(playlistNameView.getText())); + } + }) + .setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }) + .setCancelable(true); + + AlertDialog dialog = builder.create(); + dialog.show(); + } + private void createNewPlaylist(final List songs, final String name) { + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.createPlaylist(null, name, songs, context, null); + return null; + } + + @Override + protected void done(Void result) { + Util.toast(context, R.string.download_playlist_done); + } + + @Override + protected void error(Throwable error) { + String msg = context.getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error); + Util.toast(context, msg); + } + }.execute(); + } public void displaySongInfo(final MusicDirectory.Entry song) { Integer bitrate = null; -- cgit v1.2.3