[Android] Appdend feature for playlist saving dialog
Geoffrey Métais
git at videolan.org
Tue Mar 15 15:48:17 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 15 14:43:42 2016 +0100| [dc190a23278da2691bb8e08e2f077659fbef1ca6] | committer: Geoffrey Métais
Appdend feature for playlist saving dialog
> https://code.videolan.org/videolan/vlc-android/commit/dc190a23278da2691bb8e08e2f077659fbef1ca6
---
.../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