Skip to content

Conversation

@eduardbosch
Copy link

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 the FloatingSearchView through swapSuggestions. Then, when the view is restored from instance state restoreFromInstanceState, the suggestions are reversed, and when they are delivered again to swapSuggestions 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:

        if (savedInstanceState == null) {
            showFragment(new SlidingSearchResultsExampleFragment());
        }

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:

dont_keep_activities

Before the fix

wrong_order

After the fix

correct_order

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.

savedState.suggestions = mSuggestionsAdapter.getDataSet();
if (mSuggestionsAdapter.isReversed()) {
Collections.reverse(savedState.suggestions);
Copy link
Author

@eduardbosch eduardbosch Jul 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
dont_keep_activities

If the Activity is destroyed, it is restored from instance state, so everything was ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant