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

Add tag click call back event. #17

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Just use it to edit tags like EditText edit text.
* Set input tag enable ```setEditable(true)```
* Add a tag ```addTag(String tagContent)```
* Remove tag: ```removeTag(String... tagValue)```
* Set Tag data changed callback: ```setTagAddCallBack(TagAddCallback tagAddCallBack)``` and ```setTagDeletedCallback(TagDeletedCallback tagDeletedCallback)```
* Set Tag data changed callback: ```setTagAddCallBack(TagAddCallback tagAddCallBack)```, ```setTagDeletedCallback(TagDeletedCallback tagDeletedCallback)```, and ```setTagClickCallback(TagClickCallBack tagClickCallback)```
* ⚠ When you custom input_layout layout, please use ```MEditText``` replaced ```EditText```, in order to avoid some of the soft keyboard can not receive the delete action event

### Todo
Expand Down
21 changes: 21 additions & 0 deletions library/src/main/java/me/originqiu/library/EditTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class EditTag extends FrameLayout

private TagDeletedCallback tagDeletedCallback;

private TagClickCallBack tagClickCallBack;

public interface TagAddCallback {
/*
* Called when add a tag
Expand All @@ -86,6 +88,15 @@ public interface TagDeletedCallback {
void onTagDelete(String deletedTagValue);
}

public interface TagClickCallBack {

/**
* Called when tag is clicked
* @param tagValue the tag value to be send to listeners.
*/
void onTagClick(String tagValue);
}

public EditTag(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -192,6 +203,11 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

@Override
public void onClick(View view) {

if(view instanceof TextView && view.getTag(R.id.TV_TAG_ID) != null && tagClickCallBack != null) {
tagClickCallBack.onTagClick(((TextView)view).getText().toString());
}

if (view.getTag() == null && isEditableStatus) {
// TextView tag click
if (lastSelectTagView == null) {
Expand Down Expand Up @@ -285,6 +301,7 @@ public boolean addTag(String tagContent) {
defaultTagBg = tagTextView.getBackground();
}
tagTextView.setOnClickListener(EditTag.this);
tagTextView.setTag(R.id.TV_TAG_ID,tagContent);
if (isEditableStatus) {
flowLayout.addView(tagTextView, flowLayout.getChildCount() - 1);
} else {
Expand Down Expand Up @@ -318,6 +335,10 @@ public void setTagDeletedCallback(TagDeletedCallback tagDeletedCallback) {
this.tagDeletedCallback = tagDeletedCallback;
}

public void setTagClickCallback(TagClickCallBack tagClickCallback) {
this.tagClickCallBack = tagClickCallback;
}

/*
* Remove tag view by value
* warning: this method will remove tags which has the same value
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/res/values/tags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="TV_TAG_ID" type="id"/>
</resources>