Migrated SearchFragment -> Search Composable#4703
Migrated SearchFragment -> Search Composable#4703atharvyadav22 wants to merge 4 commits intokiwix:mainfrom
Conversation
|
@MohitMaliFtechiz @gouri-panda |
MohitMaliFtechiz
left a comment
There was a problem hiding this comment.
What is this SEARCH text here? It is making the UI very odd. If you are talking about the voice feature of search. It should not be like this. There should be a mic icon instead of this text. It's confusing the user here.
- The second issue is when we open any item in the reader by clicking the searched item. Then again, open the searchScreen, that item is not showing(in the previous code that shows). But, if I searched for anything and removed the query from searchBox then those items show that we have opened in a previous search.
| val context = LocalActivity.current | ||
| val coreMainActivity = context as CoreMainActivity | ||
|
|
||
| SearchContainer( |
There was a problem hiding this comment.
The name should be SearchScreenRoute.
| ): FragmentActivityExtensions.Super { | ||
| pendingIntent = intent | ||
|
|
||
| if (!isWebViewHistoryRestoring) { |
There was a problem hiding this comment.
Why are we adding this here? It has no effect here. Because when the onNewIntent runs, then isWebViewHistoryRestoring will always be true, so this condition will never run. Also, we are storing the intent in pendingIntent which will run after the history is restored.
There was a problem hiding this comment.
Okay see for that issue no #4662 whats was happening earlier when we did OnSearch Kiwix it was immediately cancelling intent actions here we had 2 possible ways which kiwix should pass intent one was outside the app and other within reader screen
There was a problem hiding this comment.
I don't think that this code #4662 will fix. The search travel is a different issue.
The search travel is only possible in the visible area of the EditTextView.
There was a problem hiding this comment.
Ops looks like an mistake sorry that fix is for different purpose i didn't raise an Issue for that. actually that SearchKiwix didn't work when in readerScreen that fix is for it sorry for that i referenced it with wrong one.
| actionMenuItemList: List<ActionMenuItem>, | ||
| isLoadingMoreResult: Boolean | ||
| isLoadingMoreResult: Boolean, | ||
| lazyListState: LazyListState |
There was a problem hiding this comment.
Why are we passing this from the outside? What is the use of this there?
There was a problem hiding this comment.
pagination was affected and i thought it was recomposing so i changed but later realized my code was not the issue left to revert it thanks for pointing
| lazyListState = listState | ||
| ) | ||
|
|
||
| DialogHost(dialogShower as AlertDialogShower) |
There was a problem hiding this comment.
We don't need to set this here, as we already set the DialogHost in mainActivity for this dialogShower.
There was a problem hiding this comment.
okay as Fragment had it so i added up ill revert it
| val showFindInPage by viewModel.showFindInPage.collectAsStateWithLifecycle(initialValue = false) | ||
|
|
||
| // Handles SideEffects | ||
| LaunchedEffect(viewModel) { |
There was a problem hiding this comment.
The key should not be viewModel since it only needs to be attached once. Use the CollectSideEffectWithActivity instead of this.
|
|
||
| SearchScreen( | ||
| screenState, | ||
| listOfNotNull( |
There was a problem hiding this comment.
We should split this into a function that returns the actionMenuList.
| ) | ||
| ).isSuccess | ||
| _effects.trySend(ShowToast(R.string.delete_specific_search_toast)).isSuccess | ||
| DeleteRecentSearch(it.searchListItem, recentSearchRoomDao, viewModelScope) |
There was a problem hiding this comment.
When I am deleting the SearchedItem, then the toast shows the success of deleting. But the item remains shown on the screen.
| .collect { | ||
| state.value = it | ||
|
|
||
| if (it.searchTerm != lastQuery && !_isLoadingMore.value) { |
There was a problem hiding this comment.
Why are we checking it.searchTerm != lastQuery when we are using the distinctUntilChanged?
There was a problem hiding this comment.
yes actually when i migrated i thought pagination and other stuff like read was affected by this reason so i was checking and i left mistakenly there bad code thanks for pointing.
|
@atharvyadav22 Please rebase this PR as well with the review changes. |
I'll also add that test coverage here should i reference this PR? or only work for migration and create new issue for it. |
|
@atharvyadav22 One ticket/PR per thing. First we should atleast achive the existing fucntionality and than we should add testing. Migration is a different thing, and code coverage is different. Doing both together can introduce regressions here. |
|
@atharvyadav22 Mark all your PRs along with this one, as draft, on which work is currently in progress. |
235968a to
08177e5
Compare
|
@MohitMaliFtechiz @kelson42 Could you verify if there are any more functionalities other than these? as we have seen migration have caused us an trouble with many functionality.
|
|
@MohitMaliFtechiz we have Fragment Tests too what do with them now ? |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4703 +/- ##
============================================
- Coverage 60.70% 60.34% -0.36%
+ Complexity 1625 1588 -37
============================================
Files 330 330
Lines 15726 15668 -58
Branches 2162 2158 -4
============================================
- Hits 9546 9455 -91
- Misses 4724 4759 +35
+ Partials 1456 1454 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
They are not for testing the fragment. They are for testing the functionality of that screen. We should rename the test cases, as now we have composables, not fragments. |
There is one more functionality where we can directly search from browsers as well via the
|
|
Yes i have already covered that too mentioned it in description as it was also an Issue it now works for both within and and outside the app |
Okay now it should be aligned with SearchScreenRoutes right? so should i raise an another PR for it as you said tests are different |
|
@atharvyadav22 Renaming the test cases should happen here. Since we are migrating to composables, related to that should be improved here. |
I thought we should add tests too got confused. |
@atharvyadav22 If you have found something that needs to be improved in testing for the current migration screen. Then you can add test cases for that in your current PR. @harshsomankar123-tech did this in his PRs. You can take reference from his PRs. But no unrelated changes should be made in PRs. |
f4c42ee to
9c8bb31
Compare
|
@atharvyadav22 Thank you for making the changes. I will review this shortly :) |
MohitMaliFtechiz
left a comment
There was a problem hiding this comment.
@atharvyadav22, I don't understand why we are always changing the UI behaviour when this PR is just for removing the fragment and migrating it to pure composables.
Here FIND_IN_PAGE option is not visible when there is no word typed. We already have a ticket for this #1782. But this type of UI change made the review harder(needs more testing/caring, and they have no effect. It only takes a long time to merge any PR).
| } | ||
|
|
||
| // Search Results | ||
| LaunchedEffect(viewModel) { |
There was a problem hiding this comment.
My previous comment has not been taken. Here we should use Unit instead of viewModel. However, the viewModel will not change, but it is not ideal to use the viewModel as a key here. Because it only requires once, so it should be Unit. In the future, it might be possible that the viewModel is changed due to some condition.
There was a problem hiding this comment.
okay i'll keep in mind like i assumed that ViewModel() is attached with lifecycle so it wont change but i agree with you.
| showFindInPage: Boolean | ||
| ): List<ActionMenuItem> { | ||
| return listOfNotNull( | ||
| ActionMenuItem( |
There was a problem hiding this comment.
I appreciate this one, that you have found this issue, and placed a fix for it 👏 .
| navigationIcon = { | ||
| NavigationIcon( | ||
| onClick = { | ||
| coreMainActivity.onBackPressedDispatcher.onBackPressed() |
There was a problem hiding this comment.
The keyboard is closing after the reader screen is visible in my Google Pixel 7a. But the keyboard is not closing in the emualtor. So I guess my device autoamtically handling the keyboard hiding. We should hide the keyboard first if the navigation icon is clicked. Because it is taking us to the reader screen, which is not an ideal UX.
- When the user presses the device back button then first keyboard hides, and on the second back pressed screen comes to the reader. This is the ideal UX for a user. We should keep this same for navigationIcon click.
There was a problem hiding this comment.
Okay as i only tested it one Real Device i'll keep that in mind.
| val firstPage = it.getVisibleResults(0).orEmpty() | ||
| _visibleResults.value = firstPage | ||
|
|
||
| if (it.searchTerm.isNotBlank()) { |
There was a problem hiding this comment.
This is a huge memory consumption code. It everytime ask to libkiwix to give suggestions; however, the result already exists. The suggestion API is just for giving suggestions if the search API did not return a result.
If you see the fragment code, it is clearly mentioned there.
There was a problem hiding this comment.
Okay i'll update 👍
| ): FragmentActivityExtensions.Super { | ||
| pendingIntent = intent | ||
|
|
||
| if (!isWebViewHistoryRestoring) { |
There was a problem hiding this comment.
I don't think that this code #4662 will fix. The search travel is a different issue.
The search travel is only possible in the visible area of the EditTextView.
| } | ||
|
|
||
| suspend fun getSuggestedSpelledWords(word: String, maxCount: Int): List<String> = | ||
| private fun getSuggestedSpelledWords(word: String, maxCount: Int): List<String> = |
There was a problem hiding this comment.
This operation should not be performed on the main thread, so it should be suspend function to make its usage clear.

Fixes: #4616 - Migrated Search Fragment to Pure Composable with basic test functionality.
Fixes: #4662 - Search keyword travel was broke due to Fragment lifecycle error and intent action issue.
It now works Within app and also outside the app
Fixes #4722
WhatsApp.Video.2026-02-18.at.9.09.27.PM.1.mp4
Fixes: #4702 - Voice to Search was broken due to Regression and Fragment changes.
WhatsApp.Video.2026-02-18.at.9.09.27.PM.mp4
Fixes: #4722 - Fixed Keyboard not closing when back button press on search screen.
WhatsApp.Video.2026-02-26.at.9.51.05.PM.mp4