Skip to content

Commit 21e4840

Browse files
committed
Bug 1942326 - Stop the onboarding theme card from skipping to the next card r=android-reviewers,rebecatudor273
Differential Revision: https://phabricator.services.mozilla.com/D234876
1 parent 6e15bc3 commit 21e4840

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/onboarding/OnboardingFragment.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ import android.view.ViewGroup
1717
import androidx.annotation.RequiresApi
1818
import androidx.compose.runtime.Composable
1919
import androidx.compose.ui.platform.ComposeView
20-
import androidx.core.app.NotificationManagerCompat
2120
import androidx.fragment.app.Fragment
2221
import androidx.localbroadcastmanager.content.LocalBroadcastManager
2322
import androidx.navigation.fragment.findNavController
2423
import mozilla.components.concept.engine.webextension.InstallationMethod
2524
import mozilla.components.service.nimbus.evalJexlSafe
2625
import mozilla.components.service.nimbus.messaging.use
27-
import mozilla.components.support.base.ext.areNotificationsEnabledSafe
2826
import mozilla.components.support.base.log.logger.Logger
2927
import mozilla.components.support.utils.BrowsersCache
3028
import org.mozilla.fenix.GleanMetrics.Pings
@@ -79,7 +77,7 @@ class OnboardingFragment : Fragment() {
7977
with(requireContext()) {
8078
pagesToDisplay(
8179
showDefaultBrowserPage = isNotDefaultBrowser(this) && !isDefaultBrowserPromptSupported(),
82-
showNotificationPage = canShowNotificationPage(this),
80+
showNotificationPage = canShowNotificationPage(),
8381
showAddWidgetPage = canShowAddSearchWidgetPrompt(),
8482
)
8583
}
@@ -359,9 +357,7 @@ class OnboardingFragment : Fragment() {
359357
private fun isNotDefaultBrowser(context: Context) =
360358
!BrowsersCache.all(context.applicationContext).isDefaultBrowser
361359

362-
private fun canShowNotificationPage(context: Context) =
363-
!NotificationManagerCompat.from(context.applicationContext)
364-
.areNotificationsEnabledSafe() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
360+
private fun canShowNotificationPage() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
365361

366362
private fun pagesToDisplay(
367363
showDefaultBrowserPage: Boolean,

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/onboarding/view/OnboardingScreen.kt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,23 @@ fun OnboardingScreen(
123123
val hasScrolledToNextPage = remember { mutableStateOf(false) }
124124

125125
LaunchedEffect(isSignedIn.value, isWidgetPinnedState) {
126-
if ((isSignedIn.value == true || isWidgetPinnedState) && !hasScrolledToNextPage.value) {
126+
val scrollToNextCardFromSignIn = isSignedIn.value?.let {
127+
scrollToNextCardFromSignIn(
128+
pagesToDisplay,
129+
pagerState.currentPage,
130+
it,
131+
)
132+
} ?: false
133+
134+
val scrollToNextCardFromAddWidget = scrollToNextCardFromAddWidget(
135+
pagesToDisplay,
136+
pagerState.currentPage,
137+
isWidgetPinnedState,
138+
)
139+
140+
val scrollToNextCard = scrollToNextCardFromSignIn || scrollToNextCardFromAddWidget
141+
142+
if (scrollToNextCard && !hasScrolledToNextPage.value) {
127143
scrollToNextPageOrDismiss()
128144
hasScrolledToNextPage.value = true
129145
}
@@ -200,6 +216,28 @@ fun OnboardingScreen(
200216
)
201217
}
202218

219+
private fun scrollToNextCardFromAddWidget(
220+
pagesToDisplay: List<OnboardingPageUiData>,
221+
currentPageIndex: Int,
222+
isWidgetPinnedState: Boolean,
223+
): Boolean {
224+
val indexOfWidgetPage =
225+
pagesToDisplay.indexOfFirst { it.type == OnboardingPageUiData.Type.ADD_SEARCH_WIDGET }
226+
val currentPageIsWidgetPage = currentPageIndex == indexOfWidgetPage
227+
return isWidgetPinnedState && currentPageIsWidgetPage
228+
}
229+
230+
private fun scrollToNextCardFromSignIn(
231+
pagesToDisplay: List<OnboardingPageUiData>,
232+
currentPageIndex: Int,
233+
isSignedIn: Boolean,
234+
): Boolean {
235+
val indexOfSignInPage =
236+
pagesToDisplay.indexOfFirst { it.type == OnboardingPageUiData.Type.SYNC_SIGN_IN }
237+
val currentPageIsSignInPage = currentPageIndex == indexOfSignInPage
238+
return isSignedIn && currentPageIsSignInPage
239+
}
240+
203241
@Composable
204242
@Suppress("LongParameterList")
205243
private fun OnboardingContent(

0 commit comments

Comments
 (0)