[Android] Audio browser: add a separator with a sharp sign when the title of the media does not begin with a letter

Adrien Maglo git at videolan.org
Fri Dec 6 11:24:16 CET 2013


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Fri Dec  6 11:24:06 2013 +0100| [124412708a9f7c0abddb34c7fea9c1fdf78966c1] | committer: Adrien Maglo

Audio browser: add a separator with a sharp sign when the title of the media does not begin with a letter

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

 .../vlc/gui/audio/AudioBrowserFragment.java        |    8 +++----
 .../vlc/gui/audio/AudioBrowserListAdapter.java     |   23 ++++++++++++++------
 2 files changed, 20 insertions(+), 11 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 25c90fb..1e29983 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -367,28 +367,28 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
             mSongsAdapter.add(media.getTitle(), media.getArtist(), media);
         }
         if (mSortBy != SORT_BY_LENGTH)
-            mSongsAdapter.addSeparators();
+            mSongsAdapter.addLeterSeparators();
 
         Collections.sort(audioList, MediaComparators.byArtist);
         for (int i = 0; i < audioList.size(); i++) {
             Media media = audioList.get(i);
             mArtistsAdapter.add(media.getArtist(), null, media);
         }
-        mArtistsAdapter.addSeparators();
+        mArtistsAdapter.addLeterSeparators();
 
         Collections.sort(audioList, MediaComparators.byAlbum);
         for (int i = 0; i < audioList.size(); i++) {
             Media media = audioList.get(i);
             mAlbumsAdapter.add(media.getAlbum(), null, media);
         }
-        mAlbumsAdapter.addSeparators();
+        mAlbumsAdapter.addLeterSeparators();
 
         Collections.sort(audioList, MediaComparators.byGenre);
         for (int i = 0; i < audioList.size(); i++) {
             Media media = audioList.get(i);
             mGenresAdapter.add(media.getGenre(), null, media);
         }
-        mGenresAdapter.addSeparators();
+        mGenresAdapter.addLeterSeparators();
 
         mSongsAdapter.notifyDataSetChanged();
         mArtistsAdapter.notifyDataSetChanged();
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 3b3579c..b7c75cb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -95,19 +95,28 @@ public class AudioBrowserListAdapter extends BaseAdapter {
         }
     }
 
-    public void addSeparators() {
-        char prevFirstLetter = 'a';
+    public void addLeterSeparators() {
+        char prevFirstChar = '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);
+            char firstChar = title.toUpperCase().charAt(0);
+
+            if (Character.isLetter(firstChar)) {
+                if (firstSeparator || firstChar != prevFirstChar) {
+                    ListItem item = new ListItem(String.valueOf(firstChar), null, null, true);
+                    mItems.add(i, item);
+                    i++;
+                    prevFirstChar = firstChar;
+                    firstSeparator = false;
+                }
+            }
+            else if (firstSeparator) {
+                ListItem item = new ListItem("#", null, null, true);
                 mItems.add(i, item);
                 i++;
-                prevFirstLetter = firstLetter;
+                prevFirstChar = firstChar;
                 firstSeparator = false;
             }
         }



More information about the Android mailing list