For #26169 - MR Home Onboarding Dialog for upgrading users
parent
2d99dbb1c5
commit
9a64acd4b6
@ -0,0 +1,279 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.onboarding.view
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.IconButton
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.google.accompanist.insets.navigationBarsPadding
|
||||
import com.google.accompanist.insets.statusBarsPadding
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.compose.button.PrimaryButton
|
||||
import org.mozilla.fenix.compose.button.SecondaryButton
|
||||
import org.mozilla.fenix.theme.FirefoxTheme
|
||||
|
||||
/**
|
||||
* Enum that represents the onboarding screen that is displayed.
|
||||
*/
|
||||
private enum class OnboardingState {
|
||||
Welcome,
|
||||
SyncSignIn
|
||||
}
|
||||
|
||||
/**
|
||||
* A screen for displaying a welcome and sync sign in onboarding.
|
||||
*
|
||||
* @param isSyncSignIn Whether or not the user is signed into their Firefox Sync account.
|
||||
* @param onDismiss Invoked when the user clicks on the close or "Skip" button.
|
||||
* @param onSignInButtonClick Invoked when the user clicks on the "Sign In" button
|
||||
*/
|
||||
@Composable
|
||||
fun Onboarding(
|
||||
isSyncSignIn: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
onSignInButtonClick: () -> Unit,
|
||||
) {
|
||||
var onboardingState by remember { mutableStateOf(OnboardingState.Welcome) }
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.background(FirefoxTheme.colors.layer1)
|
||||
.fillMaxSize()
|
||||
.padding(bottom = 32.dp)
|
||||
.statusBarsPadding()
|
||||
.navigationBarsPadding()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.SpaceBetween,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.End,
|
||||
) {
|
||||
IconButton(onClick = onDismiss) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.mozac_ic_close),
|
||||
contentDescription = null,
|
||||
tint = FirefoxTheme.colors.iconPrimary,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (onboardingState == OnboardingState.Welcome) {
|
||||
OnboardingWelcomeContent()
|
||||
|
||||
OnboardingWelcomeBottomContent(
|
||||
onboardingState = onboardingState,
|
||||
isSyncSignIn = isSyncSignIn,
|
||||
onGetStartedButtonClick = {
|
||||
if (isSyncSignIn) {
|
||||
onDismiss()
|
||||
} else {
|
||||
onboardingState = OnboardingState.SyncSignIn
|
||||
}
|
||||
},
|
||||
)
|
||||
} else if (onboardingState == OnboardingState.SyncSignIn) {
|
||||
OnboardingSyncSignInContent()
|
||||
|
||||
OnboardingSyncSignInBottomContent(
|
||||
onboardingState = onboardingState,
|
||||
onSignInButtonClick = onSignInButtonClick,
|
||||
onSkipButtonClick = onDismiss,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun OnboardingWelcomeBottomContent(
|
||||
onboardingState: OnboardingState,
|
||||
isSyncSignIn: Boolean,
|
||||
onGetStartedButtonClick: () -> Unit
|
||||
) {
|
||||
Column(modifier = Modifier.padding(horizontal = 16.dp)) {
|
||||
PrimaryButton(
|
||||
text = stringResource(id = R.string.onboarding_home_get_started_button),
|
||||
onClick = onGetStartedButtonClick,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
|
||||
if (isSyncSignIn) {
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
} else {
|
||||
Indicators(onboardingState = onboardingState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun OnboardingWelcomeContent() {
|
||||
Column(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_firefox),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(109.dp),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.onboarding_home_welcome_title),
|
||||
color = FirefoxTheme.colors.textPrimary,
|
||||
textAlign = TextAlign.Center,
|
||||
style = FirefoxTheme.typography.headline5,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.onboarding_home_welcome_description),
|
||||
color = FirefoxTheme.colors.textSecondary,
|
||||
textAlign = TextAlign.Center,
|
||||
style = FirefoxTheme.typography.body2,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun OnboardingSyncSignInContent() {
|
||||
Column(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_scan),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(320.dp, 166.dp),
|
||||
contentScale = ContentScale.FillBounds,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.onboarding_home_sync_title),
|
||||
color = FirefoxTheme.colors.textPrimary,
|
||||
textAlign = TextAlign.Center,
|
||||
style = FirefoxTheme.typography.headline5,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.onboarding_home_sync_description),
|
||||
color = FirefoxTheme.colors.textSecondary,
|
||||
textAlign = TextAlign.Center,
|
||||
style = FirefoxTheme.typography.body2,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun OnboardingSyncSignInBottomContent(
|
||||
onboardingState: OnboardingState,
|
||||
onSignInButtonClick: () -> Unit,
|
||||
onSkipButtonClick: () -> Unit,
|
||||
) {
|
||||
Column(modifier = Modifier.padding(horizontal = 16.dp)) {
|
||||
PrimaryButton(
|
||||
text = stringResource(id = R.string.onboarding_home_sign_in_button),
|
||||
onClick = onSignInButtonClick,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
SecondaryButton(
|
||||
text = stringResource(id = R.string.onboarding_home_skip_button),
|
||||
onClick = onSkipButtonClick,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Indicators(onboardingState = onboardingState)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Indicators(onboardingState: OnboardingState) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
) {
|
||||
Indicator(
|
||||
color = if (onboardingState == OnboardingState.Welcome) {
|
||||
FirefoxTheme.colors.indicatorActive
|
||||
} else {
|
||||
FirefoxTheme.colors.indicatorInactive
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
Indicator(
|
||||
color = if (onboardingState == OnboardingState.SyncSignIn) {
|
||||
FirefoxTheme.colors.indicatorActive
|
||||
} else {
|
||||
FirefoxTheme.colors.indicatorInactive
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Indicator(color: Color) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(6.dp)
|
||||
.clip(CircleShape)
|
||||
.background(color),
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview
|
||||
private fun OnboardingPreview() {
|
||||
FirefoxTheme {
|
||||
Onboarding(
|
||||
isSyncSignIn = false,
|
||||
onDismiss = {},
|
||||
onSignInButtonClick = {},
|
||||
)
|
||||
}
|
||||
}
|
@ -1,219 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:overScrollMode="never"
|
||||
android:fitsSystemWindows="true"
|
||||
android:fillViewport="true"
|
||||
android:background="?scrim"
|
||||
android:scrollbars="none">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/dialog_background"
|
||||
android:layout_marginTop="16dp" >
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/firefox_logo"
|
||||
android:layout_width="59dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_firefox" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/welcome_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginHorizontal="@dimen/oboarding_home_dialog_margin_horizontal"
|
||||
app:lineHeight="24sp"
|
||||
android:textAppearance="@style/Header20TextStyle"
|
||||
android:textAlignment="center"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/firefox_logo" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginHorizontal="@dimen/oboarding_home_dialog_margin_horizontal"
|
||||
app:lineHeight="24sp"
|
||||
android:textAppearance="@style/Body14TextStyle"
|
||||
android:text="@string/onboarding_home_screen_description_2"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/welcome_title" />
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/home_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginTop="26dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintEnd_toStartOf="@id/home_title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/description"
|
||||
app:srcCompat="@drawable/mozac_ic_home"
|
||||
app:tint="?attr/textPrimary" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/home_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/oboarding_home_dialog_margin_horizontal"
|
||||
android:layout_marginTop="26dp"
|
||||
app:lineHeight="20sp"
|
||||
android:textAppearance="@style/Header14TextStyle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/home_icon"
|
||||
app:layout_constraintTop_toBottomOf="@id/description" />
|
||||
|
||||
<View
|
||||
android:id="@+id/home_placeholder"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintEnd_toStartOf="@id/home_description"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/home_icon" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/home_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="@dimen/oboarding_home_dialog_margin_horizontal"
|
||||
app:lineHeight="20sp"
|
||||
android:text="@string/onboarding_home_screen_section_home_description_2"
|
||||
android:textAppearance="@style/Body14TextStyle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/home_placeholder"
|
||||
app:layout_constraintTop_toBottomOf="@+id/home_title" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cleaner_tab_tray_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginTop="26dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintEnd_toStartOf="@id/cleaner_tab_tray_title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/home_description"
|
||||
app:srcCompat="@drawable/ic_multiple_tabs"
|
||||
app:tint="?attr/textPrimary" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/cleaner_tab_tray_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/oboarding_home_dialog_margin_horizontal"
|
||||
android:layout_marginTop="26dp"
|
||||
app:lineHeight="20dp"
|
||||
android:text="@string/onboarding_home_screen_section_cleaner_tab_tray_title_2"
|
||||
android:textAppearance="@style/Header14TextStyle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/cleaner_tab_tray_icon"
|
||||
app:layout_constraintTop_toBottomOf="@id/home_description" />
|
||||
|
||||
<View
|
||||
android:id="@+id/cleaner_tab_tray_placeholder"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintEnd_toStartOf="@id/cleaner_tab_tray_description"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cleaner_tab_tray_icon" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/cleaner_tab_tray_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="@dimen/oboarding_home_dialog_margin_horizontal"
|
||||
app:lineHeight="20sp"
|
||||
android:text="@string/onboarding_home_screen_section_cleaner_tab_tray_description_2"
|
||||
android:textAppearance="@style/Body14TextStyle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/cleaner_tab_tray_placeholder"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cleaner_tab_tray_title" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/useful_history_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginTop="26dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintEnd_toStartOf="@id/useful_history_title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cleaner_tab_tray_description"
|
||||
app:srcCompat="@drawable/ic_history"
|
||||
app:tint="?attr/textPrimary" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/useful_history_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/oboarding_home_dialog_margin_horizontal"
|
||||
android:layout_marginTop="26dp"
|
||||
app:lineHeight="20sp"
|
||||
android:text="@string/onboarding_home_screen_section_useful_history_title_2"
|
||||
android:textAppearance="@style/Header14TextStyle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/useful_history_icon"
|
||||
app:layout_constraintTop_toBottomOf="@id/cleaner_tab_tray_description" />
|
||||
|
||||
<View
|
||||
android:id="@+id/useful_history_placeholder"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:importantForAccessibility="no"
|
||||
app:layout_constraintEnd_toStartOf="@id/useful_history_description"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/useful_history_icon" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/useful_history_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="@dimen/oboarding_home_dialog_margin_horizontal"
|
||||
app:lineHeight="20sp"
|
||||
android:text="@string/onboarding_home_screen_section_useful_history_description_2"
|
||||
android:textAppearance="@style/Body14TextStyle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/useful_history_placeholder"
|
||||
app:layout_constraintTop_toBottomOf="@+id/useful_history_title" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/finish_button"
|
||||
style="@style/PositiveButton"
|
||||
android:layout_marginHorizontal="64dp"
|
||||
android:layout_marginTop="42dp"
|
||||
android:background="@drawable/onboarding_padded_background"
|
||||
android:text="@string/onboarding_finish"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/useful_history_description" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
Loading…
Reference in New Issue