Wrong suggestions order on restore instance state #263
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
onSaveInstanceState
is called, the suggestions list is saved reversed, not as it has been delivered to theFloatingSearchView
throughswapSuggestions
. Then, when the view is restored from instance staterestoreFromInstanceState
, the suggestions are reversed, and when they are delivered again toswapSuggestions
the 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:51
from: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