Skip to content

fix(search): keep search state across rotation - #2907

Open
jpcmpc123 wants to merge 2 commits into
maxrave-dev:devfrom
jpcmpc123:fix/2711-search-results-rotation
Open

jpcmpc123 wants to merge 2 commits into
maxrave-dev:devfrom
jpcmpc123:fix/2711-search-results-rotation

Conversation

@jpcmpc123

Copy link
Copy Markdown

What & why

Rotating the device on the search screen lost everything: submitted results were replaced by "No Result Found", and suggestions never came back — only the query text was restored.

MainActivity did not declare orientation in android:configChanges, so every rotation recreated the activity, and the in-memory search state (held by SearchViewModel) went with it on memory-tight devices.

Changes:

  • AndroidManifest.xml: MainActivity now handles orientation config changes, so rotation no longer recreates the activity — results, suggestions and scroll position stay as they are, with no reload.
  • SearchScreen.kt (safety net): if the screen is still restored with a submitted query but an Empty UI state, it re-runs the submitted search (same dispatch as pull-to-refresh); if it is restored on the suggestions branch, unfocused, with a restored query and no suggestions, it re-runs the suggestion fetch once. A search that completed — even with zero results — leaves a Success state, so neither net can loop.

Linked issue

Closes #2711

Checklist

  • This PR addresses an accepted issue (linked above)
  • I wrote or personally reviewed every line of this change
  • I tested it on Android and/or Desktop (say which, and how)

Tested on Android (Galaxy M32, build from this branch): submit a search and rotate — results stay, no loading, scroll position kept; type without submitting and rotate — suggestions stay; rotated Home, Library and the player screen too, with no regressions.

Rotating the device recreates the activity, and the search screen can
come back restored (submitted query, results branch) while the search
state behind it is back at Empty with no results, so the results branch
only shows "No Result Found" and nothing re-runs the search.

Re-run the submitted search once when the screen is showing results
for a submitted query but the UI state is Empty. A finished search
leaves the state at Success (even with zero results) and a new submit
goes through Loading first, so this cannot loop or double-fire.

Refs maxrave-dev#2711
MainActivity did not handle orientation changes, so rotating recreated
the activity; on memory-tight devices the whole app state went with it
and only the saved query/flags came back — results and suggestions were
lost. Two layers:

- AndroidManifest: MainActivity now handles orientation config changes,
  so rotation no longer recreates the activity and nothing is lost.
- SearchScreen safety net: if the screen still comes back restored with
  a submitted query but an Empty UI state, re-run the submitted search;
  if it comes back on the suggestions branch, unfocused, with a restored
  query and no suggestions, re-run the suggestion fetch once.

Refs maxrave-dev#2711
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.

Search results disappear after screen rotation (“No Result Found” shown)

1 participant