diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-10-21 15:57:46 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-10-21 15:57:46 -0700 |
commit | 9ce49b158d38cd8a6110dbe598d439f94c3f9cff (patch) | |
tree | b1e3d7d1d32978ea1baa9470864773dfe8516015 /subsonic-android/src/github | |
parent | 19735a1ab0d69a1fc33711ee971cbc2bcd869d41 (diff) | |
download | dsub-9ce49b158d38cd8a6110dbe598d439f94c3f9cff.tar.gz dsub-9ce49b158d38cd8a6110dbe598d439f94c3f9cff.tar.bz2 dsub-9ce49b158d38cd8a6110dbe598d439f94c3f9cff.zip |
Added option to delete playlists quickly
Diffstat (limited to 'subsonic-android/src/github')
5 files changed, 84 insertions, 15 deletions
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>(); |