|
@@ -1,10 +1,13 @@
|
|
|
package com.example.development.mainActivity.components
|
|
|
|
|
|
+import android.widget.Toast
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
|
import androidx.compose.foundation.Image
|
|
|
+import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
+import androidx.compose.foundation.layout.Spacer
|
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
@@ -12,12 +15,16 @@ import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
import androidx.compose.foundation.layout.width
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
+import androidx.compose.material.icons.Icons
|
|
|
+import androidx.compose.material.icons.filled.Person
|
|
|
import androidx.compose.material3.Button
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
import androidx.compose.material3.Icon
|
|
|
import androidx.compose.material3.IconButton
|
|
|
+import androidx.compose.material3.OutlinedTextField
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.material3.TextField
|
|
|
+import androidx.compose.material3.TextFieldDefaults
|
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
@@ -27,6 +34,7 @@ import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
import androidx.compose.ui.layout.ContentScale
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
@@ -35,14 +43,19 @@ import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
import androidx.navigation.NavHostController
|
|
|
import com.example.development.R
|
|
|
+import com.example.development.domain.utils.CustomEmail
|
|
|
+import com.example.development.domain.utils.CustomPassword
|
|
|
import com.example.development.ui.theme.OldStandart
|
|
|
import com.example.development.mainActivity.MainViewModel
|
|
|
+import io.ktor.http.ContentType
|
|
|
|
|
|
@Composable
|
|
|
fun RegistrationScreen(navController: NavHostController, viewModel: MainViewModel) {
|
|
|
- val viewModel = MainViewModel()
|
|
|
+ val context = LocalContext.current
|
|
|
val email = remember { mutableStateOf("") }
|
|
|
val password = remember { mutableStateOf("") }
|
|
|
+ val checkPassword = remember { mutableStateOf("") }
|
|
|
+ val flag = remember { mutableStateOf(false) }
|
|
|
Box(contentAlignment = Alignment.TopCenter,
|
|
|
modifier = Modifier
|
|
|
.fillMaxSize()
|
|
@@ -82,70 +95,29 @@ fun RegistrationScreen(navController: NavHostController, viewModel: MainViewMode
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
)
|
|
|
{
|
|
|
- TextField(
|
|
|
- value = "Логин",
|
|
|
- onValueChange = {},
|
|
|
- Modifier.padding(bottom = 5.dp).width(280.dp)
|
|
|
- )
|
|
|
+ CustomEmail(search = email.value, onValueChange = {email.value = it })
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
|
.padding(top = 0.dp)
|
|
|
)
|
|
|
{
|
|
|
- var passwordVisibility: Boolean by remember { mutableStateOf(false) }
|
|
|
- TextField(value = "Пароль",
|
|
|
- visualTransformation = if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation(),
|
|
|
- leadingIcon = {
|
|
|
- IconButton(onClick = {
|
|
|
- passwordVisibility = !passwordVisibility
|
|
|
- }) {
|
|
|
- if (passwordVisibility) {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = R.drawable.eye_close),
|
|
|
- contentDescription = ""
|
|
|
- )
|
|
|
- } else {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = R.drawable.eye_open),
|
|
|
- contentDescription = ""
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- onValueChange = {})
|
|
|
- Column(
|
|
|
- modifier = Modifier
|
|
|
- .padding(top = 5.dp)
|
|
|
- )
|
|
|
+ CustomPassword("Введите пароль", search = password.value, onValueChange = {password.value = it})
|
|
|
+ CustomPassword("Повторите пароль", search = checkPassword.value, onValueChange = {checkPassword.value = it})
|
|
|
+ if (password.value == checkPassword.value)
|
|
|
+ {
|
|
|
+ flag.value = true
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- TextField(
|
|
|
- value = "Повторите пароль",
|
|
|
- visualTransformation = if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation(),
|
|
|
- leadingIcon = {
|
|
|
- IconButton(onClick = {
|
|
|
- passwordVisibility = !passwordVisibility
|
|
|
- }) {
|
|
|
- if (passwordVisibility) {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = R.drawable.eye_close),
|
|
|
- contentDescription = ""
|
|
|
- )
|
|
|
- } else {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = R.drawable.eye_open),
|
|
|
- contentDescription = ""
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- onValueChange = {},
|
|
|
- )
|
|
|
+ flag.value = false
|
|
|
}
|
|
|
}
|
|
|
Button(
|
|
|
modifier = Modifier.padding(top = 15.dp).height(50.dp),
|
|
|
onClick = {
|
|
|
- viewModel.onSignUpEmail(email.value,password.value)
|
|
|
+ if (flag.value) { viewModel.onSignUpEmail(email.value,password.value) }
|
|
|
+ else { Toast.makeText(context, "Пароли не совпадают", Toast.LENGTH_SHORT).show() }
|
|
|
+ navController.navigate("RegistrationScreen2")
|
|
|
},
|
|
|
shape = RoundedCornerShape(23.dp),
|
|
|
border = BorderStroke(1.dp, Color(255,215,0)),
|
|
@@ -162,7 +134,7 @@ fun RegistrationScreen(navController: NavHostController, viewModel: MainViewMode
|
|
|
}
|
|
|
Button(
|
|
|
modifier = Modifier.padding(top = 5.dp).height(50.dp).width(280.dp),
|
|
|
- onClick = {},
|
|
|
+ onClick = {navController.navigate("MainPage")},
|
|
|
shape = RoundedCornerShape(23.dp),
|
|
|
border = BorderStroke(1.dp, Color(255,215,0, 0)),
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
@@ -214,7 +186,7 @@ fun RegistrationScreen(navController: NavHostController, viewModel: MainViewMode
|
|
|
Button(
|
|
|
modifier = Modifier
|
|
|
.padding(top = 10.dp),
|
|
|
- onClick = {},
|
|
|
+ onClick = {navController.navigate("AuthorizationScreen")},
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
|
containerColor = Color(230, 235, 239,0),
|
|
|
contentColor = Color.Gray
|
|
@@ -236,7 +208,15 @@ fun RegistrationScreen(navController: NavHostController, viewModel: MainViewMode
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun RegistarationScreen2(navController: NavHostController, viewModel: MainViewModel) {
|
|
|
+fun RegistrationScreen2(navController: NavHostController, viewModel: MainViewModel) {
|
|
|
+ val flag = remember {mutableStateOf(false)}
|
|
|
+ val surnameFlag = remember { mutableStateOf(false) }
|
|
|
+ val nameFlag = remember {mutableStateOf(false)}
|
|
|
+ val phoneFlag = remember { mutableStateOf(false) }
|
|
|
+ val name = remember { mutableStateOf("") }
|
|
|
+ val surname = remember { mutableStateOf("") }
|
|
|
+ val phoneNumber = remember { mutableStateOf("") }
|
|
|
+
|
|
|
Box(
|
|
|
contentAlignment = Alignment.TopCenter,
|
|
|
modifier = Modifier
|
|
@@ -258,26 +238,132 @@ fun RegistarationScreen2(navController: NavHostController, viewModel: MainViewMo
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
fontFamily = OldStandart
|
|
|
)
|
|
|
- TextField(
|
|
|
- value = "Фамилия",
|
|
|
- onValueChange = {},
|
|
|
- Modifier.padding(bottom = 10.dp).width(280.dp)
|
|
|
- )
|
|
|
- TextField(
|
|
|
- value = "Имя",
|
|
|
- onValueChange = {},
|
|
|
- Modifier.padding(bottom = 10.dp).width(280.dp)
|
|
|
- )
|
|
|
- TextField(
|
|
|
- value = "Номер телефона",
|
|
|
- onValueChange = {},
|
|
|
- Modifier.padding(bottom = 30.dp).width(280.dp)
|
|
|
- )
|
|
|
+ Column()
|
|
|
+ {
|
|
|
+ OutlinedTextField(value = surname.value,
|
|
|
+ onValueChange = { it -> surname.value = it },
|
|
|
+ leadingIcon = { Icon(Icons.Filled.Person, contentDescription = "Фамилия") },
|
|
|
+ colors = TextFieldDefaults.colors(
|
|
|
+ focusedContainerColor = Color(0XFFF5F5F9),
|
|
|
+ focusedIndicatorColor = Color(0xFFEBEBEB),
|
|
|
+ focusedTextColor = Color.Black,
|
|
|
+ disabledIndicatorColor = Color.Transparent,
|
|
|
+ unfocusedIndicatorColor = Color.Transparent,
|
|
|
+ cursorColor = Color(0XFF578FFF),
|
|
|
+ focusedSupportingTextColor = Color(0xFF00000)
|
|
|
+ ),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(1f)
|
|
|
+ .background(Color(0XFFF5F5F9))
|
|
|
+ .height(height = 56.dp)
|
|
|
+ .width(width = 320.dp),
|
|
|
+ isError = surnameFlag.value,
|
|
|
+ placeholder = {
|
|
|
+ Text(
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
+ text = "Фамилия",
|
|
|
+ fontWeight = FontWeight.Normal,
|
|
|
+ fontSize = 15.sp,
|
|
|
+ color = Color(0XFF939396)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if (surname.value.isEmpty()) {
|
|
|
+ surnameFlag.value = true
|
|
|
+ Text("Введите фамилию", color = Color.Red, fontSize = 10.sp)
|
|
|
+ } else {
|
|
|
+ surnameFlag.value = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Spacer(modifier = Modifier.height(20.dp))
|
|
|
+ Column {
|
|
|
+ OutlinedTextField(value = name.value, onValueChange = { it -> name.value = it },
|
|
|
+ leadingIcon = { Icon(Icons.Filled.Person, contentDescription = "Имя") },
|
|
|
+ colors = TextFieldDefaults.colors(
|
|
|
+ focusedContainerColor = Color(0XFFF5F5F9),
|
|
|
+ focusedIndicatorColor = Color(0xFFEBEBEB),
|
|
|
+ focusedTextColor = Color.Black,
|
|
|
+ disabledIndicatorColor = Color.Transparent,
|
|
|
+ unfocusedIndicatorColor = Color.Transparent,
|
|
|
+ cursorColor = Color(0XFF578FFF),
|
|
|
+ focusedSupportingTextColor = Color(0xFF00000)
|
|
|
+ ),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(1f)
|
|
|
+ .background(Color(0XFFF5F5F9))
|
|
|
+ .height(height = 56.dp)
|
|
|
+ .width(width = 320.dp),
|
|
|
+ isError = nameFlag.value,
|
|
|
+
|
|
|
+ placeholder = {
|
|
|
+ Text(
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
+ text = "Имя",
|
|
|
+ fontWeight = FontWeight.Normal,
|
|
|
+ fontSize = 15.sp,
|
|
|
+ color = Color(0XFF939396)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if (name.value.isEmpty()) {
|
|
|
+ nameFlag.value = true
|
|
|
+ Text("Введите имя", color = Color.Red, fontSize = 10.sp)
|
|
|
+ } else {
|
|
|
+ nameFlag.value = false
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ Column {
|
|
|
+ OutlinedTextField(value = phoneNumber.value, onValueChange = { it -> name.value = it },
|
|
|
+ leadingIcon = { Icon(Icons.Filled.Person, contentDescription = "Имя") },
|
|
|
+ colors = TextFieldDefaults.colors(
|
|
|
+ focusedContainerColor = Color(0XFFF5F5F9),
|
|
|
+ focusedIndicatorColor = Color(0xFFEBEBEB),
|
|
|
+ focusedTextColor = Color.Black,
|
|
|
+ disabledIndicatorColor = Color.Transparent,
|
|
|
+ unfocusedIndicatorColor = Color.Transparent,
|
|
|
+ cursorColor = Color(0XFF578FFF),
|
|
|
+ focusedSupportingTextColor = Color(0xFF00000)
|
|
|
+ ),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(1f)
|
|
|
+ .background(Color(0XFFF5F5F9))
|
|
|
+ .height(height = 56.dp)
|
|
|
+ .width(width = 320.dp),
|
|
|
+ isError = nameFlag.value,
|
|
|
+
|
|
|
+ placeholder = {
|
|
|
+ Text(
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
+ text = "Номер телефона",
|
|
|
+ fontWeight = FontWeight.Normal,
|
|
|
+ fontSize = 15.sp,
|
|
|
+ color = Color(0XFF939396)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if (name.value.isEmpty()) {
|
|
|
+ nameFlag.value = true
|
|
|
+ Text("Введите номер телефона", color = Color.Red, fontSize = 10.sp)
|
|
|
+ } else {
|
|
|
+ nameFlag.value = false
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
Button(modifier = Modifier
|
|
|
.width(width = 270.dp)
|
|
|
.height(height = 40.dp)
|
|
|
.padding(),
|
|
|
- onClick = {},
|
|
|
+ onClick = {
|
|
|
+ viewModel.CreateUser(secondName = surname.value,
|
|
|
+ firstName = name.value,
|
|
|
+ phoneNumber = phoneNumber.value.toInt())
|
|
|
+ navController.navigate("UserProfile")
|
|
|
+ },
|
|
|
shape = RoundedCornerShape(23.dp),
|
|
|
border = BorderStroke(0.dp, Color(0xFFEBEBEB)),
|
|
|
colors = ButtonDefaults.buttonColors(
|