1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.focus.fragment.onboarding
7 import androidx.compose.foundation.Image
8 import androidx.compose.foundation.background
9 import androidx.compose.foundation.layout.Arrangement
10 import androidx.compose.foundation.layout.Column
11 import androidx.compose.foundation.layout.fillMaxSize
12 import androidx.compose.foundation.layout.fillMaxWidth
13 import androidx.compose.foundation.layout.padding
14 import androidx.compose.foundation.layout.size
15 import androidx.compose.foundation.rememberScrollState
16 import androidx.compose.foundation.shape.CircleShape
17 import androidx.compose.foundation.verticalScroll
18 import androidx.compose.material.Button
19 import androidx.compose.material.ButtonDefaults
20 import androidx.compose.material.Icon
21 import androidx.compose.material.IconButton
22 import androidx.compose.material.Text
23 import androidx.compose.runtime.Composable
24 import androidx.compose.ui.Alignment
25 import androidx.compose.ui.Modifier
26 import androidx.compose.ui.geometry.Offset
27 import androidx.compose.ui.graphics.Brush
28 import androidx.compose.ui.platform.LocalContext
29 import androidx.compose.ui.res.colorResource
30 import androidx.compose.ui.res.painterResource
31 import androidx.compose.ui.res.stringResource
32 import androidx.compose.ui.text.AnnotatedString
33 import androidx.compose.ui.text.style.TextAlign
34 import androidx.compose.ui.tooling.preview.Preview
35 import androidx.compose.ui.unit.dp
36 import mozilla.components.ui.colors.PhotonColors
37 import org.mozilla.focus.R
38 import org.mozilla.focus.ui.theme.FocusTheme
39 import org.mozilla.focus.ui.theme.focusColors
40 import org.mozilla.focus.ui.theme.focusTypography
44 private fun OnBoardingSecondScreenComposePreview() {
46 OnBoardingSecondScreenCompose({}, {}, {})
51 * Displays the second onBoarding screen
53 * @param setAsDefaultBrowser Will be called when the user clicks on SetDefaultBrowser button.
54 * @param skipScreen Will be called when the user clicks on Skip button.
55 * @param onCloseButtonClick The lambda to be invoked when close button icon is pressed.
58 @Suppress("LongMethod")
59 fun OnBoardingSecondScreenCompose(
60 setAsDefaultBrowser: () -> Unit,
61 skipScreen: () -> Unit,
62 onCloseButtonClick: () -> Unit,
68 brush = Brush.linearGradient(
70 colorResource(R.color.home_screen_modal_gradient_one),
71 colorResource(R.color.home_screen_modal_gradient_two),
72 colorResource(R.color.home_screen_modal_gradient_three),
73 colorResource(R.color.home_screen_modal_gradient_four),
74 colorResource(R.color.home_screen_modal_gradient_five),
75 colorResource(R.color.home_screen_modal_gradient_six),
77 end = Offset(0f, Float.POSITIVE_INFINITY),
78 start = Offset(Float.POSITIVE_INFINITY, 0f),
85 .padding(top = 60.dp, end = 20.dp),
86 horizontalAlignment = Alignment.End,
88 CloseButton(onCloseButtonClick)
93 .verticalScroll(rememberScrollState()),
94 verticalArrangement = Arrangement.Center,
95 horizontalAlignment = Alignment.CenterHorizontally,
98 painter = painterResource(R.drawable.onboarding_second_screen_icon),
99 contentDescription = LocalContext.current.getString(R.string.app_name),
101 .size(200.dp, 300.dp),
104 text = stringResource(
105 R.string.onboarding_second_screen_title,
106 stringResource(R.string.onboarding_short_app_name),
109 .padding(top = 32.dp, start = 16.dp, end = 16.dp),
110 textAlign = TextAlign.Center,
111 style = focusTypography.onboardingTitle,
114 text = stringResource(
115 R.string.onboarding_second_screen_subtitle_one,
118 .padding(top = 16.dp, start = 16.dp, end = 16.dp),
119 textAlign = TextAlign.Center,
120 style = focusTypography.onboardingSubtitle,
123 text = stringResource(
124 R.string.onboarding_second_screen_subtitle_two,
125 stringResource(R.string.onboarding_short_app_name),
128 .padding(top = 16.dp, start = 16.dp, end = 16.dp),
129 textAlign = TextAlign.Center,
130 style = focusTypography.onboardingSubtitle,
132 ComponentOnBoardingSecondScreenButtons(setAsDefaultBrowser, skipScreen)
138 private fun CloseButton(onCloseButtonClick: () -> Unit) {
143 colorResource(id = R.color.onboardingCloseButtonColor),
146 onClick = onCloseButtonClick,
149 painter = painterResource(R.drawable.mozac_ic_cross_24),
150 contentDescription = stringResource(R.string.onboarding_close_button_content_description),
151 tint = focusColors.closeIcon,
157 private fun ComponentOnBoardingSecondScreenButtons(setAsDefaultBrowser: () -> Unit, skipScreen: () -> Unit) {
159 onClick = setAsDefaultBrowser,
161 .padding(top = 33.dp, start = 16.dp, end = 16.dp)
163 colors = ButtonDefaults.textButtonColors(
164 backgroundColor = colorResource(R.color.onboardingButtonOneColor),
168 text = AnnotatedString(
169 LocalContext.current.resources.getString(
170 R.string.onboarding_second_screen_default_browser_button_text,
173 color = PhotonColors.White,
177 onClick = skipScreen,
179 .padding(top = 8.dp, start = 16.dp, end = 16.dp)
181 colors = ButtonDefaults.textButtonColors(
182 backgroundColor = colorResource(R.color.onboardingButtonTwoColor),
186 text = AnnotatedString(
187 LocalContext.current.resources.getString(
188 R.string.onboarding_second_screen_skip_button_text,
191 color = PhotonColors.Black,