diff options
Diffstat (limited to 'subsonic-android/src')
4 files changed, 75 insertions, 76 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 3448867a..bfdc9eb9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -86,52 +86,6 @@ public class DownloadActivity extends SubsonicActivity { return false; } } - - @Override - public Dialog onCreateDialog(int id) { - if (id == DownloadFragment.DIALOG_SAVE_PLAYLIST) { - AlertDialog.Builder builder; - - LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); - final View layout = inflater.inflate(R.layout.save_playlist, null); - playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name); - - builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.download_playlist_title); - builder.setMessage(R.string.download_playlist_name); - builder.setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - savePlaylistInBackground(String.valueOf(playlistNameView.getText())); - } - }); - builder.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - builder.setView(layout); - builder.setCancelable(true); - - return builder.create(); - } else { - return super.onCreateDialog(id); - } - } - - @Override - public void onPrepareDialog(int id, Dialog dialog) { - if (id == DownloadFragment.DIALOG_SAVE_PLAYLIST) { - String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null; - if (playlistName != null) { - playlistNameView.setText(playlistName); - } else { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - playlistNameView.setText(dateFormat.format(new Date())); - } - } - } @Override public void onBackPressed() { @@ -139,32 +93,4 @@ public class DownloadActivity extends SubsonicActivity { super.onBackPressed(); } } - - private void savePlaylistInBackground(final String playlistName) { - Util.toast(this, getResources().getString(R.string.download_playlist_saving, playlistName)); - getDownloadService().setSuggestedPlaylistName(playlistName); - new SilentBackgroundTask<Void>(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - List<MusicDirectory.Entry> entries = new LinkedList<MusicDirectory.Entry>(); - for (DownloadFile downloadFile : getDownloadService().getSongs()) { - entries.add(downloadFile.getSong()); - } - MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this); - musicService.createPlaylist(null, playlistName, entries, DownloadActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - Util.toast(DownloadActivity.this, R.string.download_playlist_done); - } - - @Override - protected void error(Throwable error) { - String msg = getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error); - Util.toast(DownloadActivity.this, msg); - } - }.execute(); - } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 9113cd74..9bcb4a05 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -606,7 +606,11 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe }.execute();
return true;
case R.id.menu_save_playlist:
- context.showDialog(DIALOG_SAVE_PLAYLIST);
+ List<MusicDirectory.Entry> entries = new LinkedList<MusicDirectory.Entry>();
+ for (DownloadFile downloadFile : getDownloadService().getSongs()) {
+ entries.add(downloadFile.getSong());
+ }
+ createNewPlaylist(entries, true);
return true;
case R.id.menu_star:
toggleStarred(song.getSong());
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 2fcdc00f..c6a0e89d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -66,8 +66,11 @@ import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.Util;
import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
@@ -627,6 +630,7 @@ public class SubsonicFragment extends SherlockFragment { @Override
protected void done(final List<Playlist> playlists) {
List<String> names = new ArrayList<String>();
+ names.add("Create New");
for(Playlist playlist: playlists) {
names.add(playlist.getName());
}
@@ -635,7 +639,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, false);
+ }
}
});
AlertDialog dialog = builder.create();
@@ -683,6 +692,65 @@ public class SubsonicFragment extends SherlockFragment { }
}.execute();
}
+
+ protected void createNewPlaylist(final List<MusicDirectory.Entry> songs, boolean getSuggestion) {
+ View layout = context.getLayoutInflater().inflate(R.layout.save_playlist, null);
+ final EditText playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name);
+ if(getSuggestion) {
+ String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null;
+ if (playlistName != null) {
+ playlistNameView.setText(playlistName);
+ } else {
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ playlistNameView.setText(dateFormat.format(new Date()));
+ }
+ } else {
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ playlistNameView.setText(dateFormat.format(new Date()));
+ }
+
+ 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<MusicDirectory.Entry> songs, final String name) {
+ new SilentBackgroundTask<Void>(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;
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index cf0c5ee1..818a4f67 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -158,6 +158,7 @@ public final class Util { SharedPreferences prefs = getPreferences(context); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, instance); + editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, null); editor.commit(); } |