Skip to content

Commit

Permalink
For mozilla-mobile#15279: switch webAppShortcutManager to LazyComponent.
Browse files Browse the repository at this point in the history
This commit series must be landed in collaboration with the changes
destined for ac.

This is the first commit towards turning `UseCases` into using
LazyComponents.
  • Loading branch information
mcomella committed Dec 9, 2020
1 parent fa9d881 commit f94d405
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {

private fun captureSnapshotTelemetryMetrics() = CoroutineScope(Dispatchers.IO).launch {
// PWA
val recentlyUsedPwaCount = components.core.webAppShortcutManager.recentlyUsedWebAppsCount(
val recentlyUsedPwaCount = components.core.webAppShortcutManager.get().recentlyUsedWebAppsCount(
activeThresholdMs = PWA_RECENTLY_USED_THRESHOLD
)
if (recentlyUsedPwaCount == 0) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import mozilla.components.service.digitalassetlinks.local.StatementRelationCheck
import mozilla.components.service.location.LocationService
import mozilla.components.service.location.MozillaLocationService
import mozilla.components.service.sync.logins.SyncableLoginsStorage
import mozilla.components.support.base.utils.LazyComponent
import mozilla.components.support.locale.LocaleManager
import org.mozilla.fenix.AppRequestInterceptor
import org.mozilla.fenix.BuildConfig
Expand Down Expand Up @@ -316,7 +317,7 @@ class Core(
/**
* Shortcut component for managing shortcuts on the device home screen.
*/
val webAppShortcutManager by lazyMonitored {
val webAppShortcutManager = LazyComponent {
WebAppShortcutManager(
context,
client,
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/mozilla/fenix/components/UseCases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import mozilla.components.feature.session.TrackingProtectionUseCases
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.feature.top.sites.TopSitesStorage
import mozilla.components.feature.top.sites.TopSitesUseCases
import mozilla.components.support.base.utils.LazyComponent
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.utils.Mockable

Expand All @@ -35,7 +36,7 @@ class UseCases(
private val engine: Engine,
private val sessionManager: SessionManager,
private val store: BrowserStore,
private val shortcutManager: WebAppShortcutManager,
private val shortcutManager: LazyComponent<WebAppShortcutManager>,
private val topSitesStorage: TopSitesStorage
) {
/**
Expand Down
3 changes: 2 additions & 1 deletion app/src/test/java/org/mozilla/fenix/components/TestCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import mozilla.components.concept.engine.Settings
import mozilla.components.concept.fetch.Client
import mozilla.components.feature.pwa.WebAppShortcutManager
import mozilla.components.feature.top.sites.DefaultTopSitesStorage
import mozilla.components.support.base.utils.LazyComponent

class TestCore(context: Context, crashReporter: CrashReporting) : Core(
context,
Expand All @@ -29,7 +30,7 @@ class TestCore(context: Context, crashReporter: CrashReporting) : Core(
override val sessionManager = SessionManager(engine)
override val store = mockk<BrowserStore>()
override val client = mockk<Client>()
override val webAppShortcutManager = mockk<WebAppShortcutManager>()
override val webAppShortcutManager = LazyComponent { mockk<WebAppShortcutManager>() }
override val thumbnailStorage = mockk<ThumbnailStorage>()
override val topSitesStorage = mockk<DefaultTopSitesStorage>()
}

0 comments on commit f94d405

Please sign in to comment.