aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-06-04 22:02:57 -0700
committerScott Jackson <daneren2005@gmail.com>2013-06-04 22:02:57 -0700
commited07cbefed26344739c4c442c7695a096f5b2cf0 (patch)
treecf704fafa7ce31602543a633aa607a17ce8bf0f2
parentb70ee482389f84bf1441c77f2d1faca1feece061 (diff)
downloaddsub-ed07cbefed26344739c4c442c7695a096f5b2cf0.tar.gz
dsub-ed07cbefed26344739c4c442c7695a096f5b2cf0.tar.bz2
dsub-ed07cbefed26344739c4c442c7695a096f5b2cf0.zip
Set playlist suggested name + merged old download activity method
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java74
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java6
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java19
3 files changed, 22 insertions, 77 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 5341bad3..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;
@@ -640,7 +643,7 @@ public class SubsonicFragment extends SherlockFragment {
if(which > 0) {
addToPlaylist(playlists.get(which - 1), songs);
} else {
- createNewPlaylist(songs);
+ createNewPlaylist(songs, false);
}
}
});
@@ -690,9 +693,21 @@ public class SubsonicFragment extends SherlockFragment {
}.execute();
}
- protected void createNewPlaylist(final List<MusicDirectory.Entry> songs) {
+ 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)