cardslib icon indicating copy to clipboard operation
cardslib copied to clipboard

Track updates to underlying list in mInternalObjects on notifyDataSetChanged().

Open mattgmg1990 opened this issue 10 years ago • 3 comments

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.

mattgmg1990 avatar Sep 22 '14 19:09 mattgmg1990

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.

gabrielemariotti avatar Sep 22 '14 20:09 gabrielemariotti

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.

mattgmg1990 avatar Sep 22 '14 22:09 mattgmg1990

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.

mattgmg1990 avatar Sep 24 '14 23:09 mattgmg1990