-
Notifications
You must be signed in to change notification settings - Fork 133
[Woo POS][Local Catalog] Catalog full sync required #14678
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
Open
samiuelson
wants to merge
26
commits into
trunk
Choose a base branch
from
woomob-1412-woo-poslocal-catalog-full-sync-overdue-handling
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
32eaa62
Allow storing last full sync timestamp
samiuelson 5aec9de
Store full sync timestamp
samiuelson df96e15
Check if full sync is overdue
samiuelson 7dd0994
Satisfy detekt's complaints
samiuelson 170d746
Merge branch 'woomob-1405-woo-poslocal-catalog-run-incremental-sync-o…
samiuelson 925d668
Clean up code
samiuelson f6edb88
Clean up code
samiuelson 15df113
Add function to check if local catalog is empty
samiuelson 144d9de
Add getProductCount method
samiuelson 941672f
Execute one-time full sync if needed before opening POS
samiuelson a9eac13
Remove incremental sync from POS splash
samiuelson 06dd9b2
Update WooPosIncrementalSyncReason
samiuelson 2a2bab8
Update WooPosIncrementalSyncReason
samiuelson eba015c
Merge branch 'trunk' into woomob-1412-woo-poslocal-catalog-full-sync-…
samiuelson 5b38e8d
Extract sync state checking into WooPosFullSyncStatusChecker
samiuelson 4800875
Schedule full sync in home if needed
samiuelson e6bb3a9
Fix tests
samiuelson 3f7fed2
Satisfy detekt's complaints
samiuelson 24ea772
Do not do full sync on app start
samiuelson f0ad8bf
Rename class
samiuelson f658137
Update FULL_SYNC_OVERDUE_THRESHOLD to 7 days
samiuelson 29a0fea
Use getWorkInfosForUniqueWorkFlow API for worker monitoring
samiuelson 8415c87
Update tests
samiuelson b5b0dd2
Handle NumberFormatException
samiuelson fae6e2c
Emit error in case site is null
samiuelson 0977a06
Remove comment
samiuelson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,12 @@ import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent.SearchEvent. | |
import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent.SearchEvent.RecentSearchSelected | ||
import com.woocommerce.android.ui.woopos.home.WooPosHomeState.DialogState | ||
import com.woocommerce.android.ui.woopos.home.WooPosHomeState.ScreenPositionState | ||
import com.woocommerce.android.ui.woopos.localcatalog.WooPosFullSyncRequirement | ||
import com.woocommerce.android.ui.woopos.localcatalog.WooPosFullSyncState | ||
import com.woocommerce.android.ui.woopos.localcatalog.WooPosFullSyncStatusChecker | ||
import com.woocommerce.android.ui.woopos.localcatalog.WooPosIncrementalSyncReason | ||
import com.woocommerce.android.ui.woopos.localcatalog.WooPosPerformInstantCatalogFullSync | ||
import com.woocommerce.android.ui.woopos.localcatalog.WooPosPerformLocalCatalogIncrementalSync | ||
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent | ||
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent.Event.BackToCartTapped | ||
import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsTracker | ||
|
@@ -31,6 +37,9 @@ class WooPosHomeViewModel @Inject constructor( | |
private val parentToChildrenEventSender: WooPosParentToChildrenEventSender, | ||
private val analyticsTracker: WooPosAnalyticsTracker, | ||
private val soundHelper: WooPosSoundHelper, | ||
private val syncStatusChecker: WooPosFullSyncStatusChecker, | ||
private val performInitialFullSync: WooPosPerformInstantCatalogFullSync, | ||
private val incrementalSync: WooPosPerformLocalCatalogIncrementalSync, | ||
savedStateHandle: SavedStateHandle, | ||
) : ViewModel() { | ||
private val _state = savedStateHandle.getStateFlow( | ||
|
@@ -54,6 +63,49 @@ class WooPosHomeViewModel @Inject constructor( | |
viewModelScope.launch { | ||
soundHelper.preloadChaChing() | ||
} | ||
startCatalogSyncIfNeeded() | ||
} | ||
|
||
private fun startCatalogSyncIfNeeded() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 I'd consider extracting this into a separate class - feels like an implementation detail the VM shouldn't know about, otherwise, it might grow a lot overtime. |
||
viewModelScope.launch { | ||
val requirement = syncStatusChecker.checkSyncRequirement() | ||
|
||
when (requirement) { | ||
is WooPosFullSyncRequirement.NotRequired, | ||
is WooPosFullSyncRequirement.Overdue -> { | ||
_state.value = _state.value.copy( | ||
catalogSyncState = WooPosHomeState.CatalogSyncState.Idle | ||
) | ||
incrementalSync.execute(WooPosIncrementalSyncReason.ON_POS_HOME) | ||
} | ||
is WooPosFullSyncRequirement.BlockingRequired -> { | ||
performInitialFullSync().collect { syncStatus -> | ||
when (syncStatus) { | ||
is WooPosFullSyncState.InProgress -> { | ||
_state.value = _state.value.copy( | ||
catalogSyncState = WooPosHomeState.CatalogSyncState.Syncing | ||
) | ||
} | ||
is WooPosFullSyncState.Success -> { | ||
_state.value = _state.value.copy( | ||
catalogSyncState = WooPosHomeState.CatalogSyncState.Success | ||
) | ||
} | ||
is WooPosFullSyncState.Failed -> { | ||
_state.value = _state.value.copy( | ||
catalogSyncState = WooPosHomeState.CatalogSyncState.Failed(syncStatus.error) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
is WooPosFullSyncRequirement.Error -> { | ||
_state.value = _state.value.copy( | ||
catalogSyncState = WooPosHomeState.CatalogSyncState.Failed(requirement.message) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun onCleared() { | ||
|
@@ -88,6 +140,10 @@ class WooPosHomeViewModel @Inject constructor( | |
} | ||
} | ||
|
||
WooPosHomeUIEvent.RetryCatalogSyncClicked -> { | ||
startCatalogSyncIfNeeded() | ||
} | ||
|
||
is WooPosHomeUIEvent.OnBarcodeEvent -> { | ||
sendEventToChildren(ParentToChildrenEvent.BarcodeEvent(event.result)) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🔍 We might want to add
perform
prefix for consistency.