-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Connect SDK] UI for Connect SDK Example App (#9276)
* Build UI of example app # Conflicts: # gradle.properties * Update build.gradle to use version catalog * Update EmbeddedComponentService.kt * Update PayoutsExampleActivity.kt * Update AccountOnboardingExampleActivity.kt * Fix dependencies * Fix lint * Fix fetch client secret * Fix lint * Fix lint * Move to color/string res * fix color values
- Loading branch information
1 parent
8f35fe0
commit 5fce962
Showing
13 changed files
with
419 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
android:exported="true" | ||
android:theme="@style/Theme.AppCompat.Light.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity | ||
android:name=".ui.accountonboarding.AccountOnboardingExampleActivity" | ||
android:exported="false" | ||
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> | ||
<activity | ||
android:name=".ui.payouts.PayoutsExampleActivity" | ||
android:exported="false" | ||
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> | ||
</application> | ||
</manifest> |
188 changes: 147 additions & 41 deletions
188
stripe-connect-example/src/main/java/com/stripe/android/connectsdk/example/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,175 @@ | ||
package com.stripe.android.connectsdk.example | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.LazyItemScope | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.Text | ||
import com.stripe.android.connectsdk.EmbeddedComponentManager | ||
import com.stripe.android.connectsdk.FetchClientSecretCallback | ||
import com.stripe.android.connectsdk.FetchClientSecretCallback.ClientSecretResultCallback | ||
import com.stripe.android.connectsdk.PrivateBetaConnectSDK | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.KeyboardArrowRight | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.LineHeightStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.stripe.android.connectsdk.example.ui.accountonboarding.AccountOnboardingExampleActivity | ||
import com.stripe.android.connectsdk.example.ui.payouts.PayoutsExampleActivity | ||
|
||
@OptIn(PrivateBetaConnectSDK::class) | ||
class MainActivity : ComponentActivity() { | ||
|
||
private lateinit var embeddedComponentManager: EmbeddedComponentManager | ||
private data class MenuItem( | ||
val title: String, | ||
val subtitle: String, | ||
val activity: Class<out ComponentActivity>, | ||
val isBeta: Boolean = false, | ||
) | ||
|
||
private val menuItems = listOf( | ||
MenuItem( | ||
title = resources.getString(R.string.account_onboarding), | ||
subtitle = resources.getString(R.string.account_onboarding_menu_subtitle), | ||
activity = AccountOnboardingExampleActivity::class.java, | ||
isBeta = true, | ||
), | ||
MenuItem( | ||
title = resources.getString(R.string.payouts), | ||
subtitle = resources.getString(R.string.payouts_menu_subtitle), | ||
activity = PayoutsExampleActivity::class.java, | ||
isBeta = true, | ||
), | ||
) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
embeddedComponentManager = EmbeddedComponentManager( | ||
activity = this, | ||
configuration = EmbeddedComponentManager.Configuration( | ||
publishableKey = "<publishable key here>" | ||
), | ||
fetchClientSecret = object : FetchClientSecretCallback { | ||
override fun fetchClientSecret(resultCallback: ClientSecretResultCallback) { | ||
// Make a network call to fetch your client secret here | ||
resultCallback.onResult("<client secret here>") | ||
setContent { | ||
ConnectSdkExampleTheme { | ||
MainContent(title = stringResource(R.string.connect_sdk_example)) { | ||
ComponentList(menuItems) | ||
} | ||
} | ||
) | ||
|
||
setContent { | ||
Text("Not yet built...") | ||
} | ||
} | ||
|
||
fun launchPayouts() { | ||
// launch the payouts activity | ||
embeddedComponentManager.presentPayouts() | ||
@Composable | ||
private fun ComponentList(components: List<MenuItem>) { | ||
LazyColumn { | ||
items(components) { menuItem -> | ||
MenuRowItem(menuItem) | ||
} | ||
} | ||
} | ||
|
||
fun launchAccountOnboardingActivity() { | ||
// launch the account onboarding activity | ||
embeddedComponentManager.presentAccountOnboarding() | ||
@Composable | ||
private fun LazyItemScope.MenuRowItem(menuItem: MenuItem) { | ||
val context = LocalContext.current | ||
Row( | ||
modifier = Modifier | ||
.fillParentMaxWidth() | ||
.clickable { context.startActivity(Intent(context, menuItem.activity)) }, | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Column(modifier = Modifier.weight(1f)) { | ||
Column(modifier = Modifier.padding(8.dp)) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
) { | ||
Text( | ||
text = menuItem.title, | ||
fontSize = 16.sp, | ||
fontWeight = FontWeight.SemiBold, | ||
) | ||
if (menuItem.isBeta) { | ||
BetaBadge() | ||
} | ||
} | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
Text( | ||
|
||
text = menuItem.subtitle, | ||
fontSize = 16.sp, | ||
) | ||
} | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
Divider() | ||
} | ||
|
||
Icon( | ||
modifier = Modifier | ||
.size(36.dp) | ||
.padding(start = 8.dp), | ||
contentDescription = null, | ||
imageVector = Icons.Default.KeyboardArrowRight, | ||
) | ||
} | ||
} | ||
|
||
fun updateAppearance() { | ||
// update the appearance | ||
embeddedComponentManager.update( | ||
EmbeddedComponentManager.Appearance( | ||
typography = EmbeddedComponentManager.Appearance.Typography(), | ||
colors = EmbeddedComponentManager.Appearance.Colors(), | ||
buttonPrimary = EmbeddedComponentManager.Appearance.Button(), | ||
buttonSecondary = EmbeddedComponentManager.Appearance.Button(), | ||
badgeNeutral = EmbeddedComponentManager.Appearance.Badge(), | ||
badgeSuccess = EmbeddedComponentManager.Appearance.Badge(), | ||
badgeWarning = EmbeddedComponentManager.Appearance.Badge(), | ||
badgeDanger = EmbeddedComponentManager.Appearance.Badge(), | ||
cornerRadius = EmbeddedComponentManager.Appearance.CornerRadius() | ||
@Composable | ||
private fun BetaBadge() { | ||
val shape = RoundedCornerShape(4.dp) | ||
val labelMediumEmphasized = TextStyle.Default.copy( | ||
fontSize = 14.sp, | ||
fontWeight = FontWeight.SemiBold, | ||
lineHeight = 20.sp, | ||
lineHeightStyle = LineHeightStyle( | ||
alignment = LineHeightStyle.Alignment.Center, | ||
trim = LineHeightStyle.Trim.None | ||
) | ||
) | ||
Text( | ||
modifier = Modifier | ||
.border(1.dp, colorResource(R.color.default_border_color), shape) | ||
.background( | ||
color = colorResource(R.color.default_background_color), | ||
shape = shape | ||
) | ||
.padding(horizontal = 6.dp, vertical = 1.dp), | ||
color = colorResource(R.color.default_text_color), | ||
fontSize = 12.sp, | ||
lineHeight = 16.sp, | ||
style = labelMediumEmphasized, | ||
text = "BETA" | ||
) | ||
} | ||
|
||
fun logout() { | ||
// log out the user | ||
embeddedComponentManager.logout() | ||
@Composable | ||
@Preview(showBackground = true) | ||
fun ComponentListPreview() { | ||
ConnectSdkExampleTheme { | ||
ComponentList(menuItems) | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview(showBackground = true) | ||
fun BetaBadgePreview() { | ||
ConnectSdkExampleTheme { | ||
BetaBadge() | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
stripe-connect-example/src/main/java/com/stripe/android/connectsdk/example/Theme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.stripe.android.connectsdk.example | ||
|
||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.darkColors | ||
import androidx.compose.material.lightColors | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
|
||
@Composable | ||
fun ConnectSdkExampleTheme( | ||
content: @Composable () -> Unit, | ||
) { | ||
MaterialTheme( | ||
colors = if (isSystemInDarkTheme()) darkColors() else lightColors(), | ||
content = content, | ||
) | ||
} | ||
|
||
@Composable | ||
fun MainContent( | ||
title: String, | ||
content: @Composable () -> Unit, | ||
) { | ||
Scaffold( | ||
topBar = { | ||
Column { | ||
Text( | ||
modifier = Modifier.padding(8.dp), | ||
text = title, | ||
fontSize = 24.sp, | ||
fontWeight = FontWeight.SemiBold, | ||
) | ||
Divider() | ||
} | ||
} | ||
) { contentPadding -> | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(contentPadding), | ||
) { | ||
content() | ||
} | ||
} | ||
} |
Oops, something went wrong.