arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 667 forks source link

Wrong suggestions order on restore instance state #263

Open eduardbosch opened 7 years ago

eduardbosch commented 7 years ago

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