From 86ed42713e0ac7ca75c22ae14fec7e2c7948ab66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolf-Martell=20Montw=C3=A9?= Date: Thu, 9 Nov 2023 11:14:10 +0100 Subject: [PATCH 1/2] Add enabled state to OAuthView and propagate to buttons --- .../k9mail/feature/account/oauth/ui/AccountOAuthContent.kt | 2 ++ .../app/k9mail/feature/account/oauth/ui/AccountOAuthView.kt | 2 ++ .../app/k9mail/feature/account/oauth/ui/view/SignInView.kt | 3 +++ .../feature/account/oauth/ui/view/SignInWithGoogleButton.kt | 2 ++ .../account/setup/ui/autodiscovery/item/ContentItems.kt | 4 ++++ 5 files changed, 13 insertions(+) diff --git a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/AccountOAuthContent.kt b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/AccountOAuthContent.kt index b766bc18918..0469b3c65a7 100644 --- a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/AccountOAuthContent.kt +++ b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/AccountOAuthContent.kt @@ -24,6 +24,7 @@ internal fun AccountOAuthContent( state: State, onEvent: (Event) -> Unit, modifier: Modifier = Modifier, + isEnabled: Boolean = true, ) { val resources = LocalContext.current.resources @@ -47,6 +48,7 @@ internal fun AccountOAuthContent( SignInView( onSignInClick = { onEvent(Event.SignInClicked) }, isGoogleSignIn = state.isGoogleSignIn, + isEnabled = isEnabled, ) } } diff --git a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/AccountOAuthView.kt b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/AccountOAuthView.kt index 44f458a0d10..ac2f743420d 100644 --- a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/AccountOAuthView.kt +++ b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/AccountOAuthView.kt @@ -15,6 +15,7 @@ fun AccountOAuthView( onOAuthResult: (OAuthResult) -> Unit, viewModel: ViewModel, modifier: Modifier = Modifier, + isEnabled: Boolean = true, ) { val oAuthLauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.StartActivityForResult(), @@ -34,5 +35,6 @@ fun AccountOAuthView( state = state.value, onEvent = { dispatch(it) }, modifier = modifier, + isEnabled = isEnabled, ) } diff --git a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInView.kt b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInView.kt index 93fef259698..3b28e3ddca0 100644 --- a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInView.kt +++ b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInView.kt @@ -18,6 +18,7 @@ internal fun SignInView( onSignInClick: () -> Unit, isGoogleSignIn: Boolean, modifier: Modifier = Modifier, + isEnabled: Boolean = true, ) { Column( horizontalAlignment = Alignment.CenterHorizontally, @@ -32,11 +33,13 @@ internal fun SignInView( if (isGoogleSignIn) { SignInWithGoogleButton( onClick = onSignInClick, + enabled = isEnabled, ) } else { Button( text = stringResource(id = R.string.account_oauth_sign_in_button), onClick = onSignInClick, + enabled = isEnabled, ) } } diff --git a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInWithGoogleButton.kt b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInWithGoogleButton.kt index bc7d62e4cac..c64fccccd6d 100644 --- a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInWithGoogleButton.kt +++ b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInWithGoogleButton.kt @@ -40,6 +40,7 @@ import app.k9mail.feature.account.oauth.R fun SignInWithGoogleButton( onClick: () -> Unit, modifier: Modifier = Modifier, + enabled: Boolean = true, isLight: Boolean = MaterialTheme.colors.isLight, ) { OutlinedButton( @@ -54,6 +55,7 @@ fun SignInWithGoogleButton( color = getBorderColor(isLight), ), contentPadding = PaddingValues(all = 0.dp), + enabled = enabled, ) { Row( modifier = Modifier diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/autodiscovery/item/ContentItems.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/autodiscovery/item/ContentItems.kt index bf6c92e495c..b0a368bbc92 100644 --- a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/autodiscovery/item/ContentItems.kt +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/autodiscovery/item/ContentItems.kt @@ -49,9 +49,13 @@ internal fun LazyListScope.contentItems( } else if (state.configStep == ConfigStep.OAUTH) { item(key = "oauth") { ListItem { + val isAutoDiscoverySettingsTrusted = state.autoDiscoverySettings?.isTrusted ?: false + val isConfigurationApproved = state.configurationApproved.value ?: false + AccountOAuthView( onOAuthResult = { result -> onEvent(Event.OnOAuthResult(result)) }, viewModel = oAuthViewModel, + isEnabled = isAutoDiscoverySettingsTrusted || isConfigurationApproved, ) } } From 9faaf96c1834c2c89458e7be7c68fb543cff3115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolf-Martell=20Montw=C3=A9?= Date: Thu, 9 Nov 2023 11:16:17 +0100 Subject: [PATCH 2/2] Change `SignInWithGoogleButton` to visually support disabled state --- .../oauth/ui/view/SignInWithGoogleButton.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInWithGoogleButton.kt b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInWithGoogleButton.kt index c64fccccd6d..29217f67a65 100644 --- a/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInWithGoogleButton.kt +++ b/feature/account/oauth/src/main/kotlin/app/k9mail/feature/account/oauth/ui/view/SignInWithGoogleButton.kt @@ -13,7 +13,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.ButtonDefaults import androidx.compose.material.Icon import androidx.compose.material.MaterialTheme -import androidx.compose.material.OutlinedButton import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -24,11 +23,12 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import app.k9mail.core.ui.compose.common.PreviewDevices import app.k9mail.core.ui.compose.theme.PreviewWithThemes import app.k9mail.feature.account.oauth.R +import androidx.compose.material.Button as MaterialButton /** * A sign in with Google button, following the Google Branding Guidelines. @@ -43,10 +43,10 @@ fun SignInWithGoogleButton( enabled: Boolean = true, isLight: Boolean = MaterialTheme.colors.isLight, ) { - OutlinedButton( + MaterialButton( onClick = onClick, modifier = modifier, - colors = ButtonDefaults.outlinedButtonColors( + colors = ButtonDefaults.buttonColors( contentColor = getTextColor(isLight), backgroundColor = getSurfaceColor(isLight), ), @@ -90,7 +90,6 @@ fun SignInWithGoogleButton( id = R.string.account_oauth_sign_in_with_google_button, ), style = TextStyle( - color = getTextColor(isLight), fontWeight = FontWeight.Medium, fontSize = 14.sp, letterSpacing = 1.25.sp, @@ -127,7 +126,7 @@ private fun getTextColor(isLight: Boolean): Color { } } -@PreviewDevices +@Preview(showBackground = true) @Composable internal fun SignInWithGoogleButtonPreview() { PreviewWithThemes { @@ -136,3 +135,14 @@ internal fun SignInWithGoogleButtonPreview() { ) } } + +@Preview(showBackground = true) +@Composable +internal fun SignInWithGoogleButtonDisabledPreview() { + PreviewWithThemes { + SignInWithGoogleButton( + onClick = {}, + enabled = false, + ) + } +}