Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enabled state to AccountOAuthView #7344

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal fun AccountOAuthContent(
state: State,
onEvent: (Event) -> Unit,
modifier: Modifier = Modifier,
isEnabled: Boolean = true,
) {
val resources = LocalContext.current.resources

Expand All @@ -47,6 +48,7 @@ internal fun AccountOAuthContent(
SignInView(
onSignInClick = { onEvent(Event.SignInClicked) },
isGoogleSignIn = state.isGoogleSignIn,
isEnabled = isEnabled,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fun AccountOAuthView(
onOAuthResult: (OAuthResult) -> Unit,
viewModel: ViewModel,
modifier: Modifier = Modifier,
isEnabled: Boolean = true,
) {
val oAuthLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
Expand All @@ -34,5 +35,6 @@ fun AccountOAuthView(
state = state.value,
onEvent = { dispatch(it) },
modifier = modifier,
isEnabled = isEnabled,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal fun SignInView(
onSignInClick: () -> Unit,
isGoogleSignIn: Boolean,
modifier: Modifier = Modifier,
isEnabled: Boolean = true,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
Expand All @@ -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,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -40,12 +40,13 @@ import app.k9mail.feature.account.oauth.R
fun SignInWithGoogleButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
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),
),
Expand All @@ -54,6 +55,7 @@ fun SignInWithGoogleButton(
color = getBorderColor(isLight),
),
contentPadding = PaddingValues(all = 0.dp),
enabled = enabled,
) {
Row(
modifier = Modifier
Expand Down Expand Up @@ -88,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,
Expand Down Expand Up @@ -125,7 +126,7 @@ private fun getTextColor(isLight: Boolean): Color {
}
}

@PreviewDevices
@Preview(showBackground = true)
@Composable
internal fun SignInWithGoogleButtonPreview() {
PreviewWithThemes {
Expand All @@ -134,3 +135,14 @@ internal fun SignInWithGoogleButtonPreview() {
)
}
}

@Preview(showBackground = true)
@Composable
internal fun SignInWithGoogleButtonDisabledPreview() {
PreviewWithThemes {
SignInWithGoogleButton(
onClick = {},
enabled = false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Expand Down