[Android] Fix playlist saving appending to existing one
Geoffrey Métais
git at videolan.org
Tue Jan 16 17:44:48 CET 2018
vlc-android | branch: chromecast | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 19 15:57:21 2017 +0100| [2618292d97430d30000a7018a27743b247f23406] | committer: Geoffrey Métais
Fix playlist saving appending to existing one
Close #408
> https://code.videolan.org/videolan/vlc-android/commit/2618292d97430d30000a7018a27743b247f23406
---
.../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 d17c34ff8..870c67418 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;
@@ -292,7 +293,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 4364e99d0..5591600b7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
@@ -208,7 +208,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 02f802655..333a93b70 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -230,16 +230,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