[Android] Fix playlist saving appending to existing one
Geoffrey Métais
git at videolan.org
Wed Dec 20 17:10:10 CET 2017
vlc-android | branch: 2.5.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 19 15:57:21 2017 +0100| [7cadc197cb0940263a9d4fe0e246493c2e019d4c] | committer: Geoffrey Métais
Fix playlist saving appending to existing one
Close #408
(cherry picked from commit 2618292d97430d30000a7018a27743b247f23406)
> https://code.videolan.org/videolan/vlc-android/commit/7cadc197cb0940263a9d4fe0e246493c2e019d4c
---
.../org/videolan/vlc/gui/audio/AudioBrowserFragment.java | 3 ++-
.../org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java | 2 +-
.../org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java | 15 ++++++---------
vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java | 14 ++++++++++----
4 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 73673fef9..10e32eeef 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -54,6 +54,7 @@ import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.PlaylistActivity;
import org.videolan.vlc.gui.SecondaryActivity;
+import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.view.ContextMenuRecyclerView;
@@ -291,7 +292,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
}
if (id == R.id.audio_view_add_playlist) {
- UiTools.addToPlaylist(getActivity(), mediaItem.getTracks());
+ UiTools.addToPlaylist(getActivity(), mediaItem.getTracks(), SavePlaylistDialog.KEY_NEW_TRACKS);
return true;
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
index 176464c21..81661d7bb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
@@ -206,7 +206,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
tag = "equalizer";
break;
case ID_SAVE_PLAYLIST:
- UiTools.addToPlaylist(getActivity(), mService.getMedias());
+ UiTools.savePlaylist(getActivity(), mService.getMedias());
dismiss();
return;
default:
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
index 2379fa34d..129efecab 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
@@ -152,19 +152,17 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
Playlist playlist = mMedialibrary.getPlaylist(mPlaylistId);
boolean exists = playlist != null;
MediaWrapper[] tracks;
- if (!exists)
- playlist = mMedialibrary.createPlaylist(name);
- if (playlist == null)
- return;
+ if (!exists) playlist = mMedialibrary.createPlaylist(name);
+ if (playlist == null) return;
if (addTracks) {
tracks = mNewTrack;
} else {//Save a playlist
- for (MediaWrapper mw : playlist.getTracks())
+ for (MediaWrapper mw : playlist.getTracks()) {
playlist.remove(mw.getId());
+ }
tracks = mTracks;
}
- if (tracks == null)
- return;
+ if (tracks == null) return;
final LinkedList<Long> ids = new LinkedList<>();
for (MediaWrapper mw : tracks) {
long id = mw.getId();
@@ -181,8 +179,7 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
ids.add(id);
}
playlist.append(ids);
- if (mCallBack != null)
- mCallBack.run();
+ if (mCallBack != null) mCallBack.run();
}
});
dismiss();
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index af06fd3e9..875ef3793 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -229,16 +229,22 @@ public class UiTools {
});
}
+ public static void savePlaylist(FragmentActivity activity, List<MediaWrapper> list) {
+ MediaWrapper[] trackList = new MediaWrapper[list.size()];
+ list.toArray(trackList);
+ addToPlaylist(activity, trackList, SavePlaylistDialog.KEY_TRACKS);
+ }
+
public static void addToPlaylist(FragmentActivity activity, List<MediaWrapper> list) {
MediaWrapper[] trackList = new MediaWrapper[list.size()];
list.toArray(trackList);
- addToPlaylist(activity, trackList);
+ addToPlaylist(activity, trackList, SavePlaylistDialog.KEY_NEW_TRACKS);
}
- public static void addToPlaylist(FragmentActivity activity, MediaWrapper[] tracks) {
+ public static void addToPlaylist(FragmentActivity activity, MediaWrapper[] tracks, String key) {
SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
- Bundle args = new Bundle();
- args.putParcelableArray(SavePlaylistDialog.KEY_NEW_TRACKS, tracks);
+ final Bundle args = new Bundle();
+ args.putParcelableArray(key, tracks);
savePlaylistDialog.setArguments(args);
savePlaylistDialog.show(activity.getSupportFragmentManager(), "fragment_add_to_playlist");
}
More information about the Android
mailing list