diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-05-01 18:01:23 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-05-01 18:01:23 -0700 |
commit | 97026ad3b3b6ca29881f5415b6862a410c219231 (patch) | |
tree | 8a80ebecc48e94a002d88d605b2955e21b2d2e3d /app | |
parent | ddcdb7cfe6635b4069a3a16601637e6b846bfb7f (diff) | |
download | dsub-97026ad3b3b6ca29881f5415b6862a410c219231.tar.gz dsub-97026ad3b3b6ca29881f5415b6862a410c219231.tar.bz2 dsub-97026ad3b3b6ca29881f5415b6862a410c219231.zip |
Fix crash when coming across album with no album...you heard me.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java index b2fcded3..7151362c 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java @@ -19,6 +19,7 @@ package github.daneren2005.dsub.adapter; import android.content.Context; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -38,6 +39,7 @@ import java.util.List; import java.util.Set; public class AlbumListAdapter extends EndlessAdapter implements SectionIndexer { + private static final String TAG = AlbumListAdapter.class.getSimpleName(); Context context; ArrayAdapter<MusicDirectory.Entry> adapter; String type; @@ -97,26 +99,35 @@ public class AlbumListAdapter extends EndlessAdapter implements SectionIndexer { } private void recreateIndexes() { - if(!shouldIndex) { - return; - } - - Set<String> sectionSet = new LinkedHashSet<String>(30); - List<Integer> positionList = new ArrayList<Integer>(30); - for (int i = 0; i < adapter.getCount(); i++) { - MusicDirectory.Entry entry = adapter.getItem(i); - String index = entry.getAlbum().substring(0, 1); - if(!Character.isLetter(index.charAt(0))) { - index = "#"; + try { + if (!shouldIndex) { + return; } - if (!sectionSet.contains(index)) { - sectionSet.add(index); - positionList.add(i); + Set<String> sectionSet = new LinkedHashSet<String>(30); + List<Integer> positionList = new ArrayList<Integer>(30); + for (int i = 0; i < adapter.getCount(); i++) { + MusicDirectory.Entry entry = adapter.getItem(i); + String index; + if (entry.getAlbum() != null) { + index = entry.getAlbum().substring(0, 1); + if (!Character.isLetter(index.charAt(0))) { + index = "#"; + } + } else { + index = "*"; + } + + if (!sectionSet.contains(index)) { + sectionSet.add(index); + positionList.add(i); + } } + sections = sectionSet.toArray(new Object[sectionSet.size()]); + positions = positionList.toArray(new Integer[positionList.size()]); + } catch(Exception e) { + Log.e(TAG, "Error while recreating indexes"); } - sections = sectionSet.toArray(new Object[sectionSet.size()]); - positions = positionList.toArray(new Integer[positionList.size()]); } @Override |