splitwise / TokenAutoComplete

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

When adding any token from onTokenRemoved callback method, the added token also gets removed #378

Closed maheshwariaanchal closed 5 years ago

maheshwariaanchal commented 5 years ago

Hello, When I remove any token by clicking cross image of the token, the callback method "onTokenRemoved" is called. Its working fine till here. Now in that method(onTokenRemoved) I am adding another token using method "MyCompletionView.addObjectAsync(list.get(0));" This is the last line of that method. No more lines are there to be executed. Whenever the token is added callbacks goes to "onTokenAdded" and after that the callback automatically again goes to "OnTokenRemoved" method, it executes from the very first line of that method for the newly added token and the newly added token is removed.

Please help. Its pretty urgent. Thanks in advance.

mgod commented 5 years ago

Can you give me some more details on what you're actually trying to accomplish in the UI? Are you able to reproduce the issue with the sample project?

I can only imaging this happening if you are adding the same object that got removed, but I can't figure out how to reproduce this myself.

maheshwariaanchal commented 5 years ago

Hi, Thanks for the reply. Actually what I am trying to do is, I have a list of items and they can be multiselected or deselected. So when I select some items from the list I show only the first selected item in completion view and write (+5 more, depending on the number of items selected) in front of that item. Now if the item which is shown in completion view is deselected by the user, I remove that item from the completion view and add one selected item from the remaining selected item list.

So while doing so the callback method "onTokenRemoved" is called when removing the item. At the same time when the call arrives in "onTokenRemoved" method, I add one token from the remaining selected items using the method MyCompletionView.addObjectSync(list.get(0)). Now the callback method "onTokenAdded" is called. And from there "onTokenRemoved" is automatically for the newly added item.

However If I add token after some delay (around 3 sec), its working fine and the callback is not going to "onTokenRemoved" for the added token.

I have not reproduced it on the sample project.

Thanks.

mgod commented 5 years ago

It seems like that should work without the delay, but I might also try a different approach. I haven't updated the docs for this yet, but I don't expect these interfaces to change at this point. I would override shouldIgnoreToken and return true if the user is selecting an item in the list that is already in the view. When this happens, the onTokenIgnored listener callback will fire and I would then remove the token from the view and add the new random token. This might avoid the callback cycle you're currently stuck in.

maheshwariaanchal commented 5 years ago

Thanks again. Sorry for the late reply. I didn't exactly get what you are trying to say. But I am still working on it. I have provided some delay when adding token and its working fine. I am still looking for some workaround. Please let me know if you get any solution for this. Thanks

mgod commented 5 years ago

I've updated the docs for version 3.0.0, which might make my suggestion more clear.

mgod commented 5 years ago

Actually, on looking this over, I think this might be resolved by 3.0.0. Can you try it and let me know if you're still seeing the issue?