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(
|
private fun LoginScreenContentComposable(
|
||||||
authentication: IAuthentication,
|
authentication: IAuthentication,
|
||||||
) {
|
) {
|
||||||
val typography = MaterialTheme.typography
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
|
@ -81,77 +80,11 @@ private fun LoginScreenContentComposable(
|
||||||
.padding(16.dp)
|
.padding(16.dp)
|
||||||
) {
|
) {
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
Title()
|
||||||
Text(
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(vertical = 16.dp)
|
|
||||||
.align(alignment = Alignment.CenterHorizontally),
|
|
||||||
style = typography.h4,
|
|
||||||
text = stringResource(id = R.string.welcome_sign_in)
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
Form(authentication)
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.weight(2f))
|
Spacer(modifier = Modifier.weight(2f))
|
||||||
|
SignIn(authentication)
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -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
|
@Composable
|
||||||
private fun LoginField(
|
private fun LoginField(
|
||||||
authentication: IAuthentication,
|
authentication: IAuthentication,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue