Android icon indicating copy to clipboard operation
Android copied to clipboard

#1962: Refactoring of Search Behavior: Restoring of Previous Search Query After Coming Back from Card Interaction or Screen Rotation on Search

Open vp193dt opened this issue 4 months ago • 4 comments

Hello, In this pull request, I implemented functionality to save and restore the user's search query during screen rotations and enhance the user experience when navigating back from a selected card, the way user will have the query entered before saved and retrived, based on Issue #1962. Unit tests were added and all four possible tests were run successfully without any error.

After hours of debugging I figured out the only way this Issue is solveble, where we need to implement 2 Strings to handle the changing text as input from user, because of the behaviour after coming back from a card regarding onQueryTextChange. (alternativelly we could use one string and one boolean for this very same behaviour) - changes in states were not effective on this Issue. This approach is a bit extraordinary but It solves both parts of problem of this Issue.

The changes are divided into 2 categories, the first are changes that are connected to screen rotation:

Saving Instance State:

I overridden the onSaveInstanceState method. When a user clicks on a card from the list, the current search query (currentQuery) is saved to a variable called finalQuery. This finalQuery is then stored in the outState bundle, allowing it to be retained even when the screen is rotated.

Restoring Instance State:

The onRestoreInstanceState method is also overridden to retrieve the saved query when the screen is rotated. If the savedInstanceState is not null, the stored search query is fetched and assigned to finalQuery. Finally, if mSearchView is available, the restored query is set in the search view, allowing users to see their previous search term after rotation.

The second part regarding the retrieving the text after coming back from card picking:

New Logic for Search History:

Additional logic was implemented to ensure that the user sees the last search query after returning from a picked card. If the newText input is empty, the app checks if finalQuery is not empty. If so, it sets the query text to finalQuery for the user. If both finalQuery and currentQuery are empty, the app clears the current search (currentQuery = "") and resets the search view to show all cards. When the user changes the text in the search view, the input is stored in currentQuery to be used later for restoring search history.

Handling Navigation from a Picked Card:

Upon returning from a picked card, if finalQuery is not empty, the search view is expanded to show the previous query. The finalQuery is reset to an empty string to avoid unintended behavior caused by the onQueryTextChange method, which is called automatically after returning to the search view.

Tests are focused on both rotation of screen by user (testing same test case as in previous unit test but with rotation commands) and also on simulating steps of the core of the issue with coming back from a card.

Thank you for feedback. Have a nice day :)

vp193dt avatar Sep 30 '24 20:09 vp193dt