-
-
Notifications
You must be signed in to change notification settings - Fork 38
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed UI State Loss In BrainzPlayerSearchScreen #534
Fixed UI State Loss In BrainzPlayerSearchScreen #534
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rahul31124, thanks for picking this up. You hit the correct spot by using view-model to preserve state!! But, there are better ways to do this task for which I have left comments in the review itself :)
onQueryChange = { newValue: String -> | ||
val updatedQuery = TextFieldValue(newValue, selection = brainzplayerQueryState.selection) | ||
viewModel.updateSearchQuery(updatedQuery) | ||
viewModel.searchSongs(newValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, we should not call this search function here itself, but in the view-model. We want to debounce this request by about 100-200 millisecs (since its local search, otherwise we prefer 500 when network calls are required). Please take inspiration from the following line:
listenbrainz-android/app/src/main/java/org/listenbrainz/android/viewmodel/SearchViewModel.kt
Line 40 in de22834
private val queryFlow = inputQueryFlow.asStateFlow().debounce(500).distinctUntilChanged() |
You can go through SearchViewModel.kt to derive your logic for searching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @07jasjeet ,
I have refactored the BrainzPlayerViewModel and BrainzPlayerSearchScreen as per the guidance,could you please review and let me know if everything looks good?
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Great work!
@rahul31124 Thanks for the contribution! |
This PR resolves the issue of UI state loss in BrainzPlayerSearchScreen during screen orientation changes. Previously, the search query and UI state were reset when the screen rotated. This issue has been fixed by introducing state retention in BrainzPlayerViewModel and ensuring that the UI state, including the search query and results, is preserved across orientation changes.
Before
Orientation_Before.mp4
After
Orientation_After.mp4