splitwise / TokenAutoComplete

Gmail style MultiAutoCompleteTextView for Android
Apache License 2.0
1.3k stars 383 forks source link

Added custom contain method (example: check duplicate by id) #364

Closed dragossusi closed 5 years ago

dragossusi commented 6 years ago

I moved the objects.contain in a separate method so you can override it and do your custom contain check. If you have tokens with the same name but different ids and want to avoid duplicates, this helps.

mgod commented 6 years ago

I'm pretty worried about changing the semantics here as you're not explicitly dealing with the fact that we depend on the behavior of the equals method in other places in the internal implementation and this exposes the idea that someone who uses the library can change the meaning of containing a token even though that's not exactly what this does.

I'd be much more inclined to add a new protected method called shouldIgnoreToken (maybe isTokenAddable?), similar to the isTokenRemovable, that returns false by default and remove the allowDuplicates flag entirely. We'd also want to update the TokenListener to rename onDuplicateRemoved to onTokenIgnored.

I'm about to wrap up the 3.0 release, which will have a bunch of breaking changes, so it's a good time to make this switch if it would resolve the problem for you without adding a method to the API that could cause confusing expectations for users of this library.

mgod commented 5 years ago

Version 3.0.0 now includes an overridable shouldIgnoreToken method and onTokenIgnored callback.