Issue/13326 fix scan backup menu animation#13976
Issue/13326 fix scan backup menu animation#13976zwarm merged 14 commits intofeature/remove-empty-state-on-site-changefrom
Conversation
…3326-fix-scan-backup-menu-animation
|
You can trigger optional UI/connected tests for these changes by visiting CircleCI here. |
| suspend fun getJetpackPurchasedProducts(remoteSiteId: Long): JetpackPurchasedProducts { | ||
| val capabilities = withContext(bgDispatcher) { | ||
| getOrFetchJetpackCapabilities(remoteSiteId) | ||
| suspend fun getJetpackPurchasedProducts(remoteSiteId: Long) = flow { |
There was a problem hiding this comment.
This method now uses flow (it's used only for the new ImprovedMySiteFragment). It always returns cached capabilities and than initiates fetch of the up-to-date capabilities if needed.
| fetchJetpackCapabilities(remoteSiteId) | ||
| } | ||
| } | ||
| fun getCachedJetpackPurchasedProducts(remoteSiteId: Long): JetpackPurchasedProducts = |
There was a problem hiding this comment.
getCachedJetpackPurchasedProducts and fetchJetpackPurchasedProducts are public since they are used directly from the legacy (currently used) My Site fragment. The legacy fragment doesn't use getJetpackPurchasedProducts (flow) -> it needs to synchronously load cached value since the state is refreshed from onResume().
| } | ||
|
|
||
| private fun forceResumeDuplicateRequests(remoteSiteId: Long) { | ||
| continuation[remoteSiteId]?.let { |
There was a problem hiding this comment.
Instead of throwing an exception, we simply resume any duplicate requests with an exception.
| it.resume(event) | ||
| } | ||
| if (continuation.isEmpty()) { | ||
| dispatcher.unregister(this@JetpackCapabilitiesUseCase) |
There was a problem hiding this comment.
We need to make sure to unregister the instance only when no requests are running (previously, multiple parallel requests for different sites were not supported at all)
| private val jetpackCapabilitiesUseCase: JetpackCapabilitiesUseCase | ||
| ) : MySiteSource<JetpackCapabilities> { | ||
| override fun buildSource(siteId: Int) = flow { | ||
| emit(JetpackCapabilities(scanAvailable = false, backupAvailable = false)) |
There was a problem hiding this comment.
We don't need to always set visibility to false before the request to fetch capabilities finished, since the use case now always returns the cached value first.
| else -> { | ||
| viewModelScope.launch { | ||
| val purchasedProducts = jetpackCapabilitiesUseCase.getJetpackPurchasedProducts(site.siteId) | ||
| val purchasedProducts = jetpackCapabilitiesUseCase.getCachedJetpackPurchasedProducts(site.siteId) |
There was a problem hiding this comment.
ActivityLogViewModel will always use the cached value now.
| mapToJetpackPurchasedProducts(getCachedJetpackCapabilities(remoteSiteId)) | ||
|
|
||
| private suspend fun hasValidCache(remoteSiteId: Long): Boolean { | ||
| return withContext(bgDispatcher) { |
There was a problem hiding this comment.
I've removed all context switches from this class, since it doesn't perform any long-running operation so it can run even on the Ui thread. I previously considered loading data from sharedPreferences for a long-running operation - but it's causing more troubles than it's worth it.
There was a problem hiding this comment.
I agree with the decision made here.
| suspend fun fetchJetpackPurchasedProducts(remoteSiteId: Long): JetpackPurchasedProducts = | ||
| mapToJetpackPurchasedProducts(fetchJetpackCapabilities(remoteSiteId)) | ||
|
|
||
| private fun mapToJetpackPurchasedProducts(capabilities: List<JetpackCapability>) = |
There was a problem hiding this comment.
This has not been changed - just extracted into a standalone method
| backup = capabilities.find { BACKUP_CAPABILITIES.contains(it) } != null | ||
| ) | ||
|
|
||
| fun hasValidCache(remoteSiteId: Long): Boolean { |
There was a problem hiding this comment.
This method was not changed at all - I'm not sure why github marked it as changed.
There was a problem hiding this comment.
Happens to me sometimes too .. I think it's AS .
| updateCache(remoteSiteId, capabilities) | ||
| } | ||
| return@withContext capabilities | ||
| forceResumeDuplicateRequests(remoteSiteId) |
There was a problem hiding this comment.
I've removed the "withContext" and replace throw exception with forceResumeDuplicateRequests(remoteSiteId), the rest is without changes.
|
You can test the changes on this Pull Request by downloading the APK here. |
zwarm
left a comment
There was a problem hiding this comment.
@malinajirka - Everything is working as expected. 👏 In addition to the tests you specified, I also attempted to recreate the crash and was unable to (switching site quickly - over & over again, back & forth through the tabs with site switching thrown in).
Thanks for the walkthrough, it was very helpful.
Parent issue #13326
This PR fixes two issues
To test:
PR submission checklist:
RELEASE-NOTES.txtif necessary.