Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kotlin/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {

implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.activity:activity-compose:1.8.2")
debugImplementation("androidx.compose.ui:ui-tooling:1.1.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycleVersion")
implementation("androidx.lifecycle:lifecycle-runtime-compose:$lifecycleVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,64 @@ fun ProductScreen(
}
}
}
}

/**
* Wrapper to simplify previews with a provided description.
*/
@Composable
private fun ProductScreenPreviewWithDescription(
payUiState: PaymentUiState,
@PreviewParameter(LoremIpsum::class) description: String
) {
ProductScreen(
title = "Men's Tech Shell Full-Zip",
description = description.take(200), // Limit description to 200 characters
price = "$49.99",
image = R.drawable.ts_10_11019a,
onGooglePayButtonClick = {}, // No-op for previews
payUiState = payUiState,
)
}

/**
* Preview of ProductScreen in the initial state, where payment has not started.
*/
@Preview
@Composable
private fun ProductScreenPreviewNotStarted(
@PreviewParameter(LoremIpsum::class) description: String
) {
ProductScreenPreviewWithDescription(
payUiState = PaymentUiState.NotStarted,
description = description
)
}

/**
* Preview of ProductScreen when Google Pay is available.
*/
@Preview
@Composable
private fun ProductScreenPreviewAvailable(
@PreviewParameter(LoremIpsum::class) description: String
) {
ProductScreenPreviewWithDescription(
payUiState = PaymentUiState.Available,
description = description
)
}

/**
* Preview of ProductScreen after payment has been completed.
*/
@Preview
@Composable
private fun ProductScreenPreviewPaymentCompleted(
@PreviewParameter(LoremIpsum::class) description: String
) {
ProductScreenPreviewWithDescription(
payUiState = PaymentUiState.PaymentCompleted(payerName = "John"),
description = description
)
}