[Android] Append feature for playlist saving dialog
Geoffrey Métais
git at videolan.org
Tue Mar 15 16:08:10 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 15 14:43:42 2016 +0100| [0fa7b39487f1cdc5297f90ba90b0c2751d91875c] | committer: Geoffrey Métais
Append feature for playlist saving dialog
> https://code.videolan.org/videolan/vlc-android/commit/0fa7b39487f1cdc5297f90ba90b0c2751d91875c
---
.../vlc/gui/dialogs/SavePlaylistDialog.java | 36 +++++++++++++++++-----
1 file changed, 29 insertions(+), 7 deletions(-)
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 c8ef247..3bb6393 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
@@ -55,6 +55,7 @@ public class SavePlaylistDialog extends DialogFragment implements AdapterView.On
public final static String TAG = "VLC/SavePlaylistDialog";
public static final String KEY_TRACKS = "PLAYLIST_TRACKS";
+ public static final String KEY_NEW_TRACKS = "PLAYLIST_TRACKS";
EditText mEditText;
ListView mListView;
@@ -63,6 +64,8 @@ public class SavePlaylistDialog extends DialogFragment implements AdapterView.On
Button mCancelButton;
AudioBrowserListAdapter mAdapter;
ArrayList<MediaWrapper> mTracks;
+ ArrayList<MediaWrapper> mNewTrack;
+ Runnable mCallBack;
public SavePlaylistDialog(){}
@@ -72,6 +75,11 @@ public class SavePlaylistDialog extends DialogFragment implements AdapterView.On
mAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITHOUT_COVER);
mAdapter.addAll(MediaLibrary.getInstance().getPlaylistDbItems());
mTracks = getArguments().getParcelableArrayList(KEY_TRACKS);
+ mNewTrack = getArguments().getParcelableArrayList(KEY_NEW_TRACKS);
+ }
+
+ public void setCallBack(Runnable cb) {
+ mCallBack = cb;
}
@NonNull
@@ -132,14 +140,28 @@ public class SavePlaylistDialog extends DialogFragment implements AdapterView.On
public void run() {
final MediaDatabase db = MediaDatabase.getInstance();
final String name = mEditText.getText().toString().trim();
- if (db.playlistExists(name))
- db.playlistDelete(name);
- db.playlistAdd(name);
- MediaWrapper mw;
- for (int i = 0 ; i< mTracks.size() ; ++i){
- mw = mTracks.get(i);
- db.playlistInsertItem(name, i, mw.getLocation());
+ boolean addTracks = mNewTrack != null;
+ boolean exists = db.playlistExists(name);
+ if (addTracks) {
+ int position = 0;
+ if (!exists)
+ db.playlistAdd(name);
+ else
+ position = db.playlistGetItems(name).length;
+ for (int i = 0 ; i < mNewTrack.size(); ++i)
+ db.playlistInsertItem(name, position+i, mNewTrack.get(i).getLocation());
+ } else { //Save a playlist
+ if (exists)
+ db.playlistDelete(name);
+ db.playlistAdd(name);
+ MediaWrapper mw;
+ for (int i = 0; i < mTracks.size(); ++i) {
+ mw = mTracks.get(i);
+ db.playlistInsertItem(name, i, mw.getLocation());
+ }
}
+ if (mCallBack != null)
+ mCallBack.run();
}
});
dismiss();
More information about the Android
mailing list