-
Notifications
You must be signed in to change notification settings - Fork 88
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 onChipAddListener #76
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,6 +150,8 @@ public class NachoTextView extends MultiAutoCompleteTextView implements TextWatc | |
|
||
// Text entry | ||
@Nullable | ||
private OnChipAddListener onChipAddListener; | ||
@Nullable | ||
private ChipTokenizer mChipTokenizer; | ||
@Nullable | ||
private ChipTerminatorHandler mChipTerminatorHandler; | ||
|
@@ -402,6 +404,13 @@ public void setChipTokenizer(@Nullable ChipTokenizer chipTokenizer) { | |
invalidateChips(); | ||
} | ||
|
||
public void setOnChipAddListener(@Nullable OnChipAddListener onChipAddListener) { | ||
this.onChipAddListener = onChipAddListener; | ||
if (mChipTerminatorHandler != null) { | ||
mChipTerminatorHandler.setChipAddListener(this.onChipAddListener); | ||
} | ||
} | ||
|
||
public void setOnChipClickListener(@Nullable OnChipClickListener onChipClickListener) { | ||
mOnChipClickListener = onChipClickListener; | ||
} | ||
|
@@ -796,6 +805,9 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon | |
|
||
editable.replace(start, end, mChipTokenizer.terminateToken(text, data)); | ||
|
||
if (onChipAddListener != null){ | ||
onChipAddListener.onChipAdded(getAllChips().get(getAllChips().size()-1)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remember to format your code with Android Studio's code formatting. The |
||
} | ||
endUnwatchedTextChange(); | ||
} | ||
|
||
|
@@ -1127,4 +1139,8 @@ public boolean onSingleTapUp(MotionEvent e) { | |
return true; | ||
} | ||
} | ||
|
||
public interface OnChipAddListener { | ||
void onChipAdded(Chip chip); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide the documentation and contract of when and what the |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,17 @@ | |
import android.support.annotation.Nullable; | ||
import android.text.Editable; | ||
|
||
import com.hootsuite.nachos.NachoTextView; | ||
import com.hootsuite.nachos.chip.Chip; | ||
import com.hootsuite.nachos.tokenizer.ChipTokenizer; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class DefaultChipTerminatorHandler implements ChipTerminatorHandler { | ||
|
||
private NachoTextView.OnChipAddListener mOnChipAddListener; | ||
|
||
@Nullable | ||
private Map<Character, Integer> mChipTerminators; | ||
private int mPasteBehavior = BEHAVIOR_CHIPIFY_TO_TERMINATOR; | ||
|
@@ -53,12 +57,28 @@ public int findAndHandleChipTerminators(@NonNull ChipTokenizer tokenizer, @NonNu | |
switch (behavior) { | ||
case BEHAVIOR_CHIPIFY_ALL: | ||
selectionIndex = handleChipifyAll(textIterator, tokenizer); | ||
if (mOnChipAddListener != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @harhsoni1110 it seems that these 3 blocks do the same thing. Why not put it into a private method? |
||
Chip[] chips = tokenizer.findAllChips(0, text.length(), text); | ||
if (chips.length > 0) | ||
mOnChipAddListener.onChipAdded(chips[chips.length - 1]); | ||
} | ||
break characterLoop; | ||
case BEHAVIOR_CHIPIFY_CURRENT_TOKEN: | ||
newSelection = handleChipifyCurrentToken(textIterator, tokenizer); | ||
if (mOnChipAddListener != null) { | ||
Chip[] chips = tokenizer.findAllChips(0, text.length(), text); | ||
if (chips.length > 0) | ||
mOnChipAddListener.onChipAdded(chips[chips.length - 1]); | ||
} | ||
|
||
break; | ||
case BEHAVIOR_CHIPIFY_TO_TERMINATOR: | ||
newSelection = handleChipifyToTerminator(textIterator, tokenizer); | ||
if (mOnChipAddListener != null) { | ||
Chip[] chips = tokenizer.findAllChips(0, text.length(), text); | ||
if (chips.length > 0) | ||
mOnChipAddListener.onChipAdded(chips[chips.length - 1]); | ||
} | ||
break; | ||
} | ||
|
||
|
@@ -111,4 +131,9 @@ private int handleChipifyToTerminator(TextIterator textIterator, ChipTokenizer t | |
private boolean isChipTerminator(char character) { | ||
return mChipTerminators != null && mChipTerminators.keySet().contains(character); | ||
} | ||
|
||
@Override | ||
public void setChipAddListener(NachoTextView.OnChipAddListener onChipAddListener) { | ||
this.mOnChipAddListener = onChipAddListener; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need a |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to stay consistent, please use
mOnChipAddListener