Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Dec 9, 2024
1 parent 2c92f33 commit b755333
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.financialconnections.example

import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -92,6 +93,9 @@ class FinancialConnectionsLauncherActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

setContent {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}
FinancialConnectionsExampleTheme {
MainScreen(items = items)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stripe.android.financialconnections.example

import android.os.Build
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
Expand Down Expand Up @@ -95,6 +96,9 @@ class FinancialConnectionsPlaygroundActivity : AppCompatActivity() {
)

setContent {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}
FinancialConnectionsExampleTheme {
FinancialConnectionsScreen()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stripe.android.identity.example

import android.content.ContentResolver
import android.net.Uri
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -31,6 +32,9 @@ abstract class ComposeExampleActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}
MaterialTheme {
ExampleScreen(
configuration = configuration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.paymentsheet.example

import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -102,6 +103,9 @@ class MainActivity : AppCompatActivity() {
setContentView(viewBinding.root)
setSupportActionBar(viewBinding.toolbar)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}
viewBinding.content.setContent {
PaymentSheetExampleTheme {
MainScreen(items = items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
Expand Down Expand Up @@ -57,6 +62,11 @@ internal class CustomerSheetExampleActivity : AppCompatActivity() {

Column(
modifier = Modifier
.padding(
paddingValues = WindowInsets.systemBars.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Top
).asPaddingValues()
)
.fillMaxSize()
.padding(16.dp)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.google.android.material.snackbar.Snackbar
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.example.samples.ui.shared.BuyButton
Expand Down Expand Up @@ -57,6 +64,12 @@ internal class CompleteFlowActivity : AppCompatActivity() {
}

Receipt(
modifier = Modifier
.padding(
paddingValues = WindowInsets.systemBars.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Top
).asPaddingValues()
),
isLoading = uiState.isProcessing,
cartState = uiState.cartState,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.google.android.material.snackbar.Snackbar
import com.stripe.android.paymentsheet.PaymentSheet
Expand Down Expand Up @@ -64,26 +72,35 @@ internal class CustomFlowActivity : AppCompatActivity() {
}
}

if (uiState.isError) {
ErrorScreen(onRetry = viewModel::retry)
} else {
Receipt(
isLoading = uiState.isProcessing,
cartState = uiState.cartState,
) {
PaymentMethodSelector(
isEnabled = uiState.isPaymentMethodButtonEnabled,
paymentMethodLabel = paymentMethodLabel,
paymentMethodPainter = uiState.paymentOption?.iconPainter,
onClick = flowController::presentPaymentOptions,
)
BuyButton(
buyButtonEnabled = uiState.isBuyButtonEnabled,
onClick = {
viewModel.handleBuyButtonPressed()
flowController.confirm()
}
)
Box(
modifier = Modifier
.padding(
paddingValues = WindowInsets.systemBars.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Top
).asPaddingValues()
),
) {
if (uiState.isError) {
ErrorScreen(onRetry = viewModel::retry)
} else {
Receipt(
isLoading = uiState.isProcessing,
cartState = uiState.cartState,
) {
PaymentMethodSelector(
isEnabled = uiState.isPaymentMethodButtonEnabled,
paymentMethodLabel = paymentMethodLabel,
paymentMethodPainter = uiState.paymentOption?.iconPainter,
onClick = flowController::presentPaymentOptions,
)
BuyButton(
buyButtonEnabled = uiState.isBuyButtonEnabled,
onClick = {
viewModel.handleBuyButtonPressed()
flowController.confirm()
}
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.google.android.material.snackbar.Snackbar
import com.stripe.android.paymentsheet.example.samples.model.toIntentConfiguration
import com.stripe.android.paymentsheet.example.samples.ui.shared.BuyButton
Expand Down Expand Up @@ -53,29 +61,38 @@ internal class ServerSideConfirmationCompleteFlowActivity : AppCompatActivity()
}
}

if (uiState.isError) {
ErrorScreen(onRetry = viewModel::retry)
} else {
Receipt(
isLoading = uiState.isProcessing,
cartState = uiState.cartState,
isEditable = true,
onQuantityChanged = viewModel::updateQuantity,
) {
SubscriptionToggle(
checked = uiState.cartState.isSubscription,
onCheckedChange = viewModel::updateSubscription,
)
Box(
modifier = Modifier
.padding(
paddingValues = WindowInsets.systemBars.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Top
).asPaddingValues()
),
) {
if (uiState.isError) {
ErrorScreen(onRetry = viewModel::retry)
} else {
Receipt(
isLoading = uiState.isProcessing,
cartState = uiState.cartState,
isEditable = true,
onQuantityChanged = viewModel::updateQuantity,
) {
SubscriptionToggle(
checked = uiState.cartState.isSubscription,
onCheckedChange = viewModel::updateSubscription,
)

BuyButton(
buyButtonEnabled = uiState.isBuyButtonEnabled,
onClick = {
paymentSheet.presentWithIntentConfiguration(
intentConfiguration = uiState.cartState.toIntentConfiguration(),
configuration = uiState.paymentSheetConfig,
)
}
)
BuyButton(
buyButtonEnabled = uiState.isBuyButtonEnabled,
onClick = {
paymentSheet.presentWithIntentConfiguration(
intentConfiguration = uiState.cartState.toIntentConfiguration(),
configuration = uiState.paymentSheetConfig,
)
}
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.google.android.material.snackbar.Snackbar
import com.stripe.android.paymentsheet.PaymentSheet
Expand Down Expand Up @@ -66,34 +74,43 @@ internal class ServerSideConfirmationCustomFlowActivity : AppCompatActivity() {
}
}

if (uiState.isError) {
ErrorScreen(onRetry = viewModel::retry)
} else {
Receipt(
isLoading = uiState.isProcessing,
cartState = uiState.cartState,
isEditable = true,
onQuantityChanged = viewModel::updateQuantity,
) {
PaymentMethodSelector(
isEnabled = uiState.isPaymentMethodButtonEnabled,
paymentMethodLabel = paymentMethodLabel,
paymentMethodPainter = uiState.paymentOption?.iconPainter,
onClick = flowController::presentPaymentOptions,
)
Box(
modifier = Modifier
.padding(
paddingValues = WindowInsets.systemBars.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Top
).asPaddingValues()
),
) {
if (uiState.isError) {
ErrorScreen(onRetry = viewModel::retry)
} else {
Receipt(
isLoading = uiState.isProcessing,
cartState = uiState.cartState,
isEditable = true,
onQuantityChanged = viewModel::updateQuantity,
) {
PaymentMethodSelector(
isEnabled = uiState.isPaymentMethodButtonEnabled,
paymentMethodLabel = paymentMethodLabel,
paymentMethodPainter = uiState.paymentOption?.iconPainter,
onClick = flowController::presentPaymentOptions,
)

SubscriptionToggle(
checked = uiState.cartState.isSubscription,
onCheckedChange = viewModel::updateSubscription,
)
SubscriptionToggle(
checked = uiState.cartState.isSubscription,
onCheckedChange = viewModel::updateSubscription,
)

BuyButton(
buyButtonEnabled = uiState.isBuyButtonEnabled,
onClick = {
viewModel.handleBuyButtonPressed()
flowController.confirm()
}
)
BuyButton(
buyButtonEnabled = uiState.isBuyButtonEnabled,
onClick = {
viewModel.handleBuyButtonPressed()
flowController.confirm()
}
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.stripe.android.paymentsheet.example.samples.ui.SUB_FONT_SIZE

@Composable
fun Receipt(
modifier: Modifier = Modifier,
isLoading: Boolean,
cartState: CartState,
isEditable: Boolean = false,
Expand All @@ -48,6 +49,7 @@ fun Receipt(
) {
val scrollState = rememberScrollState()
Surface(
modifier = modifier,
color = MaterialTheme.colors.background,
) {
Column(
Expand Down

0 comments on commit b755333

Please sign in to comment.