diff options
7 files changed, 91 insertions, 15 deletions
diff --git a/subsonic-android/res/menu/select_playlist_context.xml b/subsonic-android/res/menu/select_playlist_context.xml index 4fe24f76..b6a20c95 100644 --- a/subsonic-android/res/menu/select_playlist_context.xml +++ b/subsonic-android/res/menu/select_playlist_context.xml @@ -19,6 +19,11 @@ <item android:id="@+id/playlist_menu_pin" android:title="@string/common.pin" + /> + + <item + android:id="@+id/playlist_menu_delete" + android:title="@string/common.delete" /> </menu>
\ No newline at end of file diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index d47df064..fa3fcefd 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -46,6 +46,8 @@ <string name="menu.settings">Settings</string>
<string name="menu.help">Help</string>
<string name="menu.add_playlist">Add To Playlist</string>
+ <string name="menu.deleted_playlist">Deleted playlist %s</string>
+ <string name="menu.deleted_playlist_error">Failed to delete playlist %s</string>
<string name="playlist.label">Playlists</string>
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java index 3f9f16ff..ef9c8003 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java @@ -19,6 +19,8 @@ package github.daneren2005.dsub.activity; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.*; @@ -28,11 +30,9 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Playlist; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.util.BackgroundTask; -import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.PlaylistAdapter; -import github.daneren2005.dsub.util.TabActivityBackgroundTask; -import github.daneren2005.dsub.util.Util; +import github.daneren2005.dsub.service.OfflineException; +import github.daneren2005.dsub.service.ServerTooOldException; +import github.daneren2005.dsub.util.*; import java.util.List; @@ -124,6 +124,10 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.select_playlist_context, menu); + + if (Util.isOffline(this)) { + menu.findItem(R.id.playlist_menu_delete).setVisible(false); + } } @Override @@ -154,6 +158,9 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); break; + case R.id.playlist_menu_delete: + deletePlaylist(playlist); + break; default: return super.onContextItemSelected(menuItem); } @@ -171,4 +178,44 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); } + private void deletePlaylist(final Playlist playlist) { + new AlertDialog.Builder(this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle("Confirm") + .setMessage("Do you want to delete " + playlist.getName()) + .setPositiveButton("Ok", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new TabActivityBackgroundTask<Void>(SelectPlaylistActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); + musicService.deletePlaylist(playlist.getId(), SelectPlaylistActivity.this, null); + return null; + } + + @Override + protected void done(Void result) { + refresh(); + Util.toast(SelectPlaylistActivity.this, getResources().getString(R.string.menu_deleted_playlist, 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.menu_deleted_playlist_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 af29cf51..870e2370 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -148,6 +148,16 @@ public class CachedMusicService implements MusicService { public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception { musicService.createPlaylist(id, name, entries, context, progressListener); } + + @Override + public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception { + musicService.deletePlaylist(id, context, progressListener); + } + + @Override + public void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception { + musicService.addToPlaylist(id, toAdd, context, progressListener); + } @Override public Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception { @@ -233,11 +243,6 @@ public class CachedMusicService implements MusicService { public void setStarred(String id, boolean starred, Context context, ProgressListener progressListener) throws Exception { musicService.setStarred(id, starred, context, progressListener); } - - @Override - public void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception { - musicService.addToPlaylist(id, toAdd, context, progressListener); - } private void checkSettingsChanged(Context context) { String newUrl = Util.getRestUrl(context, null); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index d6b88d83..c615134c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -61,6 +61,8 @@ public interface MusicService { void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception; + void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception; + void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, 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 4662b974..b2a964b2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -258,6 +258,16 @@ public class OfflineMusicService extends RESTMusicService { public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception { throw new OfflineException("Playlists not available in offline mode"); } + + @Override + public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Playlists not available in offline mode"); + } + + @Override + public void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, 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 { @@ -313,11 +323,6 @@ public class OfflineMusicService extends RESTMusicService { public void setStarred(String id, boolean starred, Context context, ProgressListener progressListener) throws Exception { throw new OfflineException("Starring not available in offline mode"); } - - @Override - public void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception { - throw new OfflineException("Updating playlist not available in offline mode"); - } @Override public MusicDirectory getRandomSongs(int size, 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 e5fb059b..2113caa1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -385,6 +385,16 @@ public class RESTMusicService implements MusicService { } @Override + public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "deletePlaylist", null, "id", id); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override public void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception { checkServerVersion(context, "1.8", "Updating playlists is not supported."); List<String> names = new ArrayList<String>(); |