Skip to content

Commit

Permalink
BaseViewHolder:
Browse files Browse the repository at this point in the history
1, 优化颜色设置方式, 由颜色值改为资源ID
EdtLinkBtnUtil:
1, 新增, 根据EditText内容长度控制Button按钮Enable状态
  • Loading branch information
zuilintan committed Jun 15, 2020
1 parent 2a13bdf commit 1a200cc
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 5 deletions.
18 changes: 13 additions & 5 deletions library/src/main/java/com/lt/library/base/BaseViewHolder.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.lt.library.base;

import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lt.library.util.context.ContextUtil;

import java.util.Objects;

/**
Expand Down Expand Up @@ -63,9 +66,14 @@ public void setTextSize(int viewId, float size) {
view.setTextSize(size);
}//设置文本大小

public void setTextColor(int viewId, @ColorInt int colorInt) {
public void setTextColor(int viewId, @ColorRes int resId) {
TextView view = findViewById(viewId);
view.setTextColor(ContextCompat.getColor(ContextUtil.getInstance().getContext(), resId));
}//设置文本颜色

public void setTextColorStateList(int viewId, @ColorRes int resId) {
TextView view = findViewById(viewId);
view.setTextColor(colorInt);
view.setTextColor(ContextCompat.getColorStateList(ContextUtil.getInstance().getContext(), resId));
}//设置文本颜色

public void setImageDrawable(int viewId, @Nullable Drawable drawable) {
Expand All @@ -88,9 +96,9 @@ public void setBackgroundResource(int viewId, @DrawableRes int resId) {
view.setBackgroundResource(resId);
}//设置背景资源

public void setBackgroundColor(int viewId, @ColorInt int colorInt) {
public void setBackgroundColor(int viewId, @ColorRes int resId) {
View view = findViewById(viewId);
view.setBackgroundColor(colorInt);
view.setBackgroundColor(ContextCompat.getColor(ContextUtil.getInstance().getContext(), resId));
}//设置背景颜色

public void setVisibility(int viewId, int visibility) {
Expand Down
79 changes: 79 additions & 0 deletions library/src/main/java/com/lt/library/util/EdtLinkBtnUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.lt.library.util;

import android.text.Editable;
import android.text.TextWatcher;
import android.util.ArrayMap;
import android.widget.Button;
import android.widget.EditText;

import java.util.Map;

public class EdtLinkBtnUtil implements TextWatcher {
private ArrayMap<EditText, Integer> mEditTextMap;
private Button mButton;

private EdtLinkBtnUtil() {
mEditTextMap = new ArrayMap<>();
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}

@Override
public void afterTextChanged(Editable s) {
boolean isEnable = false;
for (Map.Entry<EditText, Integer> entry : mEditTextMap.entrySet()) {
EditText edt = entry.getKey();
Integer btnEnableLength = entry.getValue();
if (edt.getText().length() < btnEnableLength) {
isEnable = false;
break;
} else {
isEnable = true;
}
}
mButton.setEnabled(isEnable);
}

public void addEvent() {
for (Map.Entry<EditText, Integer> entry : mEditTextMap.entrySet()) {
EditText editText = entry.getKey();
editText.addTextChangedListener(this);
}
}

public void delEvent() {
for (Map.Entry<EditText, Integer> entry : mEditTextMap.entrySet()) {
EditText editText = entry.getKey();
editText.removeTextChangedListener(this);
}
}

public static class Builder {
private EdtLinkBtnUtil mEdtLinkBtnUtil;

public Builder() {
mEdtLinkBtnUtil = new EdtLinkBtnUtil();
}

public Builder addEditText(EditText editText, int btnEnableLength) {
mEdtLinkBtnUtil.mEditTextMap.put(editText, btnEnableLength);
return this;
}

public Builder setButton(Button button) {
mEdtLinkBtnUtil.mButton = button;
mEdtLinkBtnUtil.mButton.setEnabled(false);
return this;
}

public EdtLinkBtnUtil build() {
return mEdtLinkBtnUtil;
}
}
}

0 comments on commit 1a200cc

Please sign in to comment.