cardslib
cardslib copied to clipboard
Track updates to underlying list in mInternalObjects on notifyDataSetChanged().
When working on my project, I realized that this important piece was missing to my previous pull request. If the list that the CardArrayAdapter is referencing is modified outside of the adapter and notifyDataSetChanged() is called, mInternalObjects will be in an incorrect state. This can completely break the undo functionality.
The solution is to totally regenerate mInternalObjects when notifyDataSetChanged is called, since we have no guarantee what state the ArrayList is in anymore. Using notifyDataSetChanged is a relatively common workflow, so this should be patched.
True, but this kind of solution can have a performance issue if the adapter has a lot of items. I have to study this case.
Yes, that is true that the performance will suffer with many items. However, this is necessary since in the worst case the elements in the ArrayList could be completely different than before.
I still think this commit is necessary, but realized that it caused undo to become non-functional. I have fixed this properly in a57aa8bbefca0276ec1c6a0bf4fd35d58a547e64. The behavior is now what I expect it to be.