Skip to content

Conversation

@malinajirka
Copy link
Contributor

@malinajirka malinajirka commented Oct 9, 2025

Fixes WOOMOB-1446

Description

Implements cellular data preference functionality for WooPos local catalog synchronization. When users disable "Download over cellular" in the local catalog settings, background sync operations will only run when connected to WiFi, preventing unexpected data usage charges.

The implementation uses WorkManager's built-in network constraints at the OS level for optimal efficiency - the system won't even start the worker when network conditions don't match the user's preferences.

Testing information

  • Verify the cellular data toggle appears in WooPos local catalog settings
  • Test that toggling the preference saves the setting persistently
  • Confirm worker is rescheduled with updated constraints when you update the toggle

The tests that have been performed

The above

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 9, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App NameWooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commite54cf5c
Direct Downloadwoocommerce-wear-prototype-build-pr14725-e54cf5c.apk

…-downloadovercellular-preference-in

# Conflicts:
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/settings/details/localcatalog/WooPosSettingsLocalCatalogViewModel.kt
@malinajirka malinajirka added this to the 23.5 milestone Oct 9, 2025
@malinajirka malinajirka requested a review from Copilot October 9, 2025 09:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements cellular data preference functionality for WooPos local catalog synchronization, allowing users to restrict background sync operations to WiFi only to prevent unexpected data usage charges.

Key changes:

  • Added a new preference setting to control cellular data usage for sync operations
  • Updated WorkManager constraints to respect user preference (WiFi-only or any connection)
  • Integrated the preference toggle into the local catalog settings UI

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
WooPosPreferencesRepository.kt Adds storage and retrieval methods for the cellular data preference
WooPosSettingsLocalCatalogViewModel.kt Integrates preference loading/saving with UI state and triggers constraint updates
WooPosLocalCatalogSyncScheduler.kt Updates WorkManager constraints based on user preference and handles work rescheduling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@malinajirka malinajirka force-pushed the issue/woomob-1446-woo-poslocal-catalog-save-downloadovercellular-preference-in branch from 70bb768 to 12bed58 Compare October 9, 2025 10:05
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 9, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commite54cf5c
Direct Downloadwoocommerce-prototype-build-pr14725-e54cf5c.apk

@malinajirka malinajirka requested a review from kidinov October 9, 2025 16:46
@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 0% with 63 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.42%. Comparing base (d8fe4c0) to head (e54cf5c).
⚠️ Report is 100 commits behind head on trunk.

Files with missing lines Patch % Lines
...os/localcatalog/WooPosLocalCatalogSyncScheduler.kt 0.00% 45 Missing ⚠️
...ocalcatalog/WooPosSettingsLocalCatalogViewModel.kt 0.00% 11 Missing ⚠️
...opos/util/datastore/WooPosPreferencesRepository.kt 0.00% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #14725      +/-   ##
============================================
- Coverage     38.43%   38.42%   -0.02%     
  Complexity     9887     9887              
============================================
  Files          2105     2105              
  Lines        117088   117122      +34     
  Branches      15646    15646              
============================================
  Hits          45001    45001              
- Misses        67914    67948      +34     
  Partials       4173     4173              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


workManager.enqueueUniquePeriodicWork(
WooPosLocalCatalogSyncWorker.WORK_NAME,
ExistingPeriodicWorkPolicy.UPDATE,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

📓 I replaced Keep with Update and wrapped the block in coroutine.

@kidinov kidinov self-assigned this Oct 13, 2025
lastFullUpdate = formattedTimestamp // TBD local catalog: Replace with full sync timestamp
)

val allowCellularDataUpdate = preferencesRepository.allowCellularDataUpdate.first()
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider making the cellular preference fully reactive by continuously listening to the repository instead of reading it once at startup. This way the UI state always stays in sync with the stored
preference, and the Switch can pass its new value directly rather than the ViewModel toggling the current state.

Something like that. Wdyt?

Refactor_cellular_data_update_handling_to_pass_boolean_value_and_improve_state_management.patch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion @kidinov! I'm wondering what is the benefit of observing, since the settings screen is the only place how this setting can be changed 🤔. The VM would be observing a repository that only the VM itself can change -> so the VM would update the setting and the VM would receive an update from the repo. I might be missing something, but I'm not sure what is the benefit.

Could you please elaborate on it a bit?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Unidirectional data flow: Data flows in one direction: UI → VM → Repo → VM → UI. This makes it easy to trace what's happening. No shortcuts where the VM updates itself directly.
  2. Less code: No need to flip !_state.value.allowCellularDataUpdate - the Switch already has the new value, just save it
  3. Can't get out of sync: Right now, if something goes wrong between updating the VM state and saving to repo, they could be different. With observing, that's impossible.
  4. Works if anything else changes it: currently there is assumption that it can be changed only from 1 place and in sync way, but if it changes asynchronously, it'll be out of sync with the view

Bottom line: We don't maintain two copies of the same data. The repo is the source of the truth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good points, I've tested and applied the patch 🙇.

e54cf5c

Copy link
Contributor

@kidinov kidinov left a comment

Choose a reason for hiding this comment

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

LGTM! I left one code improvement suggestion, please take a look

@malinajirka malinajirka enabled auto-merge October 13, 2025 09:21
@malinajirka malinajirka merged commit d33a5c4 into trunk Oct 13, 2025
14 of 16 checks passed
@malinajirka malinajirka deleted the issue/woomob-1446-woo-poslocal-catalog-save-downloadovercellular-preference-in branch October 13, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants