diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-10-25 19:23:57 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-10-25 19:23:57 -0700 |
commit | 58fca5bd6a6bcf2c94235d25f67b4f65163441fe (patch) | |
tree | 2dcfcbff0b1d2de39fd87d7c47c88706cbdd19a2 /subsonic-android | |
parent | 25dd0ebe6389f36a91aeb00a277712f4c5544aa8 (diff) | |
download | dsub-58fca5bd6a6bcf2c94235d25f67b4f65163441fe.tar.gz dsub-58fca5bd6a6bcf2c94235d25f67b4f65163441fe.tar.bz2 dsub-58fca5bd6a6bcf2c94235d25f67b4f65163441fe.zip |
Added add to playlist support to now playing tab
Diffstat (limited to 'subsonic-android')
4 files changed, 88 insertions, 80 deletions
diff --git a/subsonic-android/res/menu/nowplaying_context.xml b/subsonic-android/res/menu/nowplaying_context.xml index 9ad2be52..82ef2e8b 100644 --- a/subsonic-android/res/menu/nowplaying_context.xml +++ b/subsonic-android/res/menu/nowplaying_context.xml @@ -19,4 +19,8 @@ <item android:id="@+id/menu_star" android:title="@string/common.star"/> + + <item + android:id="@+id/menu_add_playlist" + android:title="@string/menu.add_playlist"/> </menu> diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 003b88a0..482320b8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -623,6 +623,11 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi return true; case R.id.menu_toggle: toggleFullscreenAlbumArt(); + case R.id.menu_add_playlist: + songs = new ArrayList<MusicDirectory.Entry>(1); + songs.add(song.getSong()); + addToPlaylist(songs); + return true; default: return false; } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 7d9d7df2..4d94d0a1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -153,7 +153,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity { selectAll(false, false); return true; case R.id.menu_add_playlist: - addToPlaylist(); + addToPlaylist(getSelectedSongs()); return true; case R.id.menu_exit: intent = new Intent(this, MainActivity.class); @@ -453,80 +453,6 @@ public class SelectAlbumActivity extends SubsonicTabActivity { getDownloadService().delete(getSelectedSongs()); } } - - private void addToPlaylist() { - final List<MusicDirectory.Entry> songs = getSelectedSongs(); - if(songs.isEmpty()) { - Util.toast(this, "No songs selected"); - return; - } - - new LoadingTask<List<Playlist>>(this, true) { - @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.getId(), songs, SelectAlbumActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - Util.toast(SelectAlbumActivity.this, getResources().getString(R.string.updated_playlist, songs.size(), 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.updated_playlist_error, playlist.getName()) + " " + getErrorMessage(error); - } - - Util.toast(SelectAlbumActivity.this, msg, false); - } - }.execute(); - } private void playVideo(MusicDirectory.Entry entry) { Intent intent = new Intent(Intent.ACTION_VIEW); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index c65e3661..5b3ef186 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -24,7 +24,9 @@ import java.util.LinkedList; import java.util.List;
import android.app.Activity;
+import android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.media.AudioManager;
@@ -40,12 +42,10 @@ import android.widget.TextView; import github.daneren2005.dsub.R;
import com.actionbarsherlock.app.SherlockActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.*;
-import github.daneren2005.dsub.util.Constants;
-import github.daneren2005.dsub.util.ImageLoader;
-import github.daneren2005.dsub.util.ModalBackgroundTask;
-import github.daneren2005.dsub.util.SilentBackgroundTask;
-import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.util.*;
+import java.util.ArrayList;
/**
* @author Sindre Mehus
@@ -330,6 +330,79 @@ public class SubsonicTabActivity extends SherlockActivity { task.execute();
}
+
+ protected void addToPlaylist(final List<MusicDirectory.Entry> songs) {
+ if(songs.isEmpty()) {
+ Util.toast(this, "No songs selected");
+ return;
+ }
+
+ new LoadingTask<List<Playlist>>(this, true) {
+ @Override
+ protected List<Playlist> doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
+ return musicService.getPlaylists(false, SubsonicTabActivity.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(SubsonicTabActivity.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(SubsonicTabActivity.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(SubsonicTabActivity.this);
+ musicService.addToPlaylist(playlist.getId(), songs, SubsonicTabActivity.this, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ Util.toast(SubsonicTabActivity.this, getResources().getString(R.string.updated_playlist, songs.size(), 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.updated_playlist_error, playlist.getName()) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(SubsonicTabActivity.this, msg, false);
+ }
+ }.execute();
+ }
private void setUncaughtExceptionHandler() {
Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
|