Skip to content

Commit 07e58ab

Browse files
rahulsainanimergify[bot]
authored andcommitted
Bug 1822268 - Part 2: Add juno onboarding navigation logic
1 parent 536df03 commit 07e58ab

File tree

4 files changed

+95
-14
lines changed

4 files changed

+95
-14
lines changed

fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt

+20-14
Original file line numberDiff line numberDiff line change
@@ -266,20 +266,24 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
266266
it.start()
267267
}
268268

269-
// Unless the activity is recreated, navigate to home first (without rendering it)
270-
// to add it to the back stack.
271-
if (savedInstanceState == null) {
272-
navigateToHome()
273-
}
274-
275-
if (!shouldStartOnHome() && shouldNavigateToBrowserOnColdStart(savedInstanceState)) {
276-
navigateToBrowserOnColdStart()
269+
if (settings().shouldShowJunoOnboarding(intent.toSafeIntent().isLauncherIntent)) {
270+
navHost.navController.navigate(NavGraphDirections.actionGlobalHomeJunoOnboarding())
277271
} else {
278-
StartOnHome.enterHomeScreen.record(NoExtras())
279-
}
272+
// Unless the activity is recreated, navigate to home first (without rendering it)
273+
// to add it to the back stack.
274+
if (savedInstanceState == null) {
275+
navigateToHome()
276+
}
277+
if (!shouldStartOnHome() && shouldNavigateToBrowserOnColdStart(savedInstanceState)) {
278+
navigateToBrowserOnColdStart()
279+
} else {
280+
StartOnHome.enterHomeScreen.record(NoExtras())
281+
}
280282

281-
if (settings().showHomeOnboardingDialog && onboarding.userHasBeenOnboarded()) {
282-
navHost.navController.navigate(NavGraphDirections.actionGlobalHomeOnboardingDialog())
283+
if (settings().showHomeOnboardingDialog && onboarding.userHasBeenOnboarded()) {
284+
navHost.navController.navigate(NavGraphDirections.actionGlobalHomeOnboardingDialog())
285+
}
286+
showNotificationPermissionPromptIfRequired()
283287
}
284288

285289
Performance.processIntentIfPerformanceTest(intent, this)
@@ -341,8 +345,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
341345
}
342346
}
343347

344-
showNotificationPermissionPromptIfRequired()
345-
346348
components.backgroundServices.accountManagerAvailableQueue.runIfReadyOrQueue {
347349
lifecycleScope.launch(IO) {
348350
// If we're authenticated, kick-off a sync and a device state refresh.
@@ -368,6 +370,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
368370
* Show the pre permission dialog to the user once if the notification are not enabled.
369371
*/
370372
private fun showNotificationPermissionPromptIfRequired() {
373+
if (settings().junoOnboardingEnabled) {
374+
return
375+
}
376+
371377
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
372378
!NotificationManagerCompat.from(applicationContext).areNotificationsEnabledSafe() &&
373379
settings().numberOfAppLaunches <= 1

fenix/app/src/main/java/org/mozilla/fenix/utils/Settings.kt

+14
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,20 @@ class Settings(private val appContext: Context) : PreferencesHolder {
16061606
default = false,
16071607
)
16081608

1609+
/**
1610+
* Returns whether juno onboarding should be shown to the user.
1611+
* @param isLauncherIntent Boolean to indicate whether the app was launched on tapping on the
1612+
* app icon.
1613+
*/
1614+
fun shouldShowJunoOnboarding(isLauncherIntent: Boolean): Boolean {
1615+
return if (!isJunoOnboardingShown && isLauncherIntent) {
1616+
FxNimbus.features.junoOnboarding.recordExposure()
1617+
junoOnboardingEnabled
1618+
} else {
1619+
false
1620+
}
1621+
}
1622+
16091623
/**
16101624
* Get the current mode for how https-only is enabled.
16111625
*/

fenix/app/src/main/res/navigation/nav_graph.xml

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
app:popUpTo="@id/homeFragment"
3030
app:popUpToInclusive="false" />
3131

32+
<action
33+
android:id="@+id/action_global_home_juno_onboarding"
34+
app:destination="@id/junoOnboardingFragment"
35+
app:popUpTo="@id/startupFragment"
36+
app:popUpToInclusive="true" />
37+
38+
<action
39+
android:id="@+id/action_onboarding_home"
40+
app:destination="@id/homeFragment"
41+
app:popUpTo="@id/junoOnboardingFragment"
42+
app:popUpToInclusive="true" />
43+
3244
<action
3345
android:id="@+id/action_global_home_onboarding_dialog"
3446
app:destination="@id/homeOnboardingDialogFragment" />
@@ -183,6 +195,11 @@
183195
android:name="org.mozilla.fenix.StartupFragment">
184196
</fragment>
185197

198+
<fragment
199+
android:id="@+id/junoOnboardingFragment"
200+
android:name="org.mozilla.fenix.onboarding.JunoOnboardingFragment">
201+
</fragment>
202+
186203
<fragment
187204
android:id="@+id/homeFragment"
188205
android:name="org.mozilla.fenix.home.HomeFragment"

fenix/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt

+44
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,50 @@ class SettingsTest {
825825
assertTrue(settings.shouldShowInactiveTabsAutoCloseDialog(20))
826826
}
827827

828+
@Test
829+
fun `GIVEN junoOnboarding is disabled THEN shouldShowJunoOnboarding returns false`() {
830+
val settings = spyk(settings)
831+
every { settings.junoOnboardingEnabled } returns false
832+
every { settings.isJunoOnboardingShown } returns false
833+
834+
val actual = settings.shouldShowJunoOnboarding(true)
835+
836+
assertFalse(actual)
837+
}
838+
839+
@Test
840+
fun `GIVEN junoOnboarding is enabled, isOnboardingShown is false and isLauncherIntent is false THEN shouldShowJunoOnboarding returns false`() {
841+
val settings = spyk(settings)
842+
every { settings.junoOnboardingEnabled } returns true
843+
every { settings.isJunoOnboardingShown } returns false
844+
845+
val actual = settings.shouldShowJunoOnboarding(false)
846+
847+
assertFalse(actual)
848+
}
849+
850+
@Test
851+
fun `GIVEN junoOnboarding is enabled and isOnboardingShown is true THEN shouldShowJunoOnboarding returns false`() {
852+
val settings = spyk(settings)
853+
every { settings.junoOnboardingEnabled } returns true
854+
every { settings.isJunoOnboardingShown } returns true
855+
856+
val actual = settings.shouldShowJunoOnboarding(true)
857+
858+
assertFalse(actual)
859+
}
860+
861+
@Test
862+
fun `GIVEN junoOnboarding is enabled, isOnboardingShown is false and isLauncherIntent is true THEN shouldShowJunoOnboarding returns true`() {
863+
val settings = spyk(settings)
864+
every { settings.junoOnboardingEnabled } returns true
865+
every { settings.isJunoOnboardingShown } returns false
866+
867+
val actual = settings.shouldShowJunoOnboarding(true)
868+
869+
assertTrue(actual)
870+
}
871+
828872
@Test
829873
fun `GIVEN Https-only mode is disabled THEN the engine mode is HttpsOnlyMode#DISABLED`() {
830874
settings.shouldUseHttpsOnly = false

0 commit comments

Comments
 (0)