diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-06-05 20:36:51 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-06-05 20:36:51 -0700 |
commit | bf7acf155e730b22ae17f0bb302b14c7f1076009 (patch) | |
tree | d29e9f5ef170affe1513f0eccee4d103f32fc7dd | |
parent | 00afabea262d17d820004fe1dca6e29eaccd56f6 (diff) | |
download | dsub-bf7acf155e730b22ae17f0bb302b14c7f1076009.tar.gz dsub-bf7acf155e730b22ae17f0bb302b14c7f1076009.tar.bz2 dsub-bf7acf155e730b22ae17f0bb302b14c7f1076009.zip |
Added option to overwrite existing playlists for 4.7+
10 files changed, 107 insertions, 6 deletions
diff --git a/subsonic-android/res/layout/save_playlist.xml b/subsonic-android/res/layout/save_playlist.xml index a0272f37..43f1827a 100644 --- a/subsonic-android/res/layout/save_playlist.xml +++ b/subsonic-android/res/layout/save_playlist.xml @@ -13,5 +13,14 @@ android:inputType="text"
android:singleLine="true"/>
+ <CheckBox
+ android:id="@+id/save_playlist_overwrite"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/playlist.overwrite"
+ android:layout_marginLeft="4dp"
+ android:checked="false"
+ android:visibility="gone"/>
+
</LinearLayout>
diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index b5e8f3e1..b288e035 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -75,6 +75,7 @@ <string name="playlist.update_info">Update Information</string>
<string name="playlist.updated_info">Updated playlist information for %s</string>
<string name="playlist.updated_info_error">Failed to update playlist information for %s</string>
+ <string name="playlist.overwrite">Overwrite existing playlist</string>
<string name="help.label">Help</string>
<string name="help.title">Welcome to DSub!</string>
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 13f61625..2bb04fa3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -492,7 +492,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter warnIfNetworkOrStorageUnavailable();
getDownloadService().download(songs, save, autoplay, playNext, shuffle);
if (playlistName != null) {
- getDownloadService().setSuggestedPlaylistName(playlistName);
+ getDownloadService().setSuggestedPlaylistName(playlistName, playlistId);
+ } else {
+ getDownloadService().setSuggestedPlaylistName(null, null);
}
if (autoplay) {
Util.startActivityWithoutTransition(context, DownloadActivity.class);
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index c6a0e89d..35a97e7c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -34,8 +34,8 @@ import android.view.ContextMenu; import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.widget.AdapterView;
import android.widget.Button;
+import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
@@ -69,7 +69,6 @@ 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;
@@ -696,10 +695,21 @@ public class SubsonicFragment extends SherlockFragment { 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);
+ final CheckBox overwriteCheckBox = (CheckBox) layout.findViewById(R.id.save_playlist_overwrite);
if(getSuggestion) {
String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null;
if (playlistName != null) {
playlistNameView.setText(playlistName);
+ Version version = Util.getServerRestVersion(context);
+ Version updatePlaylistVersion = new Version("1.8.0");
+ try {
+ if(version.compareTo(updatePlaylistVersion) >= 0 && Integer.parseInt(getDownloadService().getSuggestedPlaylistId()) != -1) {
+ overwriteCheckBox.setChecked(true);
+ overwriteCheckBox.setVisibility(View.VISIBLE);
+ }
+ } catch(Exception e) {
+ Log.d(TAG, "Playlist id isn't a integer, probably MusicCabinet");
+ }
} else {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
playlistNameView.setText(dateFormat.format(new Date()));
@@ -716,7 +726,11 @@ public class SubsonicFragment extends SherlockFragment { .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
- createNewPlaylist(songs, String.valueOf(playlistNameView.getText()));
+ if(overwriteCheckBox.isChecked()) {
+ overwritePlaylist(songs, String.valueOf(playlistNameView.getText()), getDownloadService().getSuggestedPlaylistId());
+ } else {
+ createNewPlaylist(songs, String.valueOf(playlistNameView.getText()));
+ }
}
})
.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
@@ -751,6 +765,35 @@ public class SubsonicFragment extends SherlockFragment { }
}.execute();
}
+ private void overwritePlaylist(final List<MusicDirectory.Entry> songs, final String name, final String id) {
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ MusicDirectory playlist = musicService.getPlaylist(id, name, context, null);
+ List<MusicDirectory.Entry> toDelete = playlist.getChildren();
+ musicService.overwritePlaylist(id, name, toDelete.size(), 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;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(context, msg, false);
+ }
+ }.execute();
+ }
public void displaySongInfo(final MusicDirectory.Entry song) {
Integer bitrate = null;
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index 314f065e..3802ab3e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -169,6 +169,11 @@ public class CachedMusicService implements MusicService { } @Override + public void overwritePlaylist(String id, String name, int toRemove, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception { + musicService.overwritePlaylist(id, name, toRemove, toAdd, context, progressListener); + } + + @Override public void updatePlaylist(String id, String name, String comment, boolean pub, Context context, ProgressListener progressListener) throws Exception { musicService.updatePlaylist(id, name, comment, pub, context, progressListener); } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java index 43e24096..328cc962 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java @@ -107,10 +107,12 @@ public interface DownloadService { long getDownloadListUpdateRevision(); - void setSuggestedPlaylistName(String name); + void setSuggestedPlaylistName(String name, String id); String getSuggestedPlaylistName(); + String getSuggestedPlaylistId(); + boolean getEqualizerAvailable(); boolean getVisualizerAvailable(); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index f659a434..7858ac3a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -110,6 +110,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { private long revision; private static DownloadService instance; private String suggestedPlaylistName; + private String suggestedPlaylistId; private PowerManager.WakeLock wakeLock; private boolean keepScreenOn; private int cachedPosition = 0; @@ -931,8 +932,9 @@ public class DownloadServiceImpl extends Service implements DownloadService { } @Override - public void setSuggestedPlaylistName(String name) { + public void setSuggestedPlaylistName(String name, String id) { this.suggestedPlaylistName = name; + this.suggestedPlaylistId = id; } @Override @@ -941,6 +943,11 @@ public class DownloadServiceImpl extends Service implements DownloadService { } @Override + public String getSuggestedPlaylistId() { + return suggestedPlaylistId; + } + + @Override public boolean getEqualizerAvailable() { return equalizerAvailable; } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index f69ebfb1..1b60cc37 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -70,6 +70,8 @@ public interface MusicService { void removeFromPlaylist(String id, List<Integer> toRemove, Context context, ProgressListener progressListener) throws Exception; + void overwritePlaylist(String id, String name, int toRemove, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception; + void updatePlaylist(String id, String name, String comment, boolean pub, 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 9af58b16..e20a64de 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -418,6 +418,11 @@ public class OfflineMusicService extends RESTMusicService { } @Override + public void overwritePlaylist(String id, String name, int toRemove, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Overwriting playlist not available in offline mode"); + } + + @Override public void updatePlaylist(String id, String name, String comment, boolean pub, Context context, ProgressListener progressListener) throws Exception { throw new OfflineException("Updating playlist not available in offline mode"); } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index f4f64046..dae4944c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -442,6 +442,31 @@ public class RESTMusicService implements MusicService { } @Override + public void overwritePlaylist(String id, String name, int toRemove, 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>(); + List<Object> values = new ArrayList<Object>(); + names.add("playlistId"); + values.add(id); + names.add("name"); + values.add(name); + for(MusicDirectory.Entry song: toAdd) { + names.add("songIdToAdd"); + values.add(song.getId()); + } + for(int i = 0; i < toRemove; i++) { + names.add("songIndexToRemove"); + values.add(i); + } + Reader reader = getReader(context, progressListener, "updatePlaylist", null, names, values); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override public void updatePlaylist(String id, String name, String comment, boolean pub, Context context, ProgressListener progressListener) throws Exception { checkServerVersion(context, "1.8", "Updating playlists is not supported."); Reader reader = getReader(context, progressListener, "updatePlaylist", null, Arrays.asList("playlistId", "name", "comment", "public"), Arrays.<Object>asList(id, name, comment, pub)); |