@ -52,7 +52,7 @@ class OnboardingFragment : Fragment() {
private val pagesToDisplay by lazy {
pagesToDisplay (
shouldShowDefaultBrowserCard ( requireContext ( ) ) ,
isNotDefaultBrowser ( requireContext ( ) ) ,
canShowNotificationPage ( requireContext ( ) ) ,
canShowAddWidgetCard ( ) ,
)
@ -63,6 +63,7 @@ class OnboardingFragment : Fragment() {
@SuppressLint ( " SourceLockedOrientationActivity " )
override fun onCreate ( savedInstanceState : Bundle ? ) {
super . onCreate ( savedInstanceState )
val context = requireContext ( )
if ( pagesToDisplay . isEmpty ( ) ) {
/* do not continue if there's no onboarding pages to display */
onFinish ( null )
@ -72,8 +73,14 @@ class OnboardingFragment : Fragment() {
activity ?. requestedOrientation = ActivityInfo . SCREEN _ORIENTATION _PORTRAIT
}
val filter = IntentFilter ( WidgetPinnedReceiver . ACTION )
LocalBroadcastManager . getInstance ( requireContext( ) )
LocalBroadcastManager . getInstance ( context )
. registerReceiver ( pinAppWidgetReceiver , filter )
if ( isNotDefaultBrowser ( context ) &&
pagesToDisplay . none { it . type == OnboardingPageUiData . Type . DEFAULT _BROWSER }
) {
promptToSetAsDefaultBrowser ( )
}
}
@RequiresApi ( Build . VERSION_CODES . TIRAMISU )
@ -109,11 +116,7 @@ class OnboardingFragment : Fragment() {
OnboardingScreen (
pagesToDisplay = pagesToDisplay ,
onMakeFirefoxDefaultClick = {
activity ?. openSetDefaultBrowserOption ( useCustomTab = true )
telemetryRecorder . onSetToDefaultClick (
sequenceId = pagesToDisplay . telemetrySequenceId ( ) ,
sequencePosition = pagesToDisplay . sequencePosition ( OnboardingPageUiData . Type . DEFAULT _BROWSER ) ,
)
promptToSetAsDefaultBrowser ( )
} ,
onSkipDefaultClick = {
telemetryRecorder . onSkipSetToDefaultClick (
@ -212,7 +215,7 @@ class OnboardingFragment : Fragment() {
)
}
private fun shouldShowDefaultBrowserCard ( context : Context ) =
private fun isNotDefaultBrowser ( context : Context ) =
! BrowsersCache . all ( context . applicationContext ) . isDefaultBrowser
private fun canShowNotificationPage ( context : Context ) =
@ -260,4 +263,12 @@ class OnboardingFragment : Fragment() {
) { condition -> jexlHelper . evalJexlSafe ( condition ) }
}
}
private fun promptToSetAsDefaultBrowser ( ) {
activity ?. openSetDefaultBrowserOption ( useCustomTab = true )
telemetryRecorder . onSetToDefaultClick (
sequenceId = pagesToDisplay . telemetrySequenceId ( ) ,
sequencePosition = pagesToDisplay . sequencePosition ( OnboardingPageUiData . Type . DEFAULT _BROWSER ) ,
)
}
}