Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to androidx #130

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@ buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.6.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.1'
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}

allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 28 20:31:03 CEST 2017
#Wed May 13 16:38:42 EET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
30 changes: 15 additions & 15 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 29
buildToolsVersion '29.0.0'

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 9
versionName "1.0.8"
targetSdkVersion 29
versionCode 12
versionName "2.0.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
buildTypes {
Expand All @@ -23,23 +23,23 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
testCompile 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.13'

// recycler
compile 'com.android.support:recyclerview-v7:25.3.0'
compile 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'

// circle image view
compile 'de.hdodenhof:circleimageview:2.1.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'

// butter knife
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
implementation 'com.jakewharton:butterknife:10.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
}

apply plugin: 'com.github.dcendents.android-maven'
Expand Down

This file was deleted.

103 changes: 53 additions & 50 deletions library/src/main/java/com/pchmn/materialchips/ChipView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.ColorInt;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pchmn.materialchips.model.Chip;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;

import com.pchmn.materialchips.model.ChipInterface;
import com.pchmn.materialchips.util.LetterTileProvider;
import com.pchmn.materialchips.util.ViewUtil;
Expand All @@ -29,15 +28,19 @@
public class ChipView extends RelativeLayout {

private static final String TAG = ChipView.class.toString();
// context
private Context mContext;
// xml elements
@BindView(R2.id.content) LinearLayout mContentLayout;
@BindView(R2.id.icon) CircleImageView mAvatarIconImageView;
@BindView(R2.id.label) TextView mLabelTextView;
@BindView(R2.id.delete_button) ImageButton mDeleteButton;
// attributes
private static final int NONE = -1;
// xml elements
@BindView(R2.id.content)
LinearLayout mContentLayout;
@BindView(R2.id.icon)
CircleImageView mAvatarIconImageView;
@BindView(R2.id.label)
TextView mLabelTextView;
@BindView(R2.id.delete_button)
ImageButton mDeleteButton;
// context
private Context mContext;
private String mLabel;
private ColorStateList mLabelColor;
private boolean mHasAvatarIcon = false;
Expand All @@ -64,6 +67,23 @@ public ChipView(Context context, AttributeSet attrs) {
init(attrs);
}

private static ChipView newInstance(Builder builder) {
ChipView chipView = new ChipView(builder.context);
chipView.mLabel = builder.label;
chipView.mLabelColor = builder.labelColor;
chipView.mHasAvatarIcon = builder.hasAvatarIcon;
chipView.mAvatarIconUri = builder.avatarIconUri;
chipView.mAvatarIconDrawable = builder.avatarIconDrawable;
chipView.mDeletable = builder.deletable;
chipView.mDeleteIcon = builder.deleteIcon;
chipView.mDeleteIconColor = builder.deleteIconColor;
chipView.mBackgroundColor = builder.backgroundColor;
chipView.mChip = builder.chip;
chipView.inflateWithAttributes();

return chipView;
}

/**
* Inflate the view according to attributes
*
Expand All @@ -78,7 +98,7 @@ private void init(AttributeSet attrs) {
mLetterTileProvider = new LetterTileProvider(mContext);

// attributes
if(attrs != null) {
if (attrs != null) {
TypedArray a = mContext.getTheme().obtainStyledAttributes(
attrs,
R.styleable.ChipView,
Expand All @@ -91,17 +111,19 @@ private void init(AttributeSet attrs) {
// avatar icon
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;
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);
int deleteIconId = a.getResourceId(R.styleable.ChipView_deleteIcon, NONE);
if(deleteIconId != NONE) mDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId);
if (deleteIconId != NONE)
mDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId);
// background color
mBackgroundColor = a.getColorStateList(R.styleable.ChipView_backgroundColor);
}
finally {
} finally {
a.recycle();
}
}
Expand All @@ -116,7 +138,7 @@ private void init(AttributeSet attrs) {
private void inflateWithAttributes() {
// label
setLabel(mLabel);
if(mLabelColor != null)
if (mLabelColor != null)
setLabelColor(mLabelColor);

// avatar
Expand All @@ -126,7 +148,7 @@ private void inflateWithAttributes() {
setDeletable(mDeletable);

// background color
if(mBackgroundColor != null)
if (mBackgroundColor != null)
setChipBackgroundColor(mBackgroundColor);
}

Expand Down Expand Up @@ -189,29 +211,28 @@ public void setLabelColor(@ColorInt int color) {
public void setHasAvatarIcon(boolean hasAvatarIcon) {
mHasAvatarIcon = hasAvatarIcon;

if(!mHasAvatarIcon) {
if (!mHasAvatarIcon) {
// hide icon
mAvatarIconImageView.setVisibility(GONE);
// adjust padding
if(mDeleteButton.getVisibility() == VISIBLE)
if (mDeleteButton.getVisibility() == VISIBLE)
mLabelTextView.setPadding(ViewUtil.dpToPx(12), 0, 0, 0);
else
mLabelTextView.setPadding(ViewUtil.dpToPx(12), 0, ViewUtil.dpToPx(12), 0);

}
else {
} else {
// show icon
mAvatarIconImageView.setVisibility(VISIBLE);
// adjust padding
if(mDeleteButton.getVisibility() == VISIBLE)
if (mDeleteButton.getVisibility() == VISIBLE)
mLabelTextView.setPadding(ViewUtil.dpToPx(8), 0, 0, 0);
else
mLabelTextView.setPadding(ViewUtil.dpToPx(8), 0, ViewUtil.dpToPx(12), 0);

// set icon
if(mAvatarIconUri != null)
if (mAvatarIconUri != null)
mAvatarIconImageView.setImageURI(mAvatarIconUri);
else if(mAvatarIconDrawable != null)
else if (mAvatarIconDrawable != null)
mAvatarIconImageView.setImageDrawable(mAvatarIconDrawable);
else
mAvatarIconImageView.setImageBitmap(mLetterTileProvider.getLetterTile(getLabel()));
Expand Down Expand Up @@ -247,28 +268,27 @@ public void setAvatarIcon(Uri avatarUri) {
*/
public void setDeletable(boolean deletable) {
mDeletable = deletable;
if(!mDeletable) {
if (!mDeletable) {
// hide delete icon
mDeleteButton.setVisibility(GONE);
// adjust padding
if(mAvatarIconImageView.getVisibility() == VISIBLE)
if (mAvatarIconImageView.getVisibility() == VISIBLE)
mLabelTextView.setPadding(ViewUtil.dpToPx(8), 0, ViewUtil.dpToPx(12), 0);
else
mLabelTextView.setPadding(ViewUtil.dpToPx(12), 0, ViewUtil.dpToPx(12), 0);
}
else {
} else {
// show icon
mDeleteButton.setVisibility(VISIBLE);
// adjust padding
if(mAvatarIconImageView.getVisibility() == VISIBLE)
if (mAvatarIconImageView.getVisibility() == VISIBLE)
mLabelTextView.setPadding(ViewUtil.dpToPx(8), 0, 0, 0);
else
mLabelTextView.setPadding(ViewUtil.dpToPx(12), 0, 0, 0);

// set icon
if(mDeleteIcon != null)
if (mDeleteIcon != null)
mDeleteButton.setImageDrawable(mDeleteIcon);
if(mDeleteIconColor != null)
if (mDeleteIconColor != null)
mDeleteButton.getDrawable().mutate().setColorFilter(mDeleteIconColor.getDefaultColor(), PorterDuff.Mode.SRC_ATOP);
}
}
Expand Down Expand Up @@ -430,21 +450,4 @@ public ChipView build() {
return newInstance(this);
}
}

private static ChipView newInstance(Builder builder) {
ChipView chipView = new ChipView(builder.context);
chipView.mLabel = builder.label;
chipView.mLabelColor = builder.labelColor;
chipView.mHasAvatarIcon = builder.hasAvatarIcon;
chipView.mAvatarIconUri = builder.avatarIconUri;
chipView.mAvatarIconDrawable = builder.avatarIconDrawable;
chipView.mDeletable = builder.deletable;
chipView.mDeleteIcon = builder.deleteIcon;
chipView.mDeleteIconColor = builder.deleteIconColor;
chipView.mBackgroundColor = builder.backgroundColor;
chipView.mChip = builder.chip;
chipView.inflateWithAttributes();

return chipView;
}
}
Loading