From 6cfe8c9008aebfc51d6e3a27f293db8ea0089745 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Wed, 31 Aug 2022 18:17:16 -0400 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/26739 - Display MR onboarding dialog to existing users as soon as the app is opened --- .../java/org/mozilla/fenix/FeatureFlags.kt | 2 +- .../java/org/mozilla/fenix/HomeActivity.kt | 7 +++++ .../org/mozilla/fenix/home/HomeFragment.kt | 1 - .../SessionControlController.kt | 12 --------- .../SessionControlInteractor.kt | 10 ------- .../home/sessioncontrol/SessionControlView.kt | 8 ------ .../DefaultSessionControlControllerTest.kt | 15 ----------- .../home/SessionControlInteractorTest.kt | 6 ----- .../fenix/home/WallpapersObserverTest.kt | 2 ++ .../sessioncontrol/SessionControlViewTest.kt | 26 ------------------- 10 files changed, 10 insertions(+), 79 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index cbbbef1cef..b6874d06aa 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -82,7 +82,7 @@ object FeatureFlags { /** * Enables showing the homescreen onboarding card. */ - const val showHomeOnboarding = false + val showHomeOnboarding = Config.channel.isNightlyOrDebug /** * Enables history improvement features. diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 67352085f6..c118cc3dfe 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -101,6 +101,7 @@ import org.mozilla.fenix.library.history.HistoryFragmentDirections import org.mozilla.fenix.library.historymetadata.HistoryMetadataGroupFragmentDirections import org.mozilla.fenix.library.recentlyclosed.RecentlyClosedFragmentDirections import org.mozilla.fenix.onboarding.DefaultBrowserNotificationWorker +import org.mozilla.fenix.onboarding.FenixOnboarding import org.mozilla.fenix.perf.MarkersActivityLifecycleCallbacks import org.mozilla.fenix.perf.MarkersFragmentLifecycleCallbacks import org.mozilla.fenix.perf.Performance @@ -171,6 +172,8 @@ 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), @@ -252,6 +255,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { StartOnHome.enterHomeScreen.record(NoExtras()) } + if (settings().showHomeOnboardingDialog && onboarding.userHasBeenOnboarded()) { + navHost.navController.navigate(NavGraphDirections.actionGlobalHomeOnboardingDialog()) + } + Performance.processIntentIfPerformanceTest(intent, this) if (settings().isTelemetryEnabled) { diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index da38cb2c67..d88c4b7430 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -389,7 +389,6 @@ class HomeFragment : Fragment() { containerView = binding.sessionControlRecyclerView, viewLifecycleOwner = viewLifecycleOwner, interactor = sessionControlInteractor, - onboarding = onboarding, ) updateSessionControlView() diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt index f03b7f90a9..9d95b730ec 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt @@ -197,11 +197,6 @@ interface SessionControlController { */ fun handleCustomizeHomeTapped() - /** - * @see [OnboardingInteractor.showOnboardingDialog] - */ - fun handleShowOnboardingDialog() - /** * @see [SessionControlInteractor.reportSessionMetrics] */ @@ -506,13 +501,6 @@ class DefaultSessionControlController( HomeScreen.customizeHomeClicked.record(NoExtras()) } - override fun handleShowOnboardingDialog() { - navController.nav( - R.id.homeFragment, - HomeFragmentDirections.actionGlobalHomeOnboardingDialog() - ) - } - override fun handleReadPrivacyNoticeClicked() { activity.openToBrowserAndLoad( searchTermOrURL = SupportUtils.getMozillaPageUrl(SupportUtils.MozillaPage.PRIVATE_NOTICE), diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlInteractor.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlInteractor.kt index b9aa62db02..d31bc94e1d 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlInteractor.kt @@ -162,12 +162,6 @@ interface OnboardingInteractor { * Opens a custom tab to privacy notice url. Called when a user clicks on the "read our privacy notice" button. */ fun onReadPrivacyNoticeClicked() - - /** - * Show the onboarding dialog to onboard users about recentTabs,recentBookmarks, - * historyMetadata and pocketArticles sections. - */ - fun showOnboardingDialog() } interface CustomizeHomeIteractor { @@ -328,10 +322,6 @@ class SessionControlInteractor( controller.handleReadPrivacyNoticeClicked() } - override fun showOnboardingDialog() { - controller.handleShowOnboardingDialog() - } - override fun onToggleCollectionExpanded(collection: TabCollection, expand: Boolean) { controller.handleToggleCollectionExpanded(collection, expand) } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt index 0093876103..7a8566cd26 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt @@ -23,7 +23,6 @@ import org.mozilla.fenix.home.Mode import org.mozilla.fenix.home.OnboardingState import org.mozilla.fenix.home.recentbookmarks.RecentBookmark import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem -import org.mozilla.fenix.onboarding.FenixOnboarding import org.mozilla.fenix.onboarding.JumpBackInCFRDialog import org.mozilla.fenix.onboarding.SyncCFRPresenter import org.mozilla.fenix.utils.Settings @@ -192,14 +191,11 @@ private fun collectionTabItems(collection: TabCollection) = * @param viewLifecycleOwner [LifecycleOwner] for the view. * @property interactor [SessionControlInteractor] which will have delegated to all user * interactions. - * @property onboarding [FenixOnboarding] that is used to determine whether or not the user has - * been onboarded. */ class SessionControlView( containerView: View, viewLifecycleOwner: LifecycleOwner, private val interactor: SessionControlInteractor, - private val onboarding: FenixOnboarding, ) { val view: RecyclerView = containerView as RecyclerView @@ -242,10 +238,6 @@ class SessionControlView( } fun update(state: AppState, shouldReportMetrics: Boolean = false) { - if (view.context.settings().showHomeOnboardingDialog && onboarding.userHasBeenOnboarded()) { - interactor.showOnboardingDialog() - } - if (shouldReportMetrics) interactor.reportSessionMetrics(state) sessionControlAdapter.submitList(state.toAdapterList(view.context.settings())) diff --git a/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt b/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt index 85d28139de..25eca51b52 100644 --- a/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt @@ -192,21 +192,6 @@ class DefaultSessionControlControllerTest { } } - @Test - @Ignore("Until the feature is enabled again") - fun handleShowOnboardingDialog() { - createController().handleShowOnboardingDialog() - - verify { - navController.navigate( - match { - it.actionId == R.id.action_global_home_onboarding_dialog - }, - null - ) - } - } - @Test fun `handleCollectionOpenTabClicked onFailure`() { val tab = mockk { diff --git a/app/src/test/java/org/mozilla/fenix/home/SessionControlInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/home/SessionControlInteractorTest.kt index e16eb16d17..9a081afcf5 100644 --- a/app/src/test/java/org/mozilla/fenix/home/SessionControlInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/SessionControlInteractorTest.kt @@ -197,12 +197,6 @@ class SessionControlInteractorTest { verify { controller.handleCustomizeHomeTapped() } } - @Test - fun `WHEN calling showOnboardingDialog THEN handleShowOnboardingDialog`() { - interactor.showOnboardingDialog() - verify { controller.handleShowOnboardingDialog() } - } - @Test fun `WHEN Show All recently saved bookmarks button is clicked THEN the click is handled`() { interactor.onShowAllBookmarksClicked() diff --git a/app/src/test/java/org/mozilla/fenix/home/WallpapersObserverTest.kt b/app/src/test/java/org/mozilla/fenix/home/WallpapersObserverTest.kt index 8900955dcb..dfb9fe0a16 100644 --- a/app/src/test/java/org/mozilla/fenix/home/WallpapersObserverTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/WallpapersObserverTest.kt @@ -19,6 +19,7 @@ import kotlinx.coroutines.cancel import mozilla.components.support.test.libstate.ext.waitUntilIdle import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue +import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.components.AppStore @@ -84,6 +85,7 @@ class WallpapersObserverTest { } @Test + @Ignore("Intermittent test: https://github.com/mozilla-mobile/fenix/issues/26760") fun `WHEN the wallpaper is updated to a new one THEN show the wallpaper`() { val appStore = AppStore() val wallpapersUseCases: WallpapersUseCases = mockk { diff --git a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt index 364e1d2f41..3868082fd5 100644 --- a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt @@ -4,21 +4,16 @@ package org.mozilla.fenix.home.sessioncontrol -import androidx.recyclerview.widget.RecyclerView import io.mockk.every import io.mockk.mockk -import io.mockk.verify import mozilla.components.feature.tab.collections.TabCollection import mozilla.components.feature.top.sites.TopSite import mozilla.components.service.pocket.PocketStory import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory -import mozilla.components.support.test.robolectric.testContext import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith -import org.mozilla.fenix.components.appstate.AppState -import org.mozilla.fenix.ext.components import org.mozilla.fenix.gleanplumb.Message import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.home.recentbookmarks.RecentBookmark @@ -28,27 +23,6 @@ import org.mozilla.fenix.utils.Settings @RunWith(FenixRobolectricTestRunner::class) class SessionControlViewTest { - @Test - fun `GIVENs updates WHEN sections recentTabs, recentBookmarks, historyMetadata or pocketArticles are NOT available THEN DO NOT show the dialog`() { - every { testContext.components.settings } returns mockk(relaxed = true) - val interactor = mockk(relaxed = true) - val view = RecyclerView(testContext) - val controller = SessionControlView( - view, - mockk(relaxed = true), - interactor, - mockk(relaxed = true), - ) - - val state = AppState() - - controller.update(state) - - verify(exactly = 0) { - interactor.showOnboardingDialog() - } - } - @Test fun `GIVEN recent Bookmarks WHEN normalModeAdapterItems is called THEN add a customize home button`() { val settings: Settings = mockk()