Skip to content

Commit

Permalink
Fixed bug with ChipView label
Browse files Browse the repository at this point in the history
  • Loading branch information
pchmn committed Apr 24, 2017
1 parent 6136d85 commit f209a84
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Implementation of Material Design [Chips](https://material.io/guidelines/compone
<img src="https://github.com/pchmn/MaterialChipsInput/blob/master/docs/demo2.gif" alt="Demo" height="600px"/>

## 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

Expand All @@ -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'
}
```
<br><br>
Expand Down
Binary file added docs/material-chips-input-sample-v1.0.4.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
16 changes: 7 additions & 9 deletions library/src/main/java/com/pchmn/materialchips/ChipView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ public List<ChipInterface> getChipList() {
}

private boolean listContains(List<ChipInterface> contactList, ChipInterface chip) {
Log.e(TAG, mChipsInput.getChipValidator() == null ? "null": "not null");

if(mChipsInput.getChipValidator() != null) {
for(ChipInterface item: contactList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 = "";
Expand Down

0 comments on commit f209a84

Please sign in to comment.