Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong suggestions order on restore instance state #263

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

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.
@@ -1814,7 +1814,8 @@ public Parcelable onSaveInstanceState() {

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

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.

None yet

1 participant