Skip to content

Migrated ZimHostFragment -> ZimHostRoute#4736

Draft
atharvyadav22 wants to merge 7 commits intokiwix:mainfrom
atharvyadav22:migrate/zim
Draft

Migrated ZimHostFragment -> ZimHostRoute#4736
atharvyadav22 wants to merge 7 commits intokiwix:mainfrom
atharvyadav22:migrate/zim

Conversation

@atharvyadav22
Copy link
Copy Markdown
Contributor

Fixes: #4615

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@MohitMaliFtechiz
Sorry for the delay and not able to contribute in other Prs i was prioritizing this migration it was difficult because of many classes which required understanding.
This is an initial commit ill later add test cases too for now please review the logic.

I have added comments to help other read the code, also from previous migration i have implemented your points so it saves time.

Migration covered these parts-

  • Hotspot now use composable lifecycle
  • Merged Di and common fragment files and updated in ViewModel itself
  • Handled Playstore and custom apps logic
  • Permission block kept the same
  • Instead of suppressing i made small code blocks.
  • for the checkbox i modified the logic cause it wasn't updating its state with toggleSelection.

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@MohitMaliFtechiz Done with this migration waiting for your reviews.

Copy link
Copy Markdown
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atharvyadav22 Please see the review changes. If anything is unclear, please ask me before implementing it. Since this PR has many logic changes. It takes significant time in testing/reviewing PRs like this one.

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@atharvyadav22 Please see the review changes. If anything is unclear, please ask me before implementing it. Since this PR has many logic changes. It takes significant time in testing/reviewing PRs like this one.

Yes thanks for your valuable time and pointing out i always try to not many many possible errors and solve then push commits but migration is lengthy anyways i'll take care of in in next commit i'll solve everything you mentioned so it won't take your time.
Thanks for detailed review ❤️

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

@atharvyadav22 Mark your PR as a draft when the effort is ongoing.

@atharvyadav22 atharvyadav22 marked this pull request as draft March 9, 2026 06:34
@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@MohitMaliFtechiz i'll prioritize this one issue now.

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

atharvyadav22 commented Mar 30, 2026

@MohitMaliFtechiz i have checked the code and functionality it works fine for all the cases.
Coming up to test cases there are concerning issues lie.

  1. flakyTest{} wrapper
  2. testFlow should be replaced with test{} (Kotlin has this)
  3. Turbine should be closed
@Suppress("InjectDispatcher")
  private var ioDispatcher: CoroutineDispatcher = Dispatchers.IO

this should be passed via Constructor, also for my PR of stabilization IO i didn't touched this as this is little complex and as migration was going.

similarly for this

  fun sendUiEvent(uiEvent: OnlineLibraryUiEvent) =
    viewModelScope.launch {
      _onlineLibraryEvent.emit(uiEvent)
    }

we cant control this in tests

so to properly make an robust test we need to consider this after migration properly i suppose, cause we have seen many issues with these in past also.

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

@atharvyadav22 Now, this PR code is set. You can start writing the test cases(unit test cases) for ZimHostViewModel and other things introduced in this PR. If any UI test case fails, please have a look at that as well :)

If you need anything from me, just drop a comment here.

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@MohitMaliFtechiz okay ill do it here i see new pushes
Thanks for your help 👍

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

@atharvyadav22 For sendUiEvent method. I have added a comment on that method. This will be updated in the OnlineLibraryScreen migration.

Here we need to add/update/improve the test cases for this PR. Not for other screens. Since ZimManageViewModel is very large class and handles 2 screen datas. We need to first split them into seperate viewModels, and then improve those test cases.

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@atharvyadav22 For sendUiEvent method. I have added a comment on that method. This will be updated in the OnlineLibraryScreen migration.

Here we need to add/update/improve the test cases for this PR. Not for other screens. Since ZimManageViewModel is very large class and handles 2 screen datas. We need to first split them into seperate viewModels, and then improve those test cases.

new tests file for newly created methods right only or any specific things?

As we are in urgent for migration for that OnlineLibraryScreen i see no progress as that PR has many issues including many CI failure, if you allow i can take that : ) since my migration related tasks are almost completed.
between 1-1.5 week i can complete that migration.
Thanks.

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

new tests file for newly created methods right only or any specific things?

The newly created files with edge cases.

As we are in urgent for migration for that OnlineLibraryScreen i see no progress as that PR has many issues including many CI failure, if you allow i can take that : ) since my migration related tasks are almost completed.
between 1-1.5 week i can complete that migration.
Thanks.

Thank you for showing interest. But OnlineScreen has many logics and scenarios. I will take that. You can take some other issues :).

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

new tests file for newly created methods right only or any specific things?

The newly created files with edge cases.

As we are in urgent for migration for that OnlineLibraryScreen i see no progress as that PR has many issues including many CI failure, if you allow i can take that : ) since my migration related tasks are almost completed.
between 1-1.5 week i can complete that migration.
Thanks.

Thank you for showing interest. But OnlineScreen has many logics and scenarios. I will take that. You can take some other issues :).

Okay if there is anything which might help kiwix and save your time i can help with that if something you feel.
Thanks.

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

@atharvyadav22 Any update here?

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@atharvyadav22 Any update here?

Yes actually i am doing coverage also side by side for this. I am currently doing that Media Save PR as the recent test files fails for new code so its taking me time to rewrite them along side i am doing that UnsupportedMimeType as you said so.

I'll do this PR by this week itself, actually i am using best practice and trying to make test robust so it saves your reviewing time to so its taking me time.
Thanks.

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@MohitMaliFtechiz
This is only for Unit Test cases but inorder to make an robust migration i'll also make Instrument Test like i have started working on it should i go on ?

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

@atharvyadav22 Yes, we should add both instrumentation and unit test cases. However, the UI test cases are already exist. Those are the scenarios based. But you can add the compose UI test cases as well. So that we can verify the UI as well.

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

atharvyadav22 commented Apr 11, 2026

@MohitMaliFtechiz
actually the Current UI Test is not that good reason is we need to mimic actual behavior of the Screen like server starting, etc.

Now interesting thing is this can't work on CI as emulators dont have these WIFI but if we test on real device rather it should work i came up with idea like we'll check about WIFI to know whether we are testing in emulator or real devices also will be placing a fix to run for all the devices API 27+ (current has upto 32 i suppose)

I'll need time for such things as for an robust migration.

Thanks.

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

@atharvyadav22 Previously, we had the fragments, and we could not test the functionality directly within a fragment for real scenarios. But now we have migrated to compose with view models.

So now we can test layer by layer to ensure all the functionality works correctly.

  • First layer should be the viewModel testing, where all the logic is written. By doing this, we can ensure how this functionality will behave on an actual device.
  • The second layer is the UI layer. A pure compose UI testing, so that we can ensure which data come from the viewModel is rendered correctly and shows the correct UI. Also, when clicks are performed, they should call the correct viewModel methods(ViewModel testing is already done).
  • The third one is a pure real-scenario test that is already written. Due to the unavailability of WIFI on emualtor it is currently running on the API level 30, which is okay because we have tested both UI and logic above the testing layer.

By doing this, we don't need to add additional testing and conditions based on emualtor or real device.

@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@atharvyadav22 Previously, we had the fragments, and we could not test the functionality directly within a fragment for real scenarios. But now we have migrated to compose with view models.

So now we can test layer by layer to ensure all the functionality works correctly.

  • First layer should be the viewModel testing, where all the logic is written. By doing this, we can ensure how this functionality will behave on an actual device.
  • The second layer is the UI layer. A pure compose UI testing, so that we can ensure which data come from the viewModel is rendered correctly and shows the correct UI. Also, when clicks are performed, they should call the correct viewModel methods(ViewModel testing is already done).
  • The third one is a pure real-scenario test that is already written. Due to the unavailability of WIFI on emualtor it is currently running on the API level 30, which is okay because we have tested both UI and logic above the testing layer.

By doing this, we don't need to add additional testing and conditions based on emualtor or real device.

Okay actually what i was working was if someone tests on real devices they will see that navigation, clicks eg- Server is started, books selection toggle.
Keeping CI safe.

I also agree with your point so should i continue with that work or only fix that CI errors?

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

We should add the testing as I described in layers. That will already ensure that everthing works correctly. Devs can easily run the test on the required API level. However, if there are some changes made in this screen, then devs first test manually. So we should not add conditions here.

@atharvyadav22 atharvyadav22 force-pushed the migrate/zim branch 3 times, most recently from a2236ea to 8bae148 Compare April 13, 2026 14:14
@atharvyadav22
Copy link
Copy Markdown
Contributor Author

atharvyadav22 commented Apr 13, 2026

@MohitMaliFtechiz

Sorry forgot to amend the commit

Fixed Ci for Instrumentation Test and Renamed as per Layer 3 (Integration Test)
Added Test for layer 2 (UI Test)
Address review changes

Also Apologies for bad commit the reason is there was merge conflict so had to reset head .

@MohitMaliFtechiz
Copy link
Copy Markdown
Collaborator

@atharvyadav22 Thanks for the update.

There are still some conflicts in this PR. Also, in this commit 1c778bf there are still some unnecessary messages in the commit; remove that.

image

atharvyadav22 and others added 6 commits April 14, 2026 12:03
…es the DI-provided dispatcher.

* Addressed all review comments.
* Improved the logic for loading selected books.
* Refactored the ViewModel to use MutableSharedFlow instead of Channel.
* Moved all UI-related computation logic into the ViewModel. The UI now only observes state and renders it.
* Improved the ViewModel and UI logic for better robustness and readability.
* Improve the showing of hosted books for custom apps.
* Updated `BooksOnDiskListItem` to remove the isSelected from the parent class. Because it does not require for other classes like `LanguageItem`. Due to this, mutable property compose was treating this same object, and does not reflect the changes in UI when we are selecting a bookItem. So we have moved this into `BookOnDisk` where it is needed and refactor the codebase according to this change.
* Refactored the test cases according to BookOnDisk item.
…ionGranted` to `KiwixPermissionChecker`. Since some logic depends on app variants and test cases, it is now encapsulated within this checker. This allows us to use these methods across the codebase without adding extra conditions.
-Fixed Ci for Instrumentation Test and Renamed as per Layer 3 (Integration Test)
-Added Test for layer 2 (UI Test)
-Address review changes
@atharvyadav22
Copy link
Copy Markdown
Contributor Author

@MohitMaliFtechiz
Could you verify everything is fine now any improvements?
also there were many merge conflicts i have resolved them still please verify if i did correctly the rebase part for files like KiwixFilePermissionChecker and others.
I have rewritten the history as well and edited the commit message.
Thanks.

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.

Remove ZimHostFragment from project, and use pure composable instead.

3 participants