From 6152bb642d02c87977a21fe2d0814842de6756d4 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 22 Oct 2012 21:31:57 -0700 Subject: Added options to update name/comment of a playlist --- subsonic-android/res/layout/update_playlist.xml | 26 +++++++++++ .../res/menu/select_playlist_context.xml | 5 ++ subsonic-android/res/values/strings.xml | 7 ++- .../dsub/activity/SelectPlaylistActivity.java | 54 +++++++++++++++++++++- .../dsub/service/CachedMusicService.java | 5 ++ .../daneren2005/dsub/service/MusicService.java | 2 + .../dsub/service/OfflineMusicService.java | 5 ++ .../daneren2005/dsub/service/RESTMusicService.java | 11 +++++ 8 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 subsonic-android/res/layout/update_playlist.xml (limited to 'subsonic-android') diff --git a/subsonic-android/res/layout/update_playlist.xml b/subsonic-android/res/layout/update_playlist.xml new file mode 100644 index 00000000..c73d93ef --- /dev/null +++ b/subsonic-android/res/layout/update_playlist.xml @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file diff --git a/subsonic-android/res/menu/select_playlist_context.xml b/subsonic-android/res/menu/select_playlist_context.xml index a376ec58..6d844a16 100644 --- a/subsonic-android/res/menu/select_playlist_context.xml +++ b/subsonic-android/res/menu/select_playlist_context.xml @@ -25,6 +25,11 @@ android:id="@+id/playlist_menu_pin" android:title="@string/common.pin" /> + + Delete Star Unstar - Info + Details + Name + Comment DSub home Media library @@ -51,6 +53,9 @@ Failed to delete playlist %s Playlists + Update Information + Updated playlist information for %s + Failed to update playlist information for %s Help Welcome to DSub! diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java index 2249f0ec..028966a1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java @@ -25,6 +25,7 @@ import android.content.Intent; import android.os.Bundle; import android.view.*; import android.widget.AdapterView; +import android.widget.EditText; import android.widget.ListView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; @@ -159,6 +160,9 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt case R.id.playlist_info: displayPlaylistInfo(playlist); break; + case R.id.playlist_update_info: + updatePlaylistInfo(playlist); + break; default: return super.onContextItemSelected(menuItem); } @@ -199,7 +203,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt } @Override - protected void error(Throwable error) { + protected void error(Throwable error) { String msg; if (error instanceof OfflineException || error instanceof ServerTooOldException) { msg = getErrorMessage(error); @@ -226,4 +230,52 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt "\nSong Count: " + playlist.getSongCount() + "\nCreation Date: " + playlist.getCreated().replace('T', ' ')) .show(); } + + private void updatePlaylistInfo(final Playlist playlist) { + View dialogView = getLayoutInflater().inflate(R.layout.update_playlist, null); + final EditText nameBox = (EditText)dialogView.findViewById(R.id.get_playlist_name); + final EditText commentBox = (EditText)dialogView.findViewById(R.id.get_playlist_comment); + + nameBox.setText(playlist.getName()); + commentBox.setText(playlist.getComment()); + + new AlertDialog.Builder(this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(R.string.playlist_update_info) + .setView(dialogView) + .setPositiveButton("Ok", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new TabActivityBackgroundTask(SelectPlaylistActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); + musicService.updatePlaylist(playlist.getId(), nameBox.getText().toString(), commentBox.getText().toString(), SelectPlaylistActivity.this, null); + return null; + } + + @Override + protected void done(Void result) { + refresh(); + Util.toast(SelectPlaylistActivity.this, getResources().getString(R.string.playlist_updated_info, playlist.getName())); + } + + @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_updated_info_error, playlist.getName()) + " " + getErrorMessage(error); + } + + Util.toast(SelectPlaylistActivity.this, msg, false); + } + }.execute(); + } + + }) + .setNegativeButton("Cancel", null) + .show(); + } } \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index 870e2370..baab4c5f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -158,6 +158,11 @@ public class CachedMusicService implements MusicService { public void addToPlaylist(String id, List toAdd, Context context, ProgressListener progressListener) throws Exception { musicService.addToPlaylist(id, toAdd, 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); + } @Override public Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception { diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index c615134c..5f17c826 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -64,6 +64,8 @@ public interface MusicService { void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception; void addToPlaylist(String id, List toAdd, 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 b2a964b2..9b7120ea 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -268,6 +268,11 @@ public class OfflineMusicService extends RESTMusicService { public void addToPlaylist(String id, List toAdd, Context context, ProgressListener progressListener) throws Exception { throw new OfflineException("Updating 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"); + } @Override public Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception { diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index 2113caa1..4fc49a79 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -412,6 +412,17 @@ public class RESTMusicService implements MusicService { 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.asList(id, name, comment)); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } @Override public Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception { -- cgit v1.2.3