From 971a4f8cc73d78c4833a58582e650d2fa8521ec1 Mon Sep 17 00:00:00 2001 From: Kyriakos Georgiopoulos <160638587+Kyriakos-Georgiopoulos@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:29:05 +0200 Subject: [PATCH 1/2] Update CheckoutLayout.kt feat(previews): add and optimize ProductScreen previews - Added new preview functions for the ProductScreen to showcase different UI states. - Implemented a reusable helper function to centralize common setup logic. - Simplified individual previews by focusing only on their specific `payUiState`. - Ensured proper use of `@PreviewParameter` for dynamic description generation. --- .../gms/samples/pay/ui/CheckoutLayout.kt | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/kotlin/app/src/main/java/com/google/android/gms/samples/pay/ui/CheckoutLayout.kt b/kotlin/app/src/main/java/com/google/android/gms/samples/pay/ui/CheckoutLayout.kt index 7a7774d..62dac99 100644 --- a/kotlin/app/src/main/java/com/google/android/gms/samples/pay/ui/CheckoutLayout.kt +++ b/kotlin/app/src/main/java/com/google/android/gms/samples/pay/ui/CheckoutLayout.kt @@ -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 + ) } \ No newline at end of file From c6684c1aea59992038ae5b3010ec6d127ea02576 Mon Sep 17 00:00:00 2001 From: Kyriakos Georgiopoulos <160638587+Kyriakos-Georgiopoulos@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:50:02 +0200 Subject: [PATCH 2/2] Update build.gradle.kts --- kotlin/app/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/kotlin/app/build.gradle.kts b/kotlin/app/build.gradle.kts index 48ae47e..a02fcf2 100644 --- a/kotlin/app/build.gradle.kts +++ b/kotlin/app/build.gradle.kts @@ -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")