[Android] Playlist : fix separator missing issue

Alexandre Perraud git at videolan.org
Mon Aug 8 14:05:05 CEST 2016


vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Fri Aug  5 17:58:19 2016 +0200| [76f750f4d318465a2c18e060dc713fea8ae21b18] | committer: Alexandre Perraud

Playlist : fix separator missing issue

> https://code.videolan.org/videolan/vlc-android/commit/76f750f4d318465a2c18e060dc713fea8ae21b18
---

 .../vlc/gui/audio/AudioBrowserFragment.java        | 17 +++---------
 .../vlc/gui/audio/AudioBrowserListAdapter.java     | 31 ++++++++++++----------
 .../vlc/gui/dialogs/SavePlaylistDialog.java        |  2 +-
 3 files changed, 22 insertions(+), 28 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 1c7b6e2..39405f3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -25,7 +25,6 @@ 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;
@@ -269,6 +268,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
             updateLists();
         else {
             updateEmptyView(mViewPager.getCurrentItem());
+            updatePlaylists();
         }
         mMediaLibrary.addUpdateHandler(mHandler);
         mMediaLibrary.setBrowser(this);
@@ -279,7 +279,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
                 mSwipeRefreshLayout.setEnabled(current.getFirstVisiblePosition() == 0);
             }
         });
-        updatePlaylists();
     }
 
     // Focus support. Start.
@@ -863,20 +862,12 @@ 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();
-                    }
-                });
-            }
+            //DB playlists
+            ArrayList<AudioBrowserListAdapter.ListItem> dbPlaylists = mMediaLibrary.getPlaylistDbItems();
+            mPlaylistAdapter.addAllDBPlaylists(dbPlaylists);
             //File playlists
             ArrayList<MediaWrapper> playlists = mMediaLibrary.getPlaylistFilesItems();
             mPlaylistAdapter.addAll(playlists, AudioBrowserListAdapter.TYPE_PLAYLISTS);
-            //DB playlists
-            ArrayList<AudioBrowserListAdapter.ListItem> dbPlaylists = mMediaLibrary.getPlaylistDbItems();
-            mPlaylistAdapter.addAll(dbPlaylists);
 
             mAdaptersToNotify.add(mPlaylistAdapter);
             if (mReadyToDisplay && !mDisplaying)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
index a60e80e..7544bf4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -120,19 +120,6 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
         mAlignMode = Integer.valueOf(preferences.getString("audio_title_alignment", "0"));
     }
 
-    public void addAll(final List<ListItem> items) {
-        mContext.runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                for (ListItem item : items) {
-                    mMediaItemMap.put(item.mTitle, item);
-                    mItems.add(item);
-                }
-                Collections.sort(mItems, mItemsComparator);
-            }
-        });
-    }
-
     public void add(String title, String subTitle, MediaWrapper media) {
         add(title, subTitle, media, null);
     }
@@ -155,12 +142,26 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
         }
     }
 
+    public void addAllDBPlaylists(final List<ListItem> items) {
+        mContext.runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                clear();
+                for (ListItem item : items) {
+                    mMediaItemMap.put(item.mMediaKey, item);
+                    mItems.add(item);
+                }
+            }
+        });
+    }
+
     public void addAll(List<MediaWrapper> mediaList, final int type) {
         final LinkedList<MediaWrapper> list = new LinkedList<MediaWrapper>(mediaList);
         mContext.runOnUiThread(new Runnable() {
             @Override
             public void run() {
-                clear();
+                if (type != TYPE_PLAYLISTS)
+                    clear();
                 String title, subTitle, key;
                 for (MediaWrapper media : list) {
                     switch (type){
@@ -226,6 +227,8 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
         char prevFirstChar = '%';
         boolean firstSeparator = true;
         ArrayList<String> sections = new ArrayList<>();
+        if (type == TYPE_PLAYLISTS)
+            Collections.sort(mItems, mItemsComparator);
 
         for (int i = 0; i < mItems.size(); ++i) {
             String title = mItems.get(i).mTitle;
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 3bb6393..83d5b97 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
@@ -73,7 +73,7 @@ public class SavePlaylistDialog extends DialogFragment implements AdapterView.On
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mAdapter = new AudioBrowserListAdapter(getActivity(), AudioBrowserListAdapter.ITEM_WITHOUT_COVER);
-        mAdapter.addAll(MediaLibrary.getInstance().getPlaylistDbItems());
+        mAdapter.addAllDBPlaylists(MediaLibrary.getInstance().getPlaylistDbItems());
         mTracks = getArguments().getParcelableArrayList(KEY_TRACKS);
         mNewTrack = getArguments().getParcelableArrayList(KEY_NEW_TRACKS);
     }



More information about the Android mailing list