diff --git a/.gitignore b/.gitignore index 39fb081a..09b993d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ *.iml .gradle /local.properties -/.idea/workspace.xml -/.idea/libraries +/.idea .DS_Store /build /captures diff --git a/CHANGELOG.md b/CHANGELOG.md index cfd19b91..5adfbcdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # CHANGELOG +# 1.0.8 + +Fixed bug related with [issue #16](https://github.com/pchmn/MaterialChipsInput/issues/16) + +# 1.0.6 - 1.0.7 + +Fixed bug related with [issue #7](https://github.com/pchmn/MaterialChipsInput/issues/7) + +# 1.0.5 + +Fixed bug related with [issue #13](https://github.com/pchmn/MaterialChipsInput/issues/13) + # 1.0.4 Fixed bug with `ChipView` label in v1.0.3 diff --git a/README.md b/README.md index ea9c6b55..72f98b55 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Implementation of Material Design [Chips](https://material.io/guidelines/compone Demo ## Demo -[Download sample-v1.0.4.apk](https://github.com/pchmn/MaterialChipsInput/raw/master/docs/material-chips-input-sample-v1.0.4.apk) +[Download sample-v1.0.8.apk](https://github.com/pchmn/MaterialChipsInput/raw/master/docs/material-chips-input-sample-v1.0.8.apk) ## Setup @@ -26,7 +26,7 @@ allprojects { In your app level build.gradle : ```java dependencies { - compile 'com.github.pchmn:MaterialChipsInput:1.0.5' + compile 'com.github.pchmn:MaterialChipsInput:1.0.8' } ```

diff --git a/docs/material-chips-input-sample-v1.0.6.apk b/docs/material-chips-input-sample-v1.0.6.apk new file mode 100644 index 00000000..aa53fb11 Binary files /dev/null and b/docs/material-chips-input-sample-v1.0.6.apk differ diff --git a/docs/material-chips-input-sample-v1.0.4_2.apk b/docs/material-chips-input-sample-v1.0.7.apk similarity index 53% rename from docs/material-chips-input-sample-v1.0.4_2.apk rename to docs/material-chips-input-sample-v1.0.7.apk index e3693754..9c2bdef9 100644 Binary files a/docs/material-chips-input-sample-v1.0.4_2.apk and b/docs/material-chips-input-sample-v1.0.7.apk differ diff --git a/docs/material-chips-input-sample-v1.0.8.apk b/docs/material-chips-input-sample-v1.0.8.apk new file mode 100644 index 00000000..11853f57 Binary files /dev/null and b/docs/material-chips-input-sample-v1.0.8.apk differ diff --git a/library/build.gradle b/library/build.gradle index 7bdbca9c..974cc24f 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,8 +8,8 @@ android { defaultConfig { minSdkVersion 15 targetSdkVersion 25 - versionCode 5 - versionName "1.0.4" + versionCode 9 + versionName "1.0.8" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 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 b5d8903b..5fd1273f 100644 --- a/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java +++ b/library/src/main/java/com/pchmn/materialchips/adapter/FilterableAdapter.java @@ -12,6 +12,7 @@ import android.widget.Filter; import android.widget.Filterable; import android.widget.TextView; +import android.widget.Toast; import com.pchmn.materialchips.ChipsInput; import com.pchmn.materialchips.R; @@ -24,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -48,6 +50,9 @@ public class FilterableAdapter extends RecyclerView.Adapter mComparator; + private Collator mCollator; public FilterableAdapter(Context context, @@ -58,14 +63,21 @@ public FilterableAdapter(Context context, ColorStateList textColor) { mContext = context; mRecyclerView = recyclerView; - Collections.sort(chipList, new Comparator() { + mCollator = Collator.getInstance(Locale.getDefault()); + mCollator.setStrength(Collator.PRIMARY); + mComparator = 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()); + return mCollator.compare(o1.getLabel(), o2.getLabel()); } - }); + }; + // remove chips that do not have label + Iterator iterator = chipList.iterator(); + while(iterator.hasNext()) { + if(iterator.next().getLabel() == null) + iterator.remove(); + } + sortList(chipList); mOriginalList.addAll(chipList); mChipList.addAll(chipList); mFilteredList.addAll(chipList); @@ -241,23 +253,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(); } @@ -271,5 +269,7 @@ private boolean contains(ChipInterface chip) { return false; } - + private void sortList(List list) { + Collections.sort(list, mComparator); + } } diff --git a/library/src/main/java/com/pchmn/materialchips/views/ChipsInputEditText.java b/library/src/main/java/com/pchmn/materialchips/views/ChipsInputEditText.java index 570d68ed..d3bb04f5 100644 --- a/library/src/main/java/com/pchmn/materialchips/views/ChipsInputEditText.java +++ b/library/src/main/java/com/pchmn/materialchips/views/ChipsInputEditText.java @@ -18,7 +18,7 @@ public ChipsInputEditText(Context context, AttributeSet attrs) { } public boolean isFilterableListVisible() { - return filterableListView.getVisibility() == VISIBLE; + return filterableListView != null && filterableListView.getVisibility() == VISIBLE; } public FilterableListView getFilterableListView() { diff --git a/sample/build.gradle b/sample/build.gradle index b56930e6..15b85c09 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -9,8 +9,8 @@ android { applicationId "com.pchmn.sample.materialchipsinput" minSdkVersion 15 targetSdkVersion 25 - versionCode 5 - versionName "1.0.4" + versionCode 9 + versionName "1.0.8" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java index 3dc06d1e..33c7adba 100644 --- a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java +++ b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java @@ -5,7 +5,6 @@ import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; -import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; @@ -13,9 +12,7 @@ import android.widget.TextView; import android.widget.Toast; -import com.pchmn.materialchips.ChipView; import com.pchmn.materialchips.ChipsInput; -import com.pchmn.materialchips.model.Chip; import com.pchmn.materialchips.model.ChipInterface; import com.tbruyelle.rxpermissions2.RxPermissions; @@ -31,7 +28,7 @@ public class ContactListActivity extends AppCompatActivity { @BindView(R.id.chips_input) ChipsInput mChipsInput; @BindView(R.id.validate) Button mValidateButton; @BindView(R.id.chip_list) TextView mChipListText; - private List mContactList = new ArrayList<>(); + private List mContactList; @Override protected void onCreate(Bundle savedInstanceState) { @@ -39,6 +36,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_contact_list); // butter knife ButterKnife.bind(this); + mContactList = new ArrayList<>(); // get contact list new RxPermissions(this)