Merge pull request #7344 from thunderbird/add_disabled_state_to_oauth_view
Add enabled state to `AccountOAuthView`
This commit is contained in:
commit
5e452644cf
5 changed files with 29 additions and 6 deletions
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -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),
|
||||
),
|
||||
|
@ -54,6 +55,7 @@ fun SignInWithGoogleButton(
|
|||
color = getBorderColor(isLight),
|
||||
),
|
||||
contentPadding = PaddingValues(all = 0.dp),
|
||||
enabled = enabled,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
|
@ -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,
|
||||
|
@ -125,7 +126,7 @@ private fun getTextColor(isLight: Boolean): Color {
|
|||
}
|
||||
}
|
||||
|
||||
@PreviewDevices
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
internal fun SignInWithGoogleButtonPreview() {
|
||||
PreviewWithThemes {
|
||||
|
@ -134,3 +135,14 @@ internal fun SignInWithGoogleButtonPreview() {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
internal fun SignInWithGoogleButtonDisabledPreview() {
|
||||
PreviewWithThemes {
|
||||
SignInWithGoogleButton(
|
||||
onClick = {},
|
||||
enabled = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue