|
@@ -1,5 +1,6 @@
|
|
|
package com.fastest.pass.signup.presentation.ui.components
|
|
|
|
|
|
+import android.util.Log
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.border
|
|
@@ -27,6 +28,7 @@ import androidx.compose.material3.ButtonDefaults
|
|
|
import androidx.compose.material3.Icon
|
|
|
import androidx.compose.material3.IconButton
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
+import androidx.compose.material3.SnackbarHostState
|
|
|
import androidx.compose.material3.Surface
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.material3.TextField
|
|
@@ -35,6 +37,7 @@ import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.rememberCoroutineScope
|
|
|
import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
@@ -50,7 +53,6 @@ import androidx.compose.ui.res.colorResource
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
import androidx.compose.ui.text.AnnotatedString
|
|
|
-import androidx.compose.ui.text.TextStyle
|
|
|
import androidx.compose.ui.text.input.ImeAction
|
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
@@ -59,6 +61,8 @@ 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.app.Utils
|
|
|
+import kotlinx.coroutines.launch
|
|
|
|
|
|
enum class ClickType {
|
|
|
GO_BACK,
|
|
@@ -67,9 +71,15 @@ enum class ClickType {
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun SignUpScreen(clickType: (ClickType) -> Unit) {
|
|
|
+fun SignUpScreen(
|
|
|
+ clickType: (ClickType) -> Unit,
|
|
|
+ onSignupClickCredentials: (String, String) -> Unit
|
|
|
+) {
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
+ var emailSignup by remember { mutableStateOf("") }
|
|
|
+ var passwordSignup by remember { mutableStateOf("") }
|
|
|
+ val snackBarStateRed = remember { SnackbarHostState() }
|
|
|
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
@@ -103,13 +113,24 @@ fun SignUpScreen(clickType: (ClickType) -> Unit) {
|
|
|
)
|
|
|
) {
|
|
|
ShowWelcomeTextSU(R.string.create_new_account)
|
|
|
- SignUpTextField(keyboardController, focusManager)
|
|
|
+ SignUpTextField(keyboardController, focusManager, onEmailText = { emailSignup = it})
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
- PasswordTextFieldSU(keyboardController, focusManager)
|
|
|
+ PasswordTextFieldSU(keyboardController, focusManager, onPasswordText = { passwordSignup = it })
|
|
|
Spacer(modifier = Modifier.height(25.dp))
|
|
|
- SignUpButton(buttonText = R.string.signup) { clickType ->
|
|
|
- clickType(clickType)
|
|
|
- }
|
|
|
+ SignUpButton(
|
|
|
+ buttonText = R.string.signup,
|
|
|
+ clickType = { clickType ->
|
|
|
+ clickType(clickType)
|
|
|
+ },
|
|
|
+ email = emailSignup,
|
|
|
+ password = passwordSignup,
|
|
|
+ onSignupClickCredentials = { email, password ->
|
|
|
+ onSignupClickCredentials.invoke(email, password)
|
|
|
+ },
|
|
|
+ snackBarStateRed = snackBarStateRed,
|
|
|
+ keyboardController,
|
|
|
+ focusManager
|
|
|
+ )
|
|
|
HaveAnAccountText { clickType ->
|
|
|
clickType(clickType)
|
|
|
}
|
|
@@ -193,7 +214,8 @@ fun ColumnScope.ShowWelcomeTextSU(
|
|
|
@Composable
|
|
|
fun ColumnScope.SignUpTextField(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
- focusManager: FocusManager
|
|
|
+ focusManager: FocusManager,
|
|
|
+ onEmailText: (String) -> Unit
|
|
|
) {
|
|
|
var emailText by remember { mutableStateOf("") }
|
|
|
|
|
@@ -201,6 +223,7 @@ fun ColumnScope.SignUpTextField(
|
|
|
value = emailText,
|
|
|
onValueChange = {
|
|
|
emailText = it
|
|
|
+ onEmailText.invoke(emailText)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -262,7 +285,8 @@ fun ColumnScope.SignUpTextField(
|
|
|
@Composable
|
|
|
fun ColumnScope.PasswordTextFieldSU(
|
|
|
keyboardController: SoftwareKeyboardController?,
|
|
|
- focusManager: FocusManager
|
|
|
+ focusManager: FocusManager,
|
|
|
+ onPasswordText: (String) -> Unit
|
|
|
) {
|
|
|
var passwordText by remember { mutableStateOf("") }
|
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
@@ -271,6 +295,7 @@ fun ColumnScope.PasswordTextFieldSU(
|
|
|
value = passwordText,
|
|
|
onValueChange = {
|
|
|
passwordText = it
|
|
|
+ onPasswordText.invoke(passwordText)
|
|
|
},
|
|
|
textStyle = MaterialTheme.typography.displayMedium,
|
|
|
modifier = Modifier
|
|
@@ -361,7 +386,19 @@ fun ColumnScope.PasswordTextFieldSU(
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun ColumnScope.SignUpButton(buttonText: Int, clickType: (ClickType) -> Unit) {
|
|
|
+fun ColumnScope.SignUpButton(
|
|
|
+ buttonText: Int,
|
|
|
+ clickType: (ClickType) -> Unit,
|
|
|
+ email: String,
|
|
|
+ password: String,
|
|
|
+ onSignupClickCredentials: (String, String) -> Unit,
|
|
|
+ snackBarStateRed: SnackbarHostState,
|
|
|
+ keyboardController: SoftwareKeyboardController?,
|
|
|
+ focusManager: FocusManager
|
|
|
+) {
|
|
|
+ val coroutineScope = rememberCoroutineScope()
|
|
|
+ val context = LocalContext.current
|
|
|
+
|
|
|
Button(
|
|
|
modifier = Modifier
|
|
|
.padding(start = 30.dp, end = 30.dp,)
|
|
@@ -371,6 +408,22 @@ fun ColumnScope.SignUpButton(buttonText: Int, clickType: (ClickType) -> Unit) {
|
|
|
.clickable() { },
|
|
|
onClick = {
|
|
|
// clickType.invoke(ClickType.GO_TO_MASTER_SIGNUP)
|
|
|
+ Log.d("test_signup_api", "onClick = { $email, $password }")
|
|
|
+
|
|
|
+ if (email.isNotEmpty() && password.isNotEmpty()) {
|
|
|
+ focusManager.clearFocus()
|
|
|
+ keyboardController?.hide()
|
|
|
+ val hashPassword = Utils.hashing_sha256(password)
|
|
|
+ onSignupClickCredentials.invoke(email, hashPassword)
|
|
|
+ } else if (email.isEmpty()) {
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar(context.getString(R.string.email_field_req))
|
|
|
+ }
|
|
|
+ } else if (password.isEmpty()) {
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar(context.getString(R.string.password_field_req))
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
shape = RoundedCornerShape(15.dp),
|
|
|
// border = BorderStroke(25.dp, colorResource(id = R.color.black)),
|