diff --git a/docs/material-chips-input-sample-v1.0.4_4.apk b/docs/material-chips-input-sample-v1.0.4_4.apk new file mode 100644 index 00000000..289008a3 Binary files /dev/null and b/docs/material-chips-input-sample-v1.0.4_4.apk differ diff --git a/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java b/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java index 50b83cdb..68b91519 100644 --- a/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java +++ b/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java @@ -49,6 +49,9 @@ public class FilterableAdapter extends RecyclerView.Adapter mComparator; + private Collator mCollator; public FilterableAdapter(Context context, @@ -59,23 +62,18 @@ public FilterableAdapter(Context context, ColorStateList textColor) { mContext = context; mRecyclerView = recyclerView; - if(chipList == null) { - Log.e(TAG, "The filterable list is null"); - Toast.makeText(context, "The filterable list is null", Toast.LENGTH_LONG).show(); - } - else { - Collections.sort(chipList, new Comparator() { - @Override - public int compare(ChipInterface o1, ChipInterface o2) { - Collator collator = Collator.getInstance(Locale.getDefault()); - collator.setStrength(Collator.PRIMARY); - return collator.compare(o1.getLabel(), o2.getLabel()); - } - }); - mOriginalList.addAll(chipList); - mChipList.addAll(chipList); - mFilteredList.addAll(chipList); - } + mCollator = Collator.getInstance(Locale.getDefault()); + mCollator.setStrength(Collator.PRIMARY); + mComparator = new Comparator() { + @Override + public int compare(ChipInterface o1, ChipInterface o2) { + return mCollator.compare(o1.getLabel(), o2.getLabel()); + } + }; + sortList(chipList); + mOriginalList.addAll(chipList); + mChipList.addAll(chipList); + mFilteredList.addAll(chipList); mLetterTileProvider = new LetterTileProvider(mContext); mBackgroundColor = backgroundColor; mTextColor = textColor; @@ -248,23 +246,9 @@ private void addChip(ChipInterface chip) { mChipList.add(chip); mFilteredList.add(chip); // sort original list - Collections.sort(mChipList, new Comparator() { - @Override - public int compare(ChipInterface o1, ChipInterface o2) { - Collator collator = Collator.getInstance(Locale.getDefault()); - collator.setStrength(Collator.PRIMARY); - return collator.compare(o1.getLabel(), o2.getLabel()); - } - }); + sortList(mChipList); // sort filtered list - Collections.sort(mFilteredList, new Comparator() { - @Override - public int compare(ChipInterface o1, ChipInterface o2) { - Collator collator = Collator.getInstance(Locale.getDefault()); - collator.setStrength(Collator.PRIMARY); - return collator.compare(o1.getLabel(), o2.getLabel()); - } - }); + sortList(mFilteredList); notifyDataSetChanged(); } @@ -278,5 +262,7 @@ private boolean contains(ChipInterface chip) { return false; } - + private void sortList(List list) { + Collections.sort(list, mComparator); + } }