kiwix-android icon indicating copy to clipboard operation
kiwix-android copied to clipboard

Introduced the category filter on "Download" screen.

Open MohitMaliFtechiz opened this issue 3 months ago • 3 comments

Fixes #4343

  • Showing category in a dialog on the "Download" screen.
  • Saving the selected category in shared preferences so that it will automatically be applied when the user comes back to the application, similar to the language filter.
  • Fetched the category list from an online source.
  • Applied the category filter while fetching the online content.
  • Created CategoryViewModel to manage UI-related data and user actions.
  • Implemented caching of the category list in the application to avoid unnecessary API calls.
  • Created OnlineCategoryDialog to separately handle the UI and all logic related to the category filter.
  • Added unit and UI test cases for this.
  • Refactored ZimManageViewModelTest to include category filter scenarios.

https://github.com/user-attachments/assets/02644996-7fe9-425a-84ec-53f252cca7c4

MohitMaliFtechiz avatar Sep 24 '25 15:09 MohitMaliFtechiz

Codecov Report

:x: Patch coverage is 75.69620% with 96 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 58.75%. Comparing base (1da4c8a) to head (79a5d07).

Files with missing lines Patch % Lines
...tion/library/online/viewmodel/CategoryViewModel.kt 72.88% 19 Missing and 13 partials :warning:
...ation/library/online/OnlineCategoryDialogScreen.kt 80.26% 5 Missing and 10 partials :warning:
...destination/library/online/OnlineCategoryDialog.kt 72.22% 4 Missing and 6 partials :warning:
...kiwix/kiwixmobile/core/data/remote/CategoryFeed.kt 57.14% 9 Missing :warning:
...org/kiwix/kiwixmobile/core/zim_manager/Category.kt 41.66% 7 Missing :warning:
.../nav/destination/library/online/viewmodel/State.kt 84.61% 2 Missing and 4 partials :warning:
...iwixmobile/language/viewmodel/LanguageViewModel.kt 0.00% 4 Missing and 1 partial :warning:
.../library/online/viewmodel/SaveCategoryAndFinish.kt 69.23% 2 Missing and 2 partials :warning:
...wix/kiwixmobile/core/utils/SharedPreferenceUtil.kt 91.89% 0 Missing and 3 partials :warning:
...nav/destination/library/online/viewmodel/Action.kt 50.00% 2 Missing :warning:
... and 3 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4436      +/-   ##
============================================
+ Coverage     58.42%   58.75%   +0.33%     
- Complexity     1455     1473      +18     
============================================
  Files           328      337       +9     
  Lines         17016    17405     +389     
  Branches       2101     2151      +50     
============================================
+ Hits           9941    10227     +286     
- Misses         5669     5730      +61     
- Partials       1406     1448      +42     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Sep 25 '25 17:09 codecov[bot]

How does this filter behaves when device if offline? Where does the category list com from then? How work the caching (I wonder why you need one!)?

kelson42 avatar Sep 25 '25 18:09 kelson42

How does this filter behaves when device if offline? Where does the category list com from then? How work the caching (I wonder why you need one!)?

@kelson42 We have implemented the caching to store the category in sharedPreference so that the application does not need to fetch the category again and again from an online source(in a single app lifecycle).

Initially, it needs to fetch the category from an online source once, and then it will save that in shared preferences. After that, if there is no internet connection available or any error in fetching the category in the next app lifecycle, then it shows the cached category from the shared preferences. If in the next app lifecycle it fetches the category from an online source, then it saves the updated category in SharedPreferences.

We need the caching to avoid the unnecessary API calls. As it is a separate dialog screen with a viewmodel, in that viewmodel, we fetch the category, and the viewmodel keeps that category data until that screen(dialog) is dismissed. After dismissing the view model, it's clear when the screen is no longer available to free up the resource. If the user again opens this dialog for selecting a different category, then it again fetches the category, so to avoid this fetching, we need this caching. Since keeping this data on the activity level is not good.

MohitMaliFtechiz avatar Sep 26 '25 09:09 MohitMaliFtechiz