[Android] Add "Append to playlist" feature for audio browser

Geoffrey Métais git at videolan.org
Tue Mar 15 16:08:12 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 15 14:44:25 2016 +0100| [406a16ff36a76cc38fcdacc175a5c803ed43be21] | committer: Geoffrey Métais

Add "Append to playlist" feature for audio browser

> https://code.videolan.org/videolan/vlc-android/commit/406a16ff36a76cc38fcdacc175a5c803ed43be21
---

 vlc-android/res/menu/audio_list_browser.xml        |  3 +++
 vlc-android/res/values/strings.xml                 |  1 +
 .../videolan/vlc/gui/audio/AudioAlbumFragment.java | 12 ++++++++++
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java    | 12 ++++++++++
 .../vlc/gui/audio/AudioBrowserFragment.java        | 27 ++++++++++++++++++++--
 5 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/vlc-android/res/menu/audio_list_browser.xml b/vlc-android/res/menu/audio_list_browser.xml
index bb01ecc..f17432c 100644
--- a/vlc-android/res/menu/audio_list_browser.xml
+++ b/vlc-android/res/menu/audio_list_browser.xml
@@ -16,6 +16,9 @@
             android:title="@string/info" />
     </group>
     <item
+        android:id="@+id/audio_view_add_playlist"
+        android:title="@string/add_to_playlist" />
+    <item
         android:id="@+id/audio_list_browser_delete"
         android:title="@string/delete"/>
     <group android:id="@+id/phone_only" >
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index cf60605..d7d74f9 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -611,6 +611,7 @@
     <string name="network_shared_folders">Shared folders</string>
     <string name="encryption_warning">Warning, encryption is not available for this Android version, password will be stored in a private space but not encrypted</string>
     <string name="store_password">Remember password</string>
+    <string name="add_to_playlist">Add to playlist</string>
 
     <string-array name="chroma_formats" translatable="false">
         <item>RGB 32-bit</item>
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
index 8240593..291da69 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
@@ -31,6 +31,7 @@ import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
 import android.support.annotation.Nullable;
+import android.support.v4.app.FragmentManager;
 import android.support.v7.widget.PopupMenu;
 import android.util.Log;
 import android.view.ContextMenu;
@@ -51,6 +52,7 @@ import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.PlaybackServiceFragment;
 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.media.MediaDatabase;
@@ -230,6 +232,16 @@ public class AudioAlbumFragment extends PlaybackServiceFragment implements Adapt
                 i.putExtra("param", mMediaList.get(position).getUri().toString());
                 getActivity().startActivityForResult(i, MainActivity.ACTIVITY_RESULT_SECONDARY);
                 return true;
+        } else if (id == R.id .audio_view_add_playlist) {
+            ArrayList<MediaWrapper> medias = new ArrayList<>();
+            medias.add(mAdapter.getItem(position));
+            FragmentManager fm = getActivity().getSupportFragmentManager();
+            SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
+            Bundle args = new Bundle();
+            args.putParcelableArrayList(SavePlaylistDialog.KEY_NEW_TRACKS, medias);
+            savePlaylistDialog.setArguments(args);
+            savePlaylistDialog.show(fm, "fragment_add_to_playlist");
+            return true;
         }
 
         return super.onContextItemSelected(item);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index 678fe43..f540652 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -28,6 +28,7 @@ import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
 import android.support.design.widget.TabLayout;
+import android.support.v4.app.FragmentManager;
 import android.support.v4.view.ViewPager;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
@@ -53,6 +54,7 @@ import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.PlaybackServiceFragment;
 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.MediaComparators;
 import org.videolan.vlc.gui.helpers.UiTools;
@@ -258,6 +260,16 @@ public class AudioAlbumsSongsFragment extends PlaybackServiceFragment implements
                 return true;
         }
 
+        if (id == R.id .audio_view_add_playlist) {
+            FragmentManager fm = getActivity().getSupportFragmentManager();
+            SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
+            Bundle args = new Bundle();
+            args.putParcelableArrayList(SavePlaylistDialog.KEY_NEW_TRACKS, adapter.getMedias(position));
+            savePlaylistDialog.setArguments(args);
+            savePlaylistDialog.show(fm, "fragment_add_to_playlist");
+            return true;
+        }
+
         if (useAllItems) {
             medias = new ArrayList<MediaWrapper>();
             startPosition = mSongsAdapter.getListWithPosition(medias, position);
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 cc6281d..fc09692 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -25,9 +25,11 @@ import android.content.Intent;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.Looper;
 import android.os.Message;
 import android.support.design.widget.FloatingActionButton;
 import android.support.design.widget.TabLayout;
+import android.support.v4.app.FragmentManager;
 import android.support.v4.view.PagerAdapter;
 import android.support.v4.view.ViewPager;
 import android.view.ContextMenu;
@@ -57,6 +59,7 @@ import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.SecondaryActivity;
 import org.videolan.vlc.gui.browser.MediaBrowserFragment;
+import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
 import org.videolan.vlc.gui.helpers.AudioUtil;
 import org.videolan.vlc.gui.helpers.MediaComparators;
 import org.videolan.vlc.gui.helpers.UiTools;
@@ -213,7 +216,8 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
             }
 
             @Override
-            public void onTabUnselected(TabLayout.Tab tab) {}
+            public void onTabUnselected(TabLayout.Tab tab) {
+            }
 
             @Override
             public void onTabReselected(TabLayout.Tab tab) {
@@ -450,7 +454,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
 
         int startPosition;
         int mode = mViewPager.getCurrentItem();
-        List<MediaWrapper> medias;
+        ArrayList<MediaWrapper> medias;
         int id = item.getItemId();
 
         boolean useAllItems = id == R.id.audio_list_browser_play_all;
@@ -555,6 +559,17 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
             medias = adapter.getMedias(position);
         }
 
+        if (id == R.id .audio_view_add_playlist) {
+            FragmentManager fm = getActivity().getSupportFragmentManager();
+            SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
+            Bundle args = new Bundle();
+            args.putParcelableArrayList(SavePlaylistDialog.KEY_NEW_TRACKS, medias);
+            savePlaylistDialog.setArguments(args);
+            savePlaylistDialog.setCallBack(updatePlaylists);
+            savePlaylistDialog.show(fm, "fragment_add_to_playlist");
+            return true;
+        }
+
         if (mService != null) {
             if (append)
                 mService.append(medias);
@@ -869,6 +884,14 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
     Runnable updatePlaylists = new Runnable() {
         @Override
         public void run() {
+            if (Looper.myLooper() != Looper.getMainLooper()) {
+                mHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        mPlaylistAdapter.clear();
+                    }
+                });
+            }
             //File playlists
             ArrayList<MediaWrapper> playlists = mMediaLibrary.getPlaylistFilesItems();
             mPlaylistAdapter.addAll(playlists, AudioBrowserListAdapter.TYPE_PLAYLISTS);



More information about the Android mailing list