Refacor login screen composable.
This commit is contained in:
parent
9cde3f6404
commit
31b6aed8a8
1 changed files with 84 additions and 70 deletions
|
|
@ -72,7 +72,6 @@ fun LoginScreenComposable(
|
|||
private fun LoginScreenContentComposable(
|
||||
authentication: IAuthentication,
|
||||
) {
|
||||
val typography = MaterialTheme.typography
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
|
@ -81,77 +80,11 @@ private fun LoginScreenContentComposable(
|
|||
.padding(16.dp)
|
||||
) {
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.padding(vertical = 16.dp)
|
||||
.align(alignment = Alignment.CenterHorizontally),
|
||||
style = typography.h4,
|
||||
text = stringResource(id = R.string.welcome_sign_in)
|
||||
)
|
||||
|
||||
Title()
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val localFocus = LocalFocusManager.current
|
||||
LoginField(
|
||||
authentication = authentication,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
|
||||
keyboardActions = KeyboardActions { focusRequester.requestFocus() }
|
||||
)
|
||||
PasswordField(
|
||||
authentication = authentication,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp)
|
||||
.focusRequester(focusRequester),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions { localFocus.clearFocus() }
|
||||
)
|
||||
CredentialRemember(
|
||||
authentication = authentication,
|
||||
modifier = Modifier
|
||||
.height(48.dp)
|
||||
.padding(bottom = 16.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(bottom = 16.dp)
|
||||
.align(Alignment.End)
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
Button(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
colors = outlinedButtonColors(),
|
||||
onClick = {
|
||||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(REGISTER_URL)))
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.action_register))
|
||||
}
|
||||
Button(onClick = {
|
||||
authentication.login()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.action_login))
|
||||
}
|
||||
}
|
||||
|
||||
Form(authentication)
|
||||
Spacer(modifier = Modifier.weight(2f))
|
||||
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = outlinedButtonColors(),
|
||||
onClick = {
|
||||
authentication.loginWithGoogle()
|
||||
}) {
|
||||
Image(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
painter = painterResource(id = R.drawable.ic_google), contentDescription = ""
|
||||
)
|
||||
Text(text = stringResource(id = R.string.action_google_sign_in))
|
||||
}
|
||||
SignIn(authentication)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -220,6 +153,87 @@ private fun LoginScreenNavigationComposable(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ColumnScope.Title() {
|
||||
val typography = MaterialTheme.typography
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.padding(vertical = 16.dp)
|
||||
.align(alignment = Alignment.CenterHorizontally),
|
||||
style = typography.h4,
|
||||
text = stringResource(id = R.string.welcome_sign_in)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ColumnScope.Form(
|
||||
authentication: IAuthentication,
|
||||
) {
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val localFocus = LocalFocusManager.current
|
||||
LoginField(
|
||||
authentication = authentication,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
|
||||
keyboardActions = KeyboardActions { focusRequester.requestFocus() }
|
||||
)
|
||||
PasswordField(
|
||||
authentication = authentication,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp)
|
||||
.focusRequester(focusRequester),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions { localFocus.clearFocus() }
|
||||
)
|
||||
CredentialRemember(
|
||||
authentication = authentication,
|
||||
modifier = Modifier
|
||||
.height(48.dp)
|
||||
.padding(bottom = 16.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(bottom = 16.dp)
|
||||
.align(Alignment.End)
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
Button(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
colors = outlinedButtonColors(),
|
||||
onClick = {
|
||||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(REGISTER_URL)))
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.action_register))
|
||||
}
|
||||
Button(onClick = {
|
||||
authentication.login()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.action_login))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SignIn(
|
||||
authentication: IAuthentication,
|
||||
) {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = outlinedButtonColors(),
|
||||
onClick = {
|
||||
authentication.loginWithGoogle()
|
||||
}) {
|
||||
Image(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
painter = painterResource(id = R.drawable.ic_google), contentDescription = ""
|
||||
)
|
||||
Text(text = stringResource(id = R.string.action_google_sign_in))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LoginField(
|
||||
authentication: IAuthentication,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue