Track updates to underlying list in mInternalObjects on notifyDataSetChanged().#304
Open
mattgmg1990 wants to merge 2 commits intogabrielemariotti:devfrom
Open
Track updates to underlying list in mInternalObjects on notifyDataSetChanged().#304mattgmg1990 wants to merge 2 commits intogabrielemariotti:devfrom
mattgmg1990 wants to merge 2 commits intogabrielemariotti:devfrom
Conversation
If the list is modified outside of the CardArrayAdapter, re-generate mInternalObjects in notifyDataSetChanged(), as it's contents are now stale. Change-Id: I5bc6879970fbc1d8debc21d6dd0a8b8185ab2b30
Owner
|
True, but this kind of solution can have a performance issue if the adapter has a lot of items. |
Contributor
Author
|
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. |
In CardArrayAdapter, notifyDataSetChanged() will now rebuild mInternalObjects from the current list contents. However, this will discard removed cards unless they are added back in upon swiping. Fix this bug by adding removed cards back in. Change-Id: Ib836fc8773b7a087090760e119094d2decc1ecf6
Contributor
Author
|
I still think this commit is necessary, but realized that it caused undo to become non-functional. I have fixed this properly in a57aa8b. The behavior is now what I expect it to be. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.