2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

Bug 1829301 - Make fenix onboarding singleton

This commit is contained in:
rahulsainani 2023-04-21 17:20:42 +02:00 committed by mergify[bot]
parent c27779ccb4
commit 18bae37f2a
8 changed files with 15 additions and 30 deletions

View File

@ -33,7 +33,7 @@ import org.mozilla.fenix.helpers.HomeActivityTestRule
*
* Say no to main thread IO! 🙅
*/
private const val EXPECTED_SUPPRESSION_COUNT = 19
private const val EXPECTED_SUPPRESSION_COUNT = 17
/**
* The number of times we call the `runBlocking` coroutine method on the main thread during this

View File

@ -88,7 +88,6 @@ import org.mozilla.fenix.ext.setCustomEndpointIfAvailable
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.lifecycle.StoreLifecycleObserver
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.onboarding.MARKETING_CHANNEL_ID
import org.mozilla.fenix.perf.MarkersActivityLifecycleCallbacks
import org.mozilla.fenix.perf.ProfilerMarkerFactProcessor
@ -964,6 +963,6 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
internal fun shouldShowPrivacyNotice(): Boolean {
return Config.channel.isMozillaOnline &&
settings().shouldShowPrivacyPopWindow &&
!FenixOnboarding(this).userHasBeenOnboarded()
!components.fenixOnboarding.userHasBeenOnboarded()
}
}

View File

@ -118,7 +118,6 @@ import org.mozilla.fenix.messaging.FenixMessageSurfaceId
import org.mozilla.fenix.messaging.FenixNimbusMessagingController
import org.mozilla.fenix.messaging.MessageNotificationWorker
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.onboarding.ReEngagementNotificationWorker
import org.mozilla.fenix.onboarding.ensureMarketingChannelExists
import org.mozilla.fenix.perf.MarkersActivityLifecycleCallbacks
@ -194,8 +193,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
}
private val onboarding by lazy { FenixOnboarding(applicationContext) }
private val externalSourceIntentProcessors by lazy {
listOf(
HomeDeepLinkIntentProcessor(this),
@ -272,7 +269,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
if (settings().shouldShowJunoOnboarding(
hasUserBeenOnboarded = onboarding.userHasBeenOnboarded(),
hasUserBeenOnboarded = components.fenixOnboarding.userHasBeenOnboarded(),
isLauncherIntent = intent.toSafeIntent().isLauncherIntent,
)
) {
@ -296,7 +293,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
StartOnHome.enterHomeScreen.record(NoExtras())
}
if (settings().showHomeOnboardingDialog && onboarding.userHasBeenOnboarded()) {
if (settings().showHomeOnboardingDialog && components.fenixOnboarding.userHasBeenOnboarded()) {
navHost.navController.navigate(NavGraphDirections.actionGlobalHomeOnboardingDialog())
}
showNotificationPermissionPromptIfRequired()

View File

@ -142,7 +142,6 @@ import org.mozilla.fenix.ext.secure
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.HomeScreenViewModel
import org.mozilla.fenix.home.SharedViewModel
import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.perf.MarkersFragmentLifecycleCallbacks
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.biometric.BiometricPromptFeature
@ -224,9 +223,6 @@ abstract class BaseBrowserFragment :
private val sharedViewModel: SharedViewModel by activityViewModels()
private val homeViewModel: HomeScreenViewModel by activityViewModels()
@VisibleForTesting
internal val onboarding by lazy { FenixOnboarding(requireContext()) }
private var currentStartDownloadDialog: StartDownloadDialog? = null
@CallSuper
@ -295,7 +291,7 @@ abstract class BaseBrowserFragment :
observeTabSelection(requireComponents.core.store)
if (!onboarding.userHasBeenOnboarded()) {
if (!requireComponents.fenixOnboarding.userHasBeenOnboarded()) {
observeTabSource(requireComponents.core.store)
}
@ -1166,12 +1162,12 @@ abstract class BaseBrowserFragment :
state.selectedTab
}
.collect {
if (!onboarding.userHasBeenOnboarded() &&
if (!requireComponents.fenixOnboarding.userHasBeenOnboarded() &&
it.content.loadRequest?.triggeredByRedirect != true &&
it.source !is SessionState.Source.External &&
it.content.url !in onboardingLinksList
) {
onboarding.finish()
requireComponents.fenixOnboarding.finish()
}
}
}

View File

@ -38,6 +38,7 @@ import org.mozilla.fenix.home.PocketUpdatesMiddleware
import org.mozilla.fenix.home.blocklist.BlocklistHandler
import org.mozilla.fenix.home.blocklist.BlocklistMiddleware
import org.mozilla.fenix.messaging.state.MessagingMiddleware
import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.perf.AppStartReasonProvider
import org.mozilla.fenix.perf.StartupActivityLog
import org.mozilla.fenix.perf.StartupStateProvider
@ -166,6 +167,7 @@ class Components(private val context: Context) {
val strictMode by lazyMonitored { StrictModeManager(Config, this) }
val settings by lazyMonitored { Settings(context) }
val fenixOnboarding by lazyMonitored { FenixOnboarding(context) }
val reviewPromptController by lazyMonitored {
ReviewPromptController(

View File

@ -10,7 +10,6 @@ import android.content.res.Configuration
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.os.StrictMode
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
@ -105,7 +104,6 @@ import org.mozilla.fenix.messaging.DefaultMessageController
import org.mozilla.fenix.messaging.FenixNimbusMessagingController
import org.mozilla.fenix.messaging.MessagingFeature
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.onboarding.controller.DefaultOnboardingController
import org.mozilla.fenix.perf.MarkersFragmentLifecycleCallbacks
import org.mozilla.fenix.perf.runBlockingIncrement
@ -178,12 +176,6 @@ class HomeFragment : Fragment() {
private val store: BrowserStore
get() = requireComponents.core.store
private val onboarding by lazy {
requireComponents.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
FenixOnboarding(requireContext())
}
}
private var _sessionControlInteractor: SessionControlInteractor? = null
private val sessionControlInteractor: SessionControlInteractor
get() = _sessionControlInteractor!!
@ -243,7 +235,7 @@ class HomeFragment : Fragment() {
currentMode = CurrentMode(
requireContext(),
onboarding,
requireComponents.fenixOnboarding,
browsingModeManager,
::dispatchModeChanges,
)
@ -556,7 +548,7 @@ class HomeFragment : Fragment() {
PrivateBrowsingButtonView(binding.privateBrowsingButton, browsingModeManager) { newMode ->
sessionControlInteractor.onPrivateModeButtonClicked(
newMode,
onboarding.userHasBeenOnboarded(),
requireComponents.fenixOnboarding.userHasBeenOnboarded(),
)
}
@ -881,8 +873,8 @@ class HomeFragment : Fragment() {
}
private fun hideOnboardingIfNeeded() {
if (!onboarding.userHasBeenOnboarded()) {
onboarding.finish()
if (!requireComponents.fenixOnboarding.userHasBeenOnboarded()) {
requireComponents.fenixOnboarding.finish()
requireContext().components.appStore.dispatch(
AppAction.ModeChange(
mode = currentMode.getCurrentMode(),

View File

@ -37,7 +37,6 @@ import org.mozilla.fenix.theme.FirefoxTheme
*/
class JunoOnboardingFragment : Fragment() {
private val fenixOnboarding by lazy { FenixOnboarding(requireContext()) }
private val onboardingPageTypeList by lazy { onboardingPageTypeList(requireContext()) }
private val telemetryRecorder by lazy { JunoOnboardingTelemetryRecorder() }
@ -148,7 +147,7 @@ class JunoOnboardingFragment : Fragment() {
}
private fun onFinish(sequenceId: String, pageType: JunoOnboardingPageType) {
fenixOnboarding.finish()
requireComponents.fenixOnboarding.finish()
findNavController().nav(
id = R.id.junoOnboardingFragment,
directions = JunoOnboardingFragmentDirections.actionOnboardingHome(),

View File

@ -85,7 +85,7 @@ class BrowserFragmentTest {
every { browserFragment.browserToolbarView } returns mockk(relaxed = true)
every { browserFragment.activity } returns homeActivity
every { browserFragment.lifecycle } returns lifecycleOwner.lifecycle
every { browserFragment.onboarding } returns onboarding
every { context.components.fenixOnboarding } returns onboarding
every { browserFragment.requireContext() } returns context
every { browserFragment.initializeUI(any(), any()) } returns mockk()