diff --git a/ui-lib/src/main/java/cash/z/ecc/ui/screen/onboarding/state/OnboardingState.kt b/ui-lib/src/main/java/cash/z/ecc/ui/screen/onboarding/state/OnboardingState.kt index 827cbf16..e333ccf6 100644 --- a/ui-lib/src/main/java/cash/z/ecc/ui/screen/onboarding/state/OnboardingState.kt +++ b/ui-lib/src/main/java/cash/z/ecc/ui/screen/onboarding/state/OnboardingState.kt @@ -15,10 +15,6 @@ class OnboardingState(initialState: OnboardingStage = OnboardingStage.values().f val current: StateFlow = mutableState - fun hasNext() = current.value.hasNext() - - fun hasPrevious() = current.value.hasPrevious() - fun goNext() { mutableState.value = current.value.getNext() } diff --git a/ui-lib/src/main/java/cash/z/ecc/ui/screen/onboarding/view/OnboardingView.kt b/ui-lib/src/main/java/cash/z/ecc/ui/screen/onboarding/view/OnboardingView.kt index e27004fc..9411ef03 100644 --- a/ui-lib/src/main/java/cash/z/ecc/ui/screen/onboarding/view/OnboardingView.kt +++ b/ui-lib/src/main/java/cash/z/ecc/ui/screen/onboarding/view/OnboardingView.kt @@ -1,3 +1,5 @@ +@file:Suppress("TooManyFunctions") + package cash.z.ecc.ui.screen.onboarding.view import androidx.compose.foundation.Image @@ -11,13 +13,17 @@ import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.Icon +import androidx.compose.material.IconButton +import androidx.compose.material.Text +import androidx.compose.material.TopAppBar +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.painter.ColorPainter import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import cash.z.ecc.ui.R @@ -49,6 +55,10 @@ fun ComposablePreview() { } } +// Pending internal discussion on where the navigation should live. +// This toggles between the app bar or custom buttons below the app bar +private const val IS_NAVIGATION_IN_APP_BAR = false + /** * @param onImportWallet Callback when the user decides to import an existing wallet. * @param onCreateWallet Callback when the user decides to create a new wallet. @@ -60,7 +70,52 @@ fun Onboarding( onCreateWallet: () -> Unit ) { Column { - TopNavButtons(onboardingState) + OnboardingTopAppBar(onboardingState) + OnboardingMainContent(onboardingState, onImportWallet = onImportWallet, onCreateWallet = onCreateWallet) + } +} + +@Composable +private fun OnboardingTopAppBar(onboardingState: OnboardingState) { + val currentStage = onboardingState.current.collectAsState().value + + TopAppBar( + title = { Text(text = stringResource(id = R.string.app_name)) }, + navigationIcon = + if (IS_NAVIGATION_IN_APP_BAR && currentStage.hasPrevious()) { + { + IconButton(onboardingState::goPrevious) { + Icon( + imageVector = Icons.Filled.ArrowBack, + contentDescription = stringResource(R.string.onboarding_back) + ) + } + } + } else { + null + }, + actions = { + if (IS_NAVIGATION_IN_APP_BAR && currentStage.hasNext()) { + NavigationButton(onboardingState::goToEnd, stringResource(R.string.onboarding_skip)) + } + } + ) +} + +/** + * @param onImportWallet Callback when the user decides to import an existing wallet. + * @param onCreateWallet Callback when the user decides to create a new wallet. + */ +@Composable +fun OnboardingMainContent( + onboardingState: OnboardingState, + onImportWallet: () -> Unit, + onCreateWallet: () -> Unit +) { + Column { + if (!IS_NAVIGATION_IN_APP_BAR) { + TopNavButtons(onboardingState) + } val onboardingStage = onboardingState.current.collectAsState().value @@ -81,7 +136,8 @@ fun Onboarding( @Composable private fun TopNavButtons(onboardingState: OnboardingState) { Row { - if (onboardingState.hasPrevious()) { + val currentStage = onboardingState.current.collectAsState().value + if (currentStage.hasPrevious()) { NavigationButton(onboardingState::goPrevious, stringResource(R.string.onboarding_back)) } @@ -91,7 +147,7 @@ private fun TopNavButtons(onboardingState: OnboardingState) { .weight(MINIMAL_WEIGHT, true) ) - if (onboardingState.hasNext()) { + if (currentStage.hasNext()) { NavigationButton(onboardingState::goToEnd, stringResource(R.string.onboarding_skip)) } } @@ -101,7 +157,11 @@ private fun TopNavButtons(onboardingState: OnboardingState) { private fun BottomNav(progress: Progress, onNext: () -> Unit) { if (progress.current != progress.last) { Column { - Spacer(modifier = Modifier.fillMaxHeight().weight(MINIMAL_WEIGHT, true)) + Spacer( + modifier = Modifier + .fillMaxHeight() + .weight(MINIMAL_WEIGHT, true) + ) SecondaryButton(onNext, stringResource(R.string.onboarding_next), Modifier.fillMaxWidth()) @@ -117,7 +177,7 @@ private fun BottomNav(progress: Progress, onNext: () -> Unit) { private fun ShieldedByDefault() { Column { Content( - image = ColorPainter(Color.Blue), + image = painterResource(id = R.drawable.onboarding_1_shielded), imageContentDescription = stringResource(R.string.onboarding_1_image_content_description), headline = stringResource(R.string.onboarding_1_header), body = stringResource(R.string.onboarding_1_body) @@ -129,7 +189,7 @@ private fun ShieldedByDefault() { private fun UnifiedAddresses() { Column { Content( - image = ColorPainter(Color.Blue), + image = painterResource(id = R.drawable.onboarding_2_unified), imageContentDescription = stringResource(R.string.onboarding_2_image_content_description), headline = stringResource(R.string.onboarding_2_header), body = stringResource(R.string.onboarding_2_body) @@ -141,7 +201,7 @@ private fun UnifiedAddresses() { private fun More() { Column { Content( - image = ColorPainter(Color.Blue), + image = painterResource(id = R.drawable.onboarding_3_more), imageContentDescription = stringResource(R.string.onboarding_3_image_content_description), headline = stringResource(R.string.onboarding_3_header), body = stringResource(R.string.onboarding_3_body) diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_1_shielded.webp b/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_1_shielded.webp new file mode 100644 index 00000000..a4fa97b6 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_1_shielded.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_2_unified.webp b/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_2_unified.webp new file mode 100644 index 00000000..d66085f4 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_2_unified.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_3_more.webp b/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_3_more.webp new file mode 100644 index 00000000..395a7285 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-hdpi/onboarding_3_more.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_1_shielded.webp b/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_1_shielded.webp new file mode 100644 index 00000000..7ca38d80 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_1_shielded.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_2_unified.webp b/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_2_unified.webp new file mode 100644 index 00000000..757021ff Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_2_unified.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_3_more.webp b/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_3_more.webp new file mode 100644 index 00000000..9ee4ff4b Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-mdpi/onboarding_3_more.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_1_shielded.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_1_shielded.webp new file mode 100644 index 00000000..4bf194cb Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_1_shielded.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_2_unified.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_2_unified.webp new file mode 100644 index 00000000..61a1784d Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_2_unified.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_3_more.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_3_more.webp new file mode 100644 index 00000000..d01f5235 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xhdpi/onboarding_3_more.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_1_shielded.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_1_shielded.webp new file mode 100644 index 00000000..286a44e2 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_1_shielded.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_2_unified.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_2_unified.webp new file mode 100644 index 00000000..561bd837 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_2_unified.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_3_more.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_3_more.webp new file mode 100644 index 00000000..7361dc86 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xxhdpi/onboarding_3_more.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_1_shielded.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_1_shielded.webp new file mode 100644 index 00000000..10429f1d Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_1_shielded.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_2_unified.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_2_unified.webp new file mode 100644 index 00000000..e33aea9c Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_2_unified.webp differ diff --git a/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_3_more.webp b/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_3_more.webp new file mode 100644 index 00000000..85e68f83 Binary files /dev/null and b/ui-lib/src/main/res/ui/onboarding/drawable-xxxhdpi/onboarding_3_more.webp differ