Wrong suggestions order on restore instance state#263
Open
eduardbosch wants to merge 2 commits into
Open
Conversation
View must save the suggestions list in the original order so when it's restored, the data is shown in the correct order as when we call swapSuggestions.
eduardbosch
commented
Jul 20, 2017
|
|
||
| savedState.suggestions = mSuggestionsAdapter.getDataSet(); | ||
| if (mSuggestionsAdapter.isReversed()) { | ||
| Collections.reverse(savedState.suggestions); |
Author
There was a problem hiding this comment.
This introduced a bug that caused that when device moves the Activity to background, the suggestions list is reversed. Then, the suggestion adapter does not repaint the suggestions, so when the activity return to foreground, if the user selects the first element, the adapter returns that the last one was clicked.
You can check this bug deactivating this option:

If the Activity is destroyed, it is restored from instance state, so everything was ok.
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.
Hi again 🎉
I've found another problem with suggestions order when the suggestions list has been reversed and the view is restored from instance state.
The problem
When the suggestions list is reversed and
onSaveInstanceStateis called, the suggestions list is saved reversed, not as it has been delivered to theFloatingSearchViewthroughswapSuggestions. Then, when the view is restored from instance staterestoreFromInstanceState, the suggestions are reversed, and when they are delivered again toswapSuggestionsthe list is reversed again, so we end up with the results in reversed order.The solution
If the suggestions list is reversed, then we reverse it again before saving on
onSaveInstanceState.Test
To test this, I had to change in
MainActivity:51from:showFragment(new SlidingSearchResultsExampleFragment());to:
so the fragment is not created every time the Activity is destroyed if we are recovering from a previous instance. You should activate this option also in the developer settings to check restoring from instance state:
Before the fix
After the fix