|
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.BoxScope
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
+import androidx.compose.foundation.layout.ColumnScope
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
@@ -32,6 +33,7 @@ import androidx.compose.material.icons.filled.Email
|
|
|
import androidx.compose.material.icons.filled.Lock
|
|
|
import androidx.compose.material.icons.filled.Visibility
|
|
|
import androidx.compose.material.icons.filled.VisibilityOff
|
|
|
+import androidx.compose.material.icons.filled.Warning
|
|
|
import androidx.compose.material.icons.outlined.Visibility
|
|
|
import androidx.compose.material.icons.sharp.Visibility
|
|
|
import androidx.compose.material3.Button
|
|
@@ -103,6 +105,10 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
var textChanged by remember { mutableStateOf("") }
|
|
|
var passwordChanged by remember { mutableStateOf("") }
|
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
|
+ var showErrorEmail by remember { mutableStateOf(false) }
|
|
|
+ var showErrorEmail2 by remember { mutableStateOf(false) }
|
|
|
+ var showErrorPass1 by remember { mutableStateOf(false) }
|
|
|
+ var showErrorPass2 by remember { mutableStateOf(false) }
|
|
|
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
@@ -121,10 +127,7 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
focusManager.clearFocus()
|
|
|
keyboardController?.hide()
|
|
|
}
|
|
|
- }
|
|
|
- ,
|
|
|
-// contentAlignment = Alignment.Center
|
|
|
-
|
|
|
+ },
|
|
|
) {
|
|
|
Column (
|
|
|
modifier = Modifier
|
|
@@ -135,7 +138,6 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
) {
|
|
|
|
|
|
-
|
|
|
Spacer(modifier = Modifier.height(50.dp))
|
|
|
|
|
|
IconButton(
|
|
@@ -194,6 +196,12 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
|
|
|
+ val colorEmail = if (showErrorEmail || showErrorEmail2) {
|
|
|
+ colorResource(id = R.color.red)
|
|
|
+ } else {
|
|
|
+ colorResource(id = R.color.white)
|
|
|
+ }
|
|
|
+
|
|
|
TextField(
|
|
|
value = textChanged,
|
|
|
onValueChange = {
|
|
@@ -215,7 +223,7 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
.height(60.dp)
|
|
|
.border(
|
|
|
1.dp,
|
|
|
- color = colorResource(id = R.color.white),
|
|
|
+ color = colorEmail,
|
|
|
shape = RoundedCornerShape(16.dp)
|
|
|
),
|
|
|
|
|
@@ -264,11 +272,23 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
keyboardController?.hide()
|
|
|
}
|
|
|
),
|
|
|
-
|
|
|
)
|
|
|
|
|
|
+ if (showErrorEmail) {
|
|
|
+ ShowErrorRow(errorText = "Email is Empty")
|
|
|
+ }
|
|
|
+ else if (showErrorEmail2) {
|
|
|
+ ShowErrorRow(errorText = "Email format incorrect")
|
|
|
+ }
|
|
|
+
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
|
|
|
+ val colorPass = if (showErrorPass1 || showErrorPass2) {
|
|
|
+ colorResource(id = R.color.red)
|
|
|
+ } else {
|
|
|
+ colorResource(id = R.color.grey_password_field)
|
|
|
+ }
|
|
|
+
|
|
|
TextField(
|
|
|
value = passwordChanged,
|
|
|
onValueChange = {
|
|
@@ -291,7 +311,7 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
.height(60.dp)
|
|
|
.border(
|
|
|
1.dp,
|
|
|
- color = colorResource(id = R.color.grey_password_field),
|
|
|
+ color = colorPass,
|
|
|
shape = RoundedCornerShape(16.dp)
|
|
|
)
|
|
|
.background(color = colorResource(id = R.color.transparent)),
|
|
@@ -381,6 +401,13 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
}
|
|
|
)
|
|
|
|
|
|
+ if (showErrorPass1) {
|
|
|
+ ShowErrorRow(errorText = "Password is Empty")
|
|
|
+ }
|
|
|
+ else if (showErrorPass2) {
|
|
|
+ ShowErrorRow(errorText = "Should be 3 or more!")
|
|
|
+ }
|
|
|
+
|
|
|
Spacer(modifier = Modifier.height(15.dp))
|
|
|
|
|
|
Row (
|
|
@@ -444,7 +471,28 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- SignUpButton(signUpViewModel, textChanged, passwordChanged, navHostController)
|
|
|
+ SignUpButton(
|
|
|
+ signUpViewModel,
|
|
|
+ textChanged,
|
|
|
+ passwordChanged,
|
|
|
+ navHostController,
|
|
|
+ showErrorEmail1 = {
|
|
|
+ showErrorEmail = it
|
|
|
+ },
|
|
|
+ showErrorEmail,
|
|
|
+ showErrorPass1 = {
|
|
|
+ showErrorPass1 = it
|
|
|
+ },
|
|
|
+ showErrorPass1,
|
|
|
+ showErrorPass2 = {
|
|
|
+ showErrorPass2 = it
|
|
|
+ },
|
|
|
+ showErrorPass2,
|
|
|
+ showErrorEmail2 = {
|
|
|
+ showErrorEmail2 = it
|
|
|
+ },
|
|
|
+ showErrorEmail2
|
|
|
+ )
|
|
|
|
|
|
Row (
|
|
|
modifier = Modifier
|
|
@@ -501,17 +549,83 @@ fun SignUp(navHostController: NavHostController) {
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
+fun ColumnScope.ShowErrorRowSignUp(
|
|
|
+ errorText: String
|
|
|
+) {
|
|
|
+ Row(
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ modifier = Modifier
|
|
|
+ .align(Alignment.Start)
|
|
|
+ .padding(start = 16.dp, top = 8.dp)
|
|
|
+ ) {
|
|
|
+ Icon(imageVector = Icons.Default.Warning,
|
|
|
+ contentDescription = "Error",
|
|
|
+ tint = colorResource(id = R.color.red),
|
|
|
+ modifier = Modifier.size(14.dp)
|
|
|
+ )
|
|
|
+ Text(text = errorText,
|
|
|
+ style = TextStyle(
|
|
|
+ fontFamily = outfitFontFamily,
|
|
|
+ fontWeight = FontWeight.Normal,
|
|
|
+ fontSize = 14.sp,
|
|
|
+ color = colorResource(id = R.color.red)
|
|
|
+ ),
|
|
|
+ modifier = Modifier.padding(start = 5.dp)
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@Composable
|
|
|
fun BoxScope.SignUpButton(
|
|
|
signUpViewModel: SignUpViewModel,
|
|
|
email: String,
|
|
|
password: String,
|
|
|
navHostController: NavHostController,
|
|
|
+ showErrorEmail1: (Boolean) -> Unit,
|
|
|
+ isErrorEmail1: Boolean,
|
|
|
+ showErrorPass1: (Boolean) -> Unit,
|
|
|
+ isErrorPass1: Boolean,
|
|
|
+ showErrorPass2: (Boolean) -> Unit,
|
|
|
+ isErrorPass2: Boolean,
|
|
|
+ showErrorEmail2: (Boolean) -> Unit,
|
|
|
+ isErrorEmail2: Boolean
|
|
|
) {
|
|
|
val loginViewModel: LoginViewModel = viewModel()
|
|
|
val context = LocalContext.current
|
|
|
val prefHelper = BasePreferenceHelper(context)
|
|
|
val customValidation = CustomValidation()
|
|
|
|
|
|
+ if (isErrorEmail1) {
|
|
|
+ if (email.isNotEmpty()) {
|
|
|
+ showErrorEmail1(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isErrorEmail2) {
|
|
|
+ if (email.isNotEmpty()) {
|
|
|
+ val emailFormat = customValidation.isValidEmail(email)
|
|
|
+ if (emailFormat) {
|
|
|
+ showErrorEmail2(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isErrorPass1) {
|
|
|
+ if (password.isNotEmpty()) {
|
|
|
+ showErrorPass1(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isErrorPass2) {
|
|
|
+ if (password.isNotEmpty()) {
|
|
|
+ val isErrorPassSize = customValidation.isValidPassword(password)
|
|
|
+ if (isErrorPassSize) {
|
|
|
+ showErrorPass2(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if (signUpViewModel.liveDataSignUpStatus.value == true) {
|
|
|
var progress by remember { mutableFloatStateOf(0.1F) }
|
|
|
|
|
@@ -539,6 +653,21 @@ fun BoxScope.SignUpButton(
|
|
|
onClick = {
|
|
|
// navHostController.popBackStack()
|
|
|
// navHostController.navigate(Screen.BottomBarMainScreen.route)
|
|
|
+ val isErrors = customValidation.isValidText(email, "Email")
|
|
|
+ showErrorEmail1(!isErrors)
|
|
|
+
|
|
|
+ val isErrors4 = customValidation.isValidEmail(email)
|
|
|
+ if (email.isNotEmpty()) {
|
|
|
+ showErrorEmail2(!isErrors4)
|
|
|
+ }
|
|
|
+
|
|
|
+ val isErrors2 = customValidation.isValidText(password, "Password")
|
|
|
+ showErrorPass1(!isErrors2)
|
|
|
+
|
|
|
+ val isError3 = customValidation.isValidPassword(password)
|
|
|
+ if (password.isNotEmpty()) {
|
|
|
+ showErrorPass2(!isError3)
|
|
|
+ }
|
|
|
|
|
|
if (signUpViewModel.liveDataSignUpStatus.value == false) {
|
|
|
Log.d("test_button", "onClick")
|