splitwise / TokenAutoComplete

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

Add token after text #345

Closed NikolayKul closed 6 years ago

NikolayKul commented 6 years ago

All tokens are added one by one at the start of the view. How can I add a token after text?

mgod commented 6 years ago

At the moment, this isn't supported by the library. Can you give me some more details on your use case?

NikolayKul commented 6 years ago

I have something similar to your example with emails. I also want to allow users edit those emails wapped into Tokens. So when a user clicks on a Token the latter should replace itself with a simple text it contains. I tried to achieve that this way:

  1. Set TokenClickStyle.SelectDeselect
  2. Use custom TextView with a cb on setSelected
  3. Handle onClick: clear editable, reinsert all Tokens one by one. If a Token equals SelectedToken then insert text that SelectedToken represents (an email). And insert old currentCompletionText at the end.

But all Tokens are grouped together at the start of the view.

mgod commented 6 years ago

At the moment, tokens are inserted asynchronously on the main thread, which is probably what's causing trouble for you. I'm intending to change this behavior in the next version, but I'm still in the middle of re-working the view for that and I'm not sure when that will be ready. I'm not planning to add a replace object method at the moment, but it's probably something I'd consider.

I do something similar in the Splitwise app and the approach that I took was to remove the object, show an alert to edit the information, then add the new object when the user finished editing. This doesn't keep the order intact, but seems to work pretty well. Editing in place does seem more elegant.