[Android] Audio browser: group and move the separator insertion functions to the AudioBrowserListAdapter

Adrien Maglo git at videolan.org
Mon Nov 25 13:03:37 CET 2013


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon Nov 25 13:03:25 2013 +0100| [d879ee09ab4b737b082cc03062b4dacb7969fc36] | committer: Adrien Maglo

Audio browser: group and move the separator insertion functions to the AudioBrowserListAdapter

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=d879ee09ab4b737b082cc03062b4dacb7969fc36
---

 .../vlc/gui/audio/AudioBrowserFragment.java        |   13 +------------
 .../vlc/gui/audio/AudioBrowserListAdapter.java     |   20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 16 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 b7c6527..f19fa16 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -522,7 +522,6 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
             mSongsAdapter.add(audioList.get(i));
 
         char prevFirstLetter = 'A';
-        char prevFirstLetter2 = 'A';
 
         Collections.sort(audioList, byArtist);
         for (int i = 0; i < audioList.size(); i++) {
@@ -530,9 +529,9 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
             prevFirstLetter = addFirstLetterSeparator(mArtistsAdapter, i, media.getArtist(), prevFirstLetter);
             mArtistsAdapter.add(media.getArtist(), null, media);
             mArtistsAdapter.add(media.getArtist(), media.getAlbum(), media);
-            prevFirstLetter2 = addFirstLetterSeparator2(mArtistsAdapter2, i, media.getArtist(), prevFirstLetter2);
             mArtistsAdapter2.add(media.getArtist(), null, media);
         }
+        mArtistsAdapter2.addSeparators();
 
         Collections.sort(audioList, byAlbum);
         for (int i = 0; i < audioList.size(); i++) {
@@ -565,16 +564,6 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
         return prevFirstLetter;
     }
 
-    private final char addFirstLetterSeparator2(AudioBrowserListAdapter list, int i, String tittle, char prevFirstLetter) {
-        char firstLetter = tittle.toUpperCase().charAt(0);
-        if (Character.isLetter(firstLetter)
-            && (i == 0 || firstLetter != prevFirstLetter)) {
-            list.addSeparator(String.valueOf(firstLetter));
-            prevFirstLetter = firstLetter;
-        }
-        return prevFirstLetter;
-    }
-
     @Override
     public void sortBy(int sortby) {
         if(mSortBy == sortby) {
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 3bb8e3a..096ae1c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -97,10 +97,22 @@ public class AudioBrowserListAdapter extends BaseAdapter implements ListAdapter
         }
     }
 
-    public void addSeparator(String title) {
-        ListItem item = new ListItem(title, null, null, true);
-        mMediaItemMap.put(title, item);
-        mItems.add(item);
+    public void addSeparators() {
+        char prevFirstLetter = 'a';
+        boolean firstSeparator = true;
+
+        for (int i = 0; i < mItems.size(); ++i) {
+            String title = mItems.get(i).mTitle;
+            char firstLetter = title.toUpperCase().charAt(0);
+            if (Character.isLetter(firstLetter)
+                && (firstSeparator || firstLetter != prevFirstLetter)) {
+                ListItem item = new ListItem(String.valueOf(firstLetter), null, null, true);
+                mItems.add(i, item);
+                i++;
+                prevFirstLetter = firstLetter;
+                firstSeparator = false;
+            }
+        }
     }
 
     public void clear() {



More information about the Android mailing list