diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a77a43b..cfd19b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +# 1.0.4 + +Fixed bug with `ChipView` label in v1.0.3 + # 1.0.3 Fixed bug with `NullPointerException` ([see](https://github.com/pchmn/MaterialChipsInput/issues/3) issue) diff --git a/README.md b/README.md index 01bdbda4..b0359610 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.3.apk](https://github.com/pchmn/MaterialChipsInput/raw/master/docs/material-chips-input-sample-v1.0.3.apk) +[Download sample-v1.0.4.apk](https://github.com/pchmn/MaterialChipsInput/raw/master/docs/material-chips-input-sample-v1.0.4.apk) ## Setup @@ -26,7 +26,7 @@ allprojects { In your app level build.gradle : ```java dependencies { - compile 'com.github.pchmn:MaterialChipsInput:1.0.3' + compile 'com.github.pchmn:MaterialChipsInput:1.0.4' } ```

diff --git a/docs/material-chips-input-sample-v1.0.4.apk b/docs/material-chips-input-sample-v1.0.4.apk new file mode 100644 index 00000000..274c3e4c Binary files /dev/null and b/docs/material-chips-input-sample-v1.0.4.apk differ diff --git a/library/build.gradle b/library/build.gradle index 4c19464b..7bdbca9c 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,8 +8,8 @@ android { defaultConfig { minSdkVersion 15 targetSdkVersion 25 - versionCode 3 - versionName "1.0.3" + versionCode 5 + versionName "1.0.4" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/library/src/main/java/com/pchmn/materialchips/ChipView.java b/library/src/main/java/com/pchmn/materialchips/ChipView.java index 4db85788..07e3aea9 100644 --- a/library/src/main/java/com/pchmn/materialchips/ChipView.java +++ b/library/src/main/java/com/pchmn/materialchips/ChipView.java @@ -92,6 +92,7 @@ private void init(AttributeSet attrs) { mHasAvatarIcon = a.getBoolean(R.styleable.ChipView_hasAvatarIcon, false); int avatarIconId = a.getResourceId(R.styleable.ChipView_avatarIcon, NONE); if(avatarIconId != NONE) mAvatarIconDrawable = ContextCompat.getDrawable(mContext, avatarIconId); + if(mAvatarIconDrawable != null) mHasAvatarIcon = true; // delete icon mDeletable = a.getBoolean(R.styleable.ChipView_deletable, false); mDeleteIconColor = a.getColorStateList(R.styleable.ChipView_deleteIconColor); @@ -131,17 +132,14 @@ private void inflateWithAttributes() { public void inflate(ChipInterface chip) { mChip = chip; - + // label + mLabel = mChip.getLabel(); // icon - if(mHasAvatarIcon && mChip.getAvatarUri() != null) - setAvatarIcon(mChip.getAvatarUri()); - else if(mHasAvatarIcon && mChip.getAvatarDrawable() != null) - setAvatarIcon(mChip.getAvatarDrawable()); - else if(mHasAvatarIcon) - mAvatarIconImageView.setImageBitmap(mLetterTileProvider.getLetterTile(chip.getLabel())); + mAvatarIconUri = mChip.getAvatarUri(); + mAvatarIconDrawable = mChip.getAvatarDrawable(); - // label - mLabelTextView.setText(mChip.getLabel()); + // inflate + inflateWithAttributes(); } /** diff --git a/library/src/main/java/com/pchmn/materialchips/adapter/ChipsAdapter.java b/library/src/main/java/com/pchmn/materialchips/adapter/ChipsAdapter.java index c38ef36d..2e1083ee 100644 --- a/library/src/main/java/com/pchmn/materialchips/adapter/ChipsAdapter.java +++ b/library/src/main/java/com/pchmn/materialchips/adapter/ChipsAdapter.java @@ -370,7 +370,6 @@ public List getChipList() { } private boolean listContains(List contactList, ChipInterface chip) { - Log.e(TAG, mChipsInput.getChipValidator() == null ? "null": "not null"); if(mChipsInput.getChipValidator() != null) { for(ChipInterface item: contactList) { diff --git a/library/src/main/java/com/pchmn/materialchips/util/LetterTileProvider.java b/library/src/main/java/com/pchmn/materialchips/util/LetterTileProvider.java index 416c3950..9028a528 100644 --- a/library/src/main/java/com/pchmn/materialchips/util/LetterTileProvider.java +++ b/library/src/main/java/com/pchmn/materialchips/util/LetterTileProvider.java @@ -80,6 +80,7 @@ public LetterTileProvider(Context context) { * default image is shown instead */ public Bitmap getLetterTile(String displayName) { + // workaround if(displayName == null || displayName.length() == 0) return null; @@ -112,8 +113,9 @@ public Bitmap getLetterTile(String displayName) { * default image is shown instead */ public Bitmap getCircularLetterTile(String displayName) { + // workaround if(displayName == null || displayName.length() == 0) - return null; + displayName = "."; final Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888); final char firstChar = displayName.charAt(0); diff --git a/sample/build.gradle b/sample/build.gradle index 93a87bb5..b56930e6 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -9,8 +9,8 @@ android { applicationId "com.pchmn.sample.materialchipsinput" minSdkVersion 15 targetSdkVersion 25 - versionCode 4 - versionName "1.0.3" + versionCode 5 + versionName "1.0.4" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ChipExamplesActivity.java b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ChipExamplesActivity.java index 33a11121..0ec3aa70 100644 --- a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ChipExamplesActivity.java +++ b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ChipExamplesActivity.java @@ -86,9 +86,8 @@ protected void onCreate(Bundle savedInstanceState) { // programmatically Uri uri = null; ChipView chipView1 = new ChipView(this); - chipView1.setLabel("Test 1"); - chipView1.setLabelColor(ContextCompat.getColor(this, R.color.colorPrimary)); - chipView1.setAvatarIcon(uri); + chipView1.setLabel("Pritesh"); + chipView1.setPadding(2,2,2,2); chipView1.setHasAvatarIcon(true); ChipView chipView2 = new ChipView(this); @@ -98,7 +97,7 @@ protected void onCreate(Bundle savedInstanceState) { chipView2.setAvatarIcon(uri); chipView2.setDeleteIconColor(ContextCompat.getColor(this, R.color.colorPrimary)); - //mLayout.addView(chipView1); - //mLayout.addView(chipView2); + mLayout.addView(chipView1); + mLayout.addView(chipView2); } } 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 927e2afc..26ca9c82 100644 --- a/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java +++ b/sample/src/main/java/com/pchmn/sample/materialchipsinput/ContactListActivity.java @@ -5,13 +5,16 @@ 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; import android.widget.Button; import android.widget.TextView; +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; @@ -64,6 +67,7 @@ public void onTextChanged(CharSequence text) { // show selected chips mValidateButton.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { String listString = "";