|
@@ -1,5 +1,6 @@
|
|
|
package com.fastest.pass.login.presentation.ui.components
|
|
|
|
|
|
+import android.util.Log
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.border
|
|
@@ -58,6 +59,7 @@ import androidx.compose.ui.text.style.TextAlign
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
import com.fastest.pass.R
|
|
|
+import com.fastest.pass.login.data.model.LoginResult
|
|
|
|
|
|
enum class ClickType {
|
|
|
SIGNUP_CLICK,
|
|
@@ -69,9 +71,15 @@ enum class ClickType {
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun LoginScreen(clickType: (ClickType) -> Unit) {
|
|
|
+fun LoginScreen(
|
|
|
+ loginResult: LoginResult,
|
|
|
+ clickType: (ClickType) -> Unit,
|
|
|
+ onLoginClickCredentials: (String, String) -> Unit
|
|
|
+) {
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
+ var emailLogin by remember { mutableStateOf("") }
|
|
|
+ var passwordLogin by remember { mutableStateOf("") }
|
|
|
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
@@ -105,13 +113,19 @@ fun LoginScreen(clickType: (ClickType) -> Unit) {
|
|
|
)
|
|
|
) {
|
|
|
ShowWelcomeText(R.string.login_to_continue)
|
|
|
- LoginTextField(keyboardController, focusManager)
|
|
|
+ LoginTextField(keyboardController, focusManager, onEmailText = {
|
|
|
+ emailLogin = it
|
|
|
+ })
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- PasswordTextField(keyboardController, focusManager)
|
|
|
+ PasswordTextField(keyboardController, focusManager, onPasswordText = {
|
|
|
+ passwordLogin = it
|
|
|
+ })
|
|
|
Spacer(modifier = Modifier.height(25.dp))
|
|
|
- LoginButton(buttonText = R.string.login) { clickType ->
|
|
|
+ LoginButton(buttonText = R.string.login, clickType = { clickType ->
|
|
|
clickType(clickType)
|
|
|
- }
|
|
|
+ }, email = emailLogin, password = passwordLogin, onLoginClickCredentials = { email, password ->
|
|
|
+ onLoginClickCredentials.invoke(email, password)
|
|
|
+ })
|
|
|
ForgotPasswordText() { clickType ->
|
|
|
clickType(clickType)
|
|
|
}
|
|
@@ -121,6 +135,21 @@ fun LoginScreen(clickType: (ClickType) -> Unit) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ when (loginResult) {
|
|
|
+ is LoginResult.Error -> {
|
|
|
+ Log.d("loginResult", "Error")
|
|
|
+ }
|
|
|
+ LoginResult.Loading -> {
|
|
|
+ Log.d("loginResult", "Loading")
|
|
|
+ }
|
|
|
+ LoginResult.None -> {
|
|
|
+ Log.d("loginResult", "None")
|
|
|
+ }
|
|
|
+ is LoginResult.Success -> {
|
|
|
+ Log.d("loginResult", "Success")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
@@ -195,7 +224,8 @@ fun ColumnScope.ShowWelcomeText(
|
|
|
@Composable
|
|
|
fun ColumnScope.LoginTextField(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
- focusManager: FocusManager
|
|
|
+ focusManager: FocusManager,
|
|
|
+ onEmailText: (String) -> Unit
|
|
|
) {
|
|
|
var emailText by remember { mutableStateOf("") }
|
|
|
|
|
@@ -203,6 +233,7 @@ fun ColumnScope.LoginTextField(
|
|
|
value = emailText,
|
|
|
onValueChange = {
|
|
|
emailText = it
|
|
|
+ onEmailText.invoke(emailText)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -264,7 +295,8 @@ fun ColumnScope.LoginTextField(
|
|
|
@Composable
|
|
|
fun ColumnScope.PasswordTextField(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
- focusManager: FocusManager
|
|
|
+ focusManager: FocusManager,
|
|
|
+ onPasswordText: (String) -> Unit
|
|
|
) {
|
|
|
var passwordText by remember { mutableStateOf("") }
|
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
@@ -273,6 +305,7 @@ fun ColumnScope.PasswordTextField(
|
|
|
value = passwordText,
|
|
|
onValueChange = {
|
|
|
passwordText = it
|
|
|
+ onPasswordText.invoke(passwordText)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -363,7 +396,13 @@ fun ColumnScope.PasswordTextField(
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun ColumnScope.LoginButton(buttonText: Int, clickType: (ClickType) -> Unit) {
|
|
|
+fun ColumnScope.LoginButton(
|
|
|
+ buttonText: Int,
|
|
|
+ clickType: (ClickType) -> Unit,
|
|
|
+ email: String,
|
|
|
+ password: String,
|
|
|
+ onLoginClickCredentials: (String, String) -> Unit
|
|
|
+) {
|
|
|
Button(
|
|
|
modifier = Modifier
|
|
|
.padding(start = 30.dp, end = 30.dp)
|
|
@@ -372,7 +411,12 @@ fun ColumnScope.LoginButton(buttonText: Int, clickType: (ClickType) -> Unit) {
|
|
|
.height(60.dp)
|
|
|
.clickable() { },
|
|
|
onClick = {
|
|
|
- clickType.invoke(ClickType.LOGIN_CLICK)
|
|
|
+ Log.d("test_api_login", "ClickType.LOGIN_CLICK")
|
|
|
+// clickType.invoke(ClickType.LOGIN_CLICK)
|
|
|
+
|
|
|
+ if (email.isNotEmpty() && password.isNotEmpty()) {
|
|
|
+ onLoginClickCredentials.invoke(email, password)
|
|
|
+ }
|
|
|
},
|
|
|
shape = RoundedCornerShape(15.dp),
|
|
|
// border = BorderStroke(25.dp, colorResource(id = R.color.black)),
|