From 950251ce837912d087e1a5cfde5b8c0f236f9926 Mon Sep 17 00:00:00 2001 From: lalwani Date: Mon, 10 Jun 2024 14:13:37 -0700 Subject: [PATCH 1/9] Added UberAuthButton in compose --- authentication/build.gradle.kts | 8 ++ .../com/uber/sdk2/auth/ui/LoginButton.kt | 87 +++++++++++++ .../com/uber/sdk2/auth/ui/UberAuthButton.kt | 122 ++++++++++++++++++ .../res/values-hi-rIN/strings_localized.xml | 20 +++ .../res/values-zh-rCN/strings_localized.xml | 20 +++ .../res/values-zh-rHK/strings_localized.xml | 20 +++ .../res/values-zh-rTW/strings_localized.xml | 20 +++ authentication/src/main/res/values/dimens.xml | 20 +++ .../src/main/res/values/strings_localized.xml | 20 +++ authentication/src/main/res/values/styles.xml | 32 +++++ 10 files changed, 369 insertions(+) create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/ui/LoginButton.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt create mode 100644 authentication/src/main/res/values-hi-rIN/strings_localized.xml create mode 100644 authentication/src/main/res/values-zh-rCN/strings_localized.xml create mode 100644 authentication/src/main/res/values-zh-rHK/strings_localized.xml create mode 100644 authentication/src/main/res/values-zh-rTW/strings_localized.xml create mode 100644 authentication/src/main/res/values/dimens.xml create mode 100644 authentication/src/main/res/values/strings_localized.xml create mode 100644 authentication/src/main/res/values/styles.xml diff --git a/authentication/build.gradle.kts b/authentication/build.gradle.kts index 93bf9037..0a2fad64 100644 --- a/authentication/build.gradle.kts +++ b/authentication/build.gradle.kts @@ -42,9 +42,17 @@ android { } buildTypes { release { isMinifyEnabled = false } } + + buildFeatures { compose = true } + composeOptions { kotlinCompilerExtensionVersion = "1.5.11" } } dependencies { + implementation(libs.androidx.ui.tooling.preview.android) + val composeBom = platform(libs.compose.bom) + implementation(composeBom) + implementation(libs.androidx.compose.foundation) + implementation(libs.material3) implementation(libs.appCompat) implementation(libs.chrometabs) implementation(libs.material) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/LoginButton.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/LoginButton.kt new file mode 100644 index 00000000..c33d167f --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/LoginButton.kt @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2016. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.uber.sdk2.auth.ui + +import android.content.Context +import android.util.AttributeSet +import androidx.annotation.StringRes +import androidx.annotation.StyleRes +import androidx.annotation.VisibleForTesting +import com.uber.sdk2.auth.R +import com.uber.sdk2.auth.UberAuthClientImpl +import com.uber.sdk2.auth.request.AuthContext +import com.uber.sdk2.core.ui.UberStyle +import com.uber.sdk2.core.ui.legacy.UberButton + +/** The [LoginButton] is used to initiate the Uber SDK Login flow. */ +class LoginButton : UberButton { + private var authContext: AuthContext? = null + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) + + constructor( + context: Context, + attrs: AttributeSet?, + defStyleAttr: Int, + ) : super(context, attrs, defStyleAttr) + + constructor( + context: Context, + attrs: AttributeSet?, + defStyleAttr: Int, + defStyleRes: Int, + ) : super(context, attrs, defStyleAttr, defStyleRes) + + override fun init( + context: Context, + @StringRes defaultText: Int, + attrs: AttributeSet?, + defStyleAttr: Int, + uberStyle: UberStyle, + ) { + isAllCaps = true + + val defStyleRes = STYLES[uberStyle.value] + + applyStyle(context, R.string.ub__sign_in, attrs, defStyleAttr, defStyleRes) + + setOnClickListener { login() } + } + + @VisibleForTesting + fun login() { + val activity = activity + UberAuthClientImpl().authenticate(activity, authContext!!) + } + + /** + * A [AuthContext] is required to identify the app being authenticated. + * + * @param authContext to be identified. + * @return this instance of [LoginButton] + */ + fun authContext(authContext: AuthContext): LoginButton { + this.authContext = authContext + return this + } + + companion object { + @StyleRes + private val STYLES = intArrayOf(R.style.UberButton_Login, R.style.UberButton_Login_White) + } +} diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt new file mode 100644 index 00000000..5bfca854 --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt @@ -0,0 +1,122 @@ +package com.uber.sdk2.auth.ui + +import android.media.Image +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsPressedAsState +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.res.colorResource +import androidx.compose.ui.res.dimensionResource +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.uber.sdk2.core.R + +/** A button that looks like the Uber button. */ +@Composable +fun UberCustomButton( + text: String, + isWhite: Boolean = false, + onClick: () -> Unit +) { + val interactionSource = remember { MutableInteractionSource() } + val isPressed = interactionSource.collectIsPressedAsState().value + val backgroundColor = if (isPressed) { + if (isWhite) colorResource(id = R.color.uber_white_40) else colorResource(id = R.color.uber_black_90) + } else { + if (isWhite) colorResource(id = R.color.uber_white) else colorResource(id = R.color.uber_black) + } + + val textColor = if (isWhite) { + colorResource(id = R.color.uber_black) + } else { + colorResource(id = R.color.uber_white) + } + + Text( + text = text, + color = textColor, + style = TextStyle( + fontSize = dimensionResource(id = R.dimen.ub__text_size).value.sp + ), + modifier = Modifier + .clip(RoundedCornerShape(4.dp)) + .background(backgroundColor) + .clickable(interactionSource = interactionSource, indication = null, onClick = onClick) + .padding(16.dp) + ) +} + +@Composable +fun UberAuthButton( + text: String, + isWhite: Boolean = false, + onClick: () -> Unit +) { + val interactionSource = remember { MutableInteractionSource() } + val isPressed = interactionSource.collectIsPressedAsState().value + val backgroundColor = if (isPressed) { + if (isWhite) colorResource(id = R.color.uber_white_40) else colorResource(id = R.color.uber_black_90) + } else { + if (isWhite) colorResource(id = R.color.uber_white) else colorResource(id = R.color.uber_black) + } + + val textColor = if (isWhite) { + colorResource(id = R.color.uber_black) + } else { + colorResource(id = R.color.uber_white) + } + + val logo = if (isWhite) { + painterResource(id = R.drawable.uber_logotype_black) + } else { + painterResource(id = R.drawable.uber_logotype_white) + } + + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .clip(RoundedCornerShape(4.dp)) + .background(backgroundColor) + .clickable(interactionSource = interactionSource, indication = null, onClick = onClick) + .padding(dimensionResource(id = R.dimen.ub__standard_padding)) + ) { + Image( + painter = logo, + contentDescription = null, + modifier = Modifier.padding(end = dimensionResource(id = com.uber.sdk2.auth.R.dimen.ub__signin_margin)) + ) + Text( + text = text, + color = textColor, + style = TextStyle( + fontSize = dimensionResource(id = R.dimen.ub__secondary_text_size).value.sp + ), + modifier = Modifier.weight(1f) + ) + } +} + +@Preview(showBackground = true) +@Composable +fun UberButtonPreview() { + Column { + UberCustomButton(text = "Default Uber Button", onClick = { /* Do something */ }) + UberCustomButton(text = "White Uber Button", isWhite = true, onClick = { /* Do something */ }) + UberAuthButton(text = "Sign in with Uber", onClick = { /* Do something */ }) + UberAuthButton(text = "Sign in with Uber (White)", isWhite = true, onClick = { /* Do something */ }) + } +} diff --git a/authentication/src/main/res/values-hi-rIN/strings_localized.xml b/authentication/src/main/res/values-hi-rIN/strings_localized.xml new file mode 100644 index 00000000..886d2422 --- /dev/null +++ b/authentication/src/main/res/values-hi-rIN/strings_localized.xml @@ -0,0 +1,20 @@ + + + + + साइन इन करें + diff --git a/authentication/src/main/res/values-zh-rCN/strings_localized.xml b/authentication/src/main/res/values-zh-rCN/strings_localized.xml new file mode 100644 index 00000000..26a8d8d5 --- /dev/null +++ b/authentication/src/main/res/values-zh-rCN/strings_localized.xml @@ -0,0 +1,20 @@ + + + + + 登录 + diff --git a/authentication/src/main/res/values-zh-rHK/strings_localized.xml b/authentication/src/main/res/values-zh-rHK/strings_localized.xml new file mode 100644 index 00000000..55912c52 --- /dev/null +++ b/authentication/src/main/res/values-zh-rHK/strings_localized.xml @@ -0,0 +1,20 @@ + + + + + Sign in + diff --git a/authentication/src/main/res/values-zh-rTW/strings_localized.xml b/authentication/src/main/res/values-zh-rTW/strings_localized.xml new file mode 100644 index 00000000..cd8bc4a7 --- /dev/null +++ b/authentication/src/main/res/values-zh-rTW/strings_localized.xml @@ -0,0 +1,20 @@ + + + + + 登入 + diff --git a/authentication/src/main/res/values/dimens.xml b/authentication/src/main/res/values/dimens.xml new file mode 100644 index 00000000..8323bd6f --- /dev/null +++ b/authentication/src/main/res/values/dimens.xml @@ -0,0 +1,20 @@ + + + + + 48dp + \ No newline at end of file diff --git a/authentication/src/main/res/values/strings_localized.xml b/authentication/src/main/res/values/strings_localized.xml new file mode 100644 index 00000000..55912c52 --- /dev/null +++ b/authentication/src/main/res/values/strings_localized.xml @@ -0,0 +1,20 @@ + + + + + Sign in + diff --git a/authentication/src/main/res/values/styles.xml b/authentication/src/main/res/values/styles.xml new file mode 100644 index 00000000..93fcffe9 --- /dev/null +++ b/authentication/src/main/res/values/styles.xml @@ -0,0 +1,32 @@ + + + + + + + + \ No newline at end of file From 52f2ef93d5487491a492bf65a5f1e1e954e66f8e Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 12 Jun 2024 14:32:38 -0700 Subject: [PATCH 2/9] upgraded libs and modified UberAuthButton to wrap content and customize shape --- .../com/uber/sdk2/auth/ui/UberAuthButton.kt | 89 +++++-------------- .../uber/sdk2/core/utils/CustomTabsHelper.kt | 5 +- gradle/libs.versions.toml | 2 +- settings.gradle.kts | 1 + 4 files changed, 26 insertions(+), 71 deletions(-) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt index 5bfca854..6cf3ffe1 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt @@ -1,21 +1,23 @@ package com.uber.sdk2.auth.ui -import android.media.Image -import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsPressedAsState import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.wrapContentSize +import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Shape import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.painterResource @@ -25,49 +27,16 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.uber.sdk2.core.R -/** A button that looks like the Uber button. */ -@Composable -fun UberCustomButton( - text: String, - isWhite: Boolean = false, - onClick: () -> Unit -) { - val interactionSource = remember { MutableInteractionSource() } - val isPressed = interactionSource.collectIsPressedAsState().value - val backgroundColor = if (isPressed) { - if (isWhite) colorResource(id = R.color.uber_white_40) else colorResource(id = R.color.uber_black_90) - } else { - if (isWhite) colorResource(id = R.color.uber_white) else colorResource(id = R.color.uber_black) - } - - val textColor = if (isWhite) { - colorResource(id = R.color.uber_black) - } else { - colorResource(id = R.color.uber_white) - } - - Text( - text = text, - color = textColor, - style = TextStyle( - fontSize = dimensionResource(id = R.dimen.ub__text_size).value.sp - ), - modifier = Modifier - .clip(RoundedCornerShape(4.dp)) - .background(backgroundColor) - .clickable(interactionSource = interactionSource, indication = null, onClick = onClick) - .padding(16.dp) - ) -} - @Composable fun UberAuthButton( text: String, isWhite: Boolean = false, + shape: Shape = RoundedCornerShape(4.dp), onClick: () -> Unit ) { val interactionSource = remember { MutableInteractionSource() } val isPressed = interactionSource.collectIsPressedAsState().value + val backgroundColor = if (isPressed) { if (isWhite) colorResource(id = R.color.uber_white_40) else colorResource(id = R.color.uber_black_90) } else { @@ -80,43 +49,27 @@ fun UberAuthButton( colorResource(id = R.color.uber_white) } - val logo = if (isWhite) { - painterResource(id = R.drawable.uber_logotype_black) - } else { - painterResource(id = R.drawable.uber_logotype_white) - } + val iconResId = if (isWhite) R.drawable.uber_logotype_black else R.drawable.uber_logotype_white - Row( - verticalAlignment = Alignment.CenterVertically, + Button( + onClick = onClick, modifier = Modifier - .clip(RoundedCornerShape(4.dp)) - .background(backgroundColor) - .clickable(interactionSource = interactionSource, indication = null, onClick = onClick) - .padding(dimensionResource(id = R.dimen.ub__standard_padding)) + .wrapContentSize(), + colors = ButtonDefaults.buttonColors(containerColor = backgroundColor, contentColor = textColor), + shape = RoundedCornerShape(4.dp) ) { - Image( - painter = logo, + Icon( + painter = painterResource(id = iconResId), contentDescription = null, modifier = Modifier.padding(end = dimensionResource(id = com.uber.sdk2.auth.R.dimen.ub__signin_margin)) ) Text( - text = text, + text = text.uppercase(), color = textColor, - style = TextStyle( - fontSize = dimensionResource(id = R.dimen.ub__secondary_text_size).value.sp - ), - modifier = Modifier.weight(1f) + style = TextStyle(fontSize = dimensionResource(id = R.dimen.ub__secondary_text_size).value.sp), + modifier = Modifier + .padding(dimensionResource(id = R.dimen.ub__standard_padding)) + .wrapContentWidth() ) } } - -@Preview(showBackground = true) -@Composable -fun UberButtonPreview() { - Column { - UberCustomButton(text = "Default Uber Button", onClick = { /* Do something */ }) - UberCustomButton(text = "White Uber Button", isWhite = true, onClick = { /* Do something */ }) - UberAuthButton(text = "Sign in with Uber", onClick = { /* Do something */ }) - UberAuthButton(text = "Sign in with Uber (White)", isWhite = true, onClick = { /* Do something */ }) - } -} diff --git a/core/src/main/kotlin/com/uber/sdk2/core/utils/CustomTabsHelper.kt b/core/src/main/kotlin/com/uber/sdk2/core/utils/CustomTabsHelper.kt index cbe5fe28..57c2fccf 100644 --- a/core/src/main/kotlin/com/uber/sdk2/core/utils/CustomTabsHelper.kt +++ b/core/src/main/kotlin/com/uber/sdk2/core/utils/CustomTabsHelper.kt @@ -48,10 +48,10 @@ object CustomTabsHelper { ) { val packageName = getPackageNameToUse(context) if (packageName != null) { - connection = + val connection = object : CustomTabsServiceConnection() { override fun onCustomTabsServiceConnected( - componentName: ComponentName?, + componentName: ComponentName, client: CustomTabsClient, ) { client.warmup(0L) // This prevents backgrounding after redirection @@ -63,6 +63,7 @@ object CustomTabsHelper { override fun onServiceDisconnected(name: ComponentName?) {} } CustomTabsClient.bindCustomTabsService(context, packageName, connection) + this.connection = connection } else fallback?.openUri(context, uri) ?: Log.e( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e234dfa8..1c9000fc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ [versions] agp = "8.2.2" -androidxVersion = "1.0.0" +androidxVersion = "1.7.0" uberJava = "0.8.5" mavenPublish = "0.27.0" kotlin = "1.9.23" diff --git a/settings.gradle.kts b/settings.gradle.kts index 165cf445..4d6a9505 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -45,6 +45,7 @@ include( ":core", ":core-android", ":rides-android", + ":samples:auth-demo", ":samples:request-button-sample", ":samples:login-sample", ":samples:login-with-auth-code-demo", From cad424753e79e474a5e163262fabe40ef4863f75 Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 12 Jun 2024 14:35:19 -0700 Subject: [PATCH 3/9] spotless --- .../com/uber/sdk2/auth/ui/UberAuthButton.kt | 93 +++++++++++-------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt index 6cf3ffe1..625a8e3f 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt @@ -1,10 +1,22 @@ +/* + * Copyright (C) 2024. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.uber.sdk2.auth.ui -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsPressedAsState -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.layout.wrapContentWidth @@ -16,60 +28,63 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Shape import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.uber.sdk2.core.R @Composable fun UberAuthButton( - text: String, - isWhite: Boolean = false, - shape: Shape = RoundedCornerShape(4.dp), - onClick: () -> Unit + text: String, + isWhite: Boolean = false, + shape: Shape = RoundedCornerShape(4.dp), + onClick: () -> Unit, ) { - val interactionSource = remember { MutableInteractionSource() } - val isPressed = interactionSource.collectIsPressedAsState().value + val interactionSource = remember { MutableInteractionSource() } + val isPressed = interactionSource.collectIsPressedAsState().value - val backgroundColor = if (isPressed) { - if (isWhite) colorResource(id = R.color.uber_white_40) else colorResource(id = R.color.uber_black_90) + val backgroundColor = + if (isPressed) { + if (isWhite) colorResource(id = R.color.uber_white_40) + else colorResource(id = R.color.uber_black_90) } else { - if (isWhite) colorResource(id = R.color.uber_white) else colorResource(id = R.color.uber_black) + if (isWhite) colorResource(id = R.color.uber_white) + else colorResource(id = R.color.uber_black) } - val textColor = if (isWhite) { - colorResource(id = R.color.uber_black) + val textColor = + if (isWhite) { + colorResource(id = R.color.uber_black) } else { - colorResource(id = R.color.uber_white) + colorResource(id = R.color.uber_white) } - val iconResId = if (isWhite) R.drawable.uber_logotype_black else R.drawable.uber_logotype_white + val iconResId = if (isWhite) R.drawable.uber_logotype_black else R.drawable.uber_logotype_white - Button( - onClick = onClick, - modifier = Modifier - .wrapContentSize(), - colors = ButtonDefaults.buttonColors(containerColor = backgroundColor, contentColor = textColor), - shape = RoundedCornerShape(4.dp) - ) { - Icon( - painter = painterResource(id = iconResId), - contentDescription = null, - modifier = Modifier.padding(end = dimensionResource(id = com.uber.sdk2.auth.R.dimen.ub__signin_margin)) - ) - Text( - text = text.uppercase(), - color = textColor, - style = TextStyle(fontSize = dimensionResource(id = R.dimen.ub__secondary_text_size).value.sp), - modifier = Modifier - .padding(dimensionResource(id = R.dimen.ub__standard_padding)) - .wrapContentWidth() - ) - } + Button( + onClick = onClick, + modifier = Modifier.wrapContentSize(), + colors = + ButtonDefaults.buttonColors(containerColor = backgroundColor, contentColor = textColor), + shape = RoundedCornerShape(4.dp), + ) { + Icon( + painter = painterResource(id = iconResId), + contentDescription = null, + modifier = + Modifier.padding(end = dimensionResource(id = com.uber.sdk2.auth.R.dimen.ub__signin_margin)), + ) + Text( + text = text.uppercase(), + color = textColor, + style = + TextStyle(fontSize = dimensionResource(id = R.dimen.ub__secondary_text_size).value.sp), + modifier = + Modifier.padding(dimensionResource(id = R.dimen.ub__standard_padding)).wrapContentWidth(), + ) + } } From f970b6849bfebe12baf9e6a15ee22c456e05d9bf Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 12 Jun 2024 14:41:24 -0700 Subject: [PATCH 4/9] updating the old sample app to comply with lib upgrades --- .../java/com/uber/sdk/android/samples/LoginSampleActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/login-sample/src/main/java/com/uber/sdk/android/samples/LoginSampleActivity.java b/samples/login-sample/src/main/java/com/uber/sdk/android/samples/LoginSampleActivity.java index ac28664a..5ab10550 100644 --- a/samples/login-sample/src/main/java/com/uber/sdk/android/samples/LoginSampleActivity.java +++ b/samples/login-sample/src/main/java/com/uber/sdk/android/samples/LoginSampleActivity.java @@ -147,6 +147,7 @@ protected void onResume() { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); Log.i(LOG_TAG, String.format("onActivityResult requestCode:[%s] resultCode [%s]", requestCode, resultCode)); From 4d795c51708b2d85b8a1d8c6ffe9a90cc4ee263f Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 12 Jun 2024 14:44:57 -0700 Subject: [PATCH 5/9] Removing customization for auth button text --- .../src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt index 625a8e3f..3481ca74 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt @@ -32,6 +32,7 @@ import androidx.compose.ui.graphics.Shape import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -39,11 +40,11 @@ import com.uber.sdk2.core.R @Composable fun UberAuthButton( - text: String, isWhite: Boolean = false, shape: Shape = RoundedCornerShape(4.dp), onClick: () -> Unit, ) { + val text = stringResource(id = com.uber.sdk2.auth.R.string.ub__sign_in) val interactionSource = remember { MutableInteractionSource() } val isPressed = interactionSource.collectIsPressedAsState().value From c4ae823b9dd071a734e226ecb79ddb14a0c8d458 Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 12 Jun 2024 14:58:07 -0700 Subject: [PATCH 6/9] updating the old sample app to comply with lib upgrades --- .../src/main/java/com/uber/sdk/android/samples/DemoActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/login-with-auth-code-demo/src/main/java/com/uber/sdk/android/samples/DemoActivity.java b/samples/login-with-auth-code-demo/src/main/java/com/uber/sdk/android/samples/DemoActivity.java index b9b2c2bd..d8d53d57 100644 --- a/samples/login-with-auth-code-demo/src/main/java/com/uber/sdk/android/samples/DemoActivity.java +++ b/samples/login-with-auth-code-demo/src/main/java/com/uber/sdk/android/samples/DemoActivity.java @@ -92,6 +92,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); Log.i(LOG_TAG, String.format("onActivityResult requestCode:[%s] resultCode [%s]", requestCode, resultCode)); if (data != null) { From 95e0a1996b5389016fba6bb20d4484966e11cb93 Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 26 Jun 2024 16:17:58 -0700 Subject: [PATCH 7/9] added material theme design --- .../com/uber/sdk2/auth/ui/UberAuthButton.kt | 39 +++++-------- .../auth/ui/theme/UberButtonAttributes.kt | 33 +++++++++++ .../sdk2/auth/ui/theme/UberColorPalette.kt | 23 ++++++++ .../com/uber/sdk2/auth/ui/theme/UberTheme.kt | 57 +++++++++++++++++++ .../uber/sdk2/auth/ui/theme/UberTypography.kt | 27 +++++++++ 5 files changed, 155 insertions(+), 24 deletions(-) create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberButtonAttributes.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberColorPalette.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTheme.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTypography.kt diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt index 3481ca74..a27ad640 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt @@ -20,28 +20,29 @@ import androidx.compose.foundation.interaction.collectIsPressedAsState import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.layout.wrapContentWidth -import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Shape -import androidx.compose.ui.res.colorResource -import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp +import com.uber.sdk2.auth.ui.theme.UberBlack +import com.uber.sdk2.auth.ui.theme.UberBlack90 +import com.uber.sdk2.auth.ui.theme.UberDimens +import com.uber.sdk2.auth.ui.theme.UberTypography +import com.uber.sdk2.auth.ui.theme.UberWhite +import com.uber.sdk2.auth.ui.theme.UberWhite40 import com.uber.sdk2.core.R @Composable fun UberAuthButton( isWhite: Boolean = false, - shape: Shape = RoundedCornerShape(4.dp), + shape: Shape = MaterialTheme.shapes.small, onClick: () -> Unit, ) { val text = stringResource(id = com.uber.sdk2.auth.R.string.ub__sign_in) @@ -50,19 +51,12 @@ fun UberAuthButton( val backgroundColor = if (isPressed) { - if (isWhite) colorResource(id = R.color.uber_white_40) - else colorResource(id = R.color.uber_black_90) + if (isWhite) UberWhite40 else UberBlack90 } else { - if (isWhite) colorResource(id = R.color.uber_white) - else colorResource(id = R.color.uber_black) + if (isWhite) UberWhite else UberBlack } - val textColor = - if (isWhite) { - colorResource(id = R.color.uber_black) - } else { - colorResource(id = R.color.uber_white) - } + val textColor = MaterialTheme.colorScheme.onPrimary val iconResId = if (isWhite) R.drawable.uber_logotype_black else R.drawable.uber_logotype_white @@ -71,21 +65,18 @@ fun UberAuthButton( modifier = Modifier.wrapContentSize(), colors = ButtonDefaults.buttonColors(containerColor = backgroundColor, contentColor = textColor), - shape = RoundedCornerShape(4.dp), + shape = shape, ) { Icon( painter = painterResource(id = iconResId), contentDescription = null, - modifier = - Modifier.padding(end = dimensionResource(id = com.uber.sdk2.auth.R.dimen.ub__signin_margin)), + modifier = Modifier.padding(end = UberDimens.signInMargin), ) Text( text = text.uppercase(), color = textColor, - style = - TextStyle(fontSize = dimensionResource(id = R.dimen.ub__secondary_text_size).value.sp), - modifier = - Modifier.padding(dimensionResource(id = R.dimen.ub__standard_padding)).wrapContentWidth(), + style = UberTypography.bodySmall, + modifier = Modifier.padding(UberDimens.standardPadding).wrapContentWidth(), ) } } diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberButtonAttributes.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberButtonAttributes.kt new file mode 100644 index 00000000..22e9bfbc --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberButtonAttributes.kt @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.uber.sdk2.auth.ui.theme + +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Shapes +import androidx.compose.ui.unit.dp + +val UberButtonShapes = + Shapes( + small = RoundedCornerShape(4.dp), + medium = RoundedCornerShape(8.dp), + large = RoundedCornerShape(4.dp), + ) + +object UberDimens { + val smallPadding = 8.dp + val standardPadding = 16.dp + val signInMargin = 48.dp +} diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberColorPalette.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberColorPalette.kt new file mode 100644 index 00000000..c8789a40 --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberColorPalette.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.uber.sdk2.auth.ui.theme + +import androidx.compose.ui.graphics.Color + +val UberBlack = Color(0xFF000000) +val UberBlack90 = Color(0xFF282727) +val UberWhite = Color(0xFFFFFFFF) +val UberWhite40 = Color(0xFFE5E5E4) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTheme.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTheme.kt new file mode 100644 index 00000000..60ce6aad --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTheme.kt @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2024. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.uber.sdk2.auth.ui.theme + +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable + +@Composable +fun UberTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) { + val colors = + if (darkTheme) { + darkColorScheme( + primary = UberBlack, + onPrimary = UberWhite, + secondary = UberWhite, + onSecondary = UberBlack, + background = UberBlack90, + surface = UberBlack90, + onBackground = UberWhite, + onSurface = UberWhite, + ) + } else { + lightColorScheme( + primary = UberBlack, + onPrimary = UberWhite, + secondary = UberBlack90, + onSecondary = UberWhite, + background = UberWhite, + surface = UberWhite40, + onBackground = UberBlack, + onSurface = UberBlack, + ) + } + + MaterialTheme( + colorScheme = colors, + typography = UberTypography, + shapes = UberButtonShapes, + content = content, + ) +} diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTypography.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTypography.kt new file mode 100644 index 00000000..94ae9caa --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTypography.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024. Uber Technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.uber.sdk2.auth.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.unit.sp + +val UberTypography = + Typography( + bodySmall = TextStyle(fontSize = 12.sp), + bodyMedium = TextStyle(fontSize = 14.sp), + bodyLarge = TextStyle(fontSize = 20.sp), + ) From 90236f828432f0659d8e68629c4e56c4532a08e9 Mon Sep 17 00:00:00 2001 From: lalwani Date: Thu, 27 Jun 2024 06:55:42 -0700 Subject: [PATCH 8/9] created a compose theme to avoid using resource dimens. addressed comments --- .../com/uber/sdk2/auth/ui/UberAuthButton.kt | 16 +++++--------- .../auth/ui/theme/UberButtonAttributes.kt | 2 +- .../com/uber/sdk2/auth/ui/theme/UberTheme.kt | 22 ++----------------- authentication/src/main/res/values/dimens.xml | 20 ----------------- 4 files changed, 9 insertions(+), 51 deletions(-) delete mode 100644 authentication/src/main/res/values/dimens.xml diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt index a27ad640..072281ce 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/UberAuthButton.kt @@ -31,32 +31,27 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Shape import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import com.uber.sdk2.auth.ui.theme.UberBlack -import com.uber.sdk2.auth.ui.theme.UberBlack90 import com.uber.sdk2.auth.ui.theme.UberDimens import com.uber.sdk2.auth.ui.theme.UberTypography -import com.uber.sdk2.auth.ui.theme.UberWhite -import com.uber.sdk2.auth.ui.theme.UberWhite40 import com.uber.sdk2.core.R @Composable fun UberAuthButton( isWhite: Boolean = false, - shape: Shape = MaterialTheme.shapes.small, + shape: Shape = MaterialTheme.shapes.large, onClick: () -> Unit, ) { val text = stringResource(id = com.uber.sdk2.auth.R.string.ub__sign_in) val interactionSource = remember { MutableInteractionSource() } val isPressed = interactionSource.collectIsPressedAsState().value - val backgroundColor = if (isPressed) { - if (isWhite) UberWhite40 else UberBlack90 + MaterialTheme.colorScheme.onSecondary } else { - if (isWhite) UberWhite else UberBlack + MaterialTheme.colorScheme.onPrimary } - val textColor = MaterialTheme.colorScheme.onPrimary + val textColor = MaterialTheme.colorScheme.primary val iconResId = if (isWhite) R.drawable.uber_logotype_black else R.drawable.uber_logotype_white @@ -66,6 +61,7 @@ fun UberAuthButton( colors = ButtonDefaults.buttonColors(containerColor = backgroundColor, contentColor = textColor), shape = shape, + interactionSource = interactionSource, ) { Icon( painter = painterResource(id = iconResId), @@ -75,7 +71,7 @@ fun UberAuthButton( Text( text = text.uppercase(), color = textColor, - style = UberTypography.bodySmall, + style = UberTypography.bodyMedium, modifier = Modifier.padding(UberDimens.standardPadding).wrapContentWidth(), ) } diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberButtonAttributes.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberButtonAttributes.kt index 22e9bfbc..2413aae7 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberButtonAttributes.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberButtonAttributes.kt @@ -23,7 +23,7 @@ val UberButtonShapes = Shapes( small = RoundedCornerShape(4.dp), medium = RoundedCornerShape(8.dp), - large = RoundedCornerShape(4.dp), + large = RoundedCornerShape(16.dp), ) object UberDimens { diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTheme.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTheme.kt index 60ce6aad..a269d8f4 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTheme.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/ui/theme/UberTheme.kt @@ -25,27 +25,9 @@ import androidx.compose.runtime.Composable fun UberTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) { val colors = if (darkTheme) { - darkColorScheme( - primary = UberBlack, - onPrimary = UberWhite, - secondary = UberWhite, - onSecondary = UberBlack, - background = UberBlack90, - surface = UberBlack90, - onBackground = UberWhite, - onSurface = UberWhite, - ) + darkColorScheme(primary = UberBlack, onPrimary = UberWhite, onSecondary = UberWhite40) } else { - lightColorScheme( - primary = UberBlack, - onPrimary = UberWhite, - secondary = UberBlack90, - onSecondary = UberWhite, - background = UberWhite, - surface = UberWhite40, - onBackground = UberBlack, - onSurface = UberBlack, - ) + lightColorScheme(primary = UberWhite, onPrimary = UberBlack, onSecondary = UberBlack90) } MaterialTheme( diff --git a/authentication/src/main/res/values/dimens.xml b/authentication/src/main/res/values/dimens.xml deleted file mode 100644 index 8323bd6f..00000000 --- a/authentication/src/main/res/values/dimens.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - 48dp - \ No newline at end of file From 60525e4a91850bf87701dc70bff6d3bc5669176c Mon Sep 17 00:00:00 2001 From: lalwani Date: Thu, 27 Jun 2024 10:43:52 -0700 Subject: [PATCH 9/9] removed auto demo from settings gradle --- settings.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 4d6a9505..165cf445 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -45,7 +45,6 @@ include( ":core", ":core-android", ":rides-android", - ":samples:auth-demo", ":samples:request-button-sample", ":samples:login-sample", ":samples:login-with-auth-code-demo",