|
@@ -1,6 +1,7 @@
|
|
package com.example.tomatoandpotatoapp.Screens
|
|
package com.example.tomatoandpotatoapp.Screens
|
|
|
|
|
|
import android.widget.ImageButton
|
|
import android.widget.ImageButton
|
|
|
|
+import android.widget.Toast
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
@@ -19,6 +20,7 @@ import androidx.compose.material.icons.filled.KeyboardArrowDown
|
|
import androidx.compose.material.icons.filled.KeyboardArrowUp
|
|
import androidx.compose.material.icons.filled.KeyboardArrowUp
|
|
import androidx.compose.material3.Button
|
|
import androidx.compose.material3.Button
|
|
import androidx.compose.material3.ButtonDefaults
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
+import androidx.compose.material3.CircularProgressIndicator
|
|
import androidx.compose.material3.DropdownMenu
|
|
import androidx.compose.material3.DropdownMenu
|
|
import androidx.compose.material3.DropdownMenuItem
|
|
import androidx.compose.material3.DropdownMenuItem
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.Icon
|
|
@@ -52,138 +54,160 @@ import com.example.tomatoandpotatoapp.ViewModelsPack.SupabaseAuthViewModel
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import androidx.navigation.NavController
|
|
import androidx.navigation.NavController
|
|
import com.example.tomatoandpotatoapp.R
|
|
import com.example.tomatoandpotatoapp.R
|
|
|
|
+import com.example.tomatoandpotatoapp.data.models.UserState
|
|
|
|
+import com.example.tomatoandpotatoapp.navigationPack.Screens
|
|
import com.example.tomatoandpotatoapp.utils.EditProfileString
|
|
import com.example.tomatoandpotatoapp.utils.EditProfileString
|
|
|
|
|
|
|
|
|
|
-@Preview
|
|
|
|
|
|
+//@Preview
|
|
@Composable
|
|
@Composable
|
|
fun MyProfile(
|
|
fun MyProfile(
|
|
viewModel: SupabaseAuthViewModel = viewModel(),
|
|
viewModel: SupabaseAuthViewModel = viewModel(),
|
|
- //navController: NavController
|
|
|
|
|
|
+ navController: NavController
|
|
) {
|
|
) {
|
|
-// val userState by viewModel.userState
|
|
|
|
-// val people by viewModel.user
|
|
|
|
-// val f = remember { mutableStateOf(false) }
|
|
|
|
-// val context = LocalContext.current
|
|
|
|
-// val f2 = remember { mutableStateOf(true) }
|
|
|
|
-//
|
|
|
|
-// if (f2.value) {
|
|
|
|
-// viewModel.selectPeople()
|
|
|
|
-// f2.value = false
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// if (viewModel.user.value.isNotEmpty()){
|
|
|
|
-// val firstName = remember {
|
|
|
|
-// mutableStateOf(people.last().firstName)
|
|
|
|
-// }
|
|
|
|
-// val genderId = remember {
|
|
|
|
-// mutableStateOf(people.last().genderId)
|
|
|
|
-// }
|
|
|
|
-// val birthDate = remember {
|
|
|
|
-// mutableStateOf(people.last().birthDate)
|
|
|
|
-// }
|
|
|
|
|
|
+ val userState by viewModel.userState
|
|
|
|
+ val people by viewModel.user
|
|
|
|
+ val f = remember { mutableStateOf(false) }
|
|
|
|
+ val context = LocalContext.current
|
|
|
|
+ val f2 = remember { mutableStateOf(true) }
|
|
|
|
+ val out = remember { mutableStateOf(false) }
|
|
var mSelectedText by remember { mutableStateOf("") }
|
|
var mSelectedText by remember { mutableStateOf("") }
|
|
var expanded by remember { mutableStateOf(false) }
|
|
var expanded by remember { mutableStateOf(false) }
|
|
var mTextFieldSize by remember { mutableStateOf(Size.Zero) }
|
|
var mTextFieldSize by remember { mutableStateOf(Size.Zero) }
|
|
- val genders = listOf("Мужской", "Женский")
|
|
|
|
|
|
+
|
|
|
|
+ val genders = viewModel.genders
|
|
|
|
|
|
val icon = if (expanded)
|
|
val icon = if (expanded)
|
|
Icons.Filled.KeyboardArrowUp
|
|
Icons.Filled.KeyboardArrowUp
|
|
else
|
|
else
|
|
Icons.Filled.KeyboardArrowDown
|
|
Icons.Filled.KeyboardArrowDown
|
|
|
|
|
|
- Box(modifier = Modifier.fillMaxSize()) {
|
|
|
|
- Box(
|
|
|
|
- modifier = Modifier
|
|
|
|
- .fillMaxSize()
|
|
|
|
- .background(
|
|
|
|
- brush = Brush.verticalGradient(
|
|
|
|
- colors = listOf(
|
|
|
|
- Color(0xFF666666).copy(alpha = 0.85f),
|
|
|
|
- Color(0xFF666666).copy(alpha = 0.1f)
|
|
|
|
- ),
|
|
|
|
- startY = 0.0f,
|
|
|
|
- endY = 1500.0f
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- Column(modifier = Modifier.fillMaxSize()) {
|
|
|
|
- Row(
|
|
|
|
|
|
+ if (f2.value) {
|
|
|
|
+ viewModel.selectPeople()
|
|
|
|
+ f2.value = false
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (people.isNotEmpty()) {
|
|
|
|
+ val firstName = remember {
|
|
|
|
+ mutableStateOf(people.last().firstName)
|
|
|
|
+ }
|
|
|
|
+ val genderId = remember {
|
|
|
|
+ mutableStateOf(people.last().genderId)
|
|
|
|
+ }
|
|
|
|
+ val birthDate = remember {
|
|
|
|
+ mutableStateOf(people.last().birthDate)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Box(modifier = Modifier.fillMaxSize()) {
|
|
|
|
+ Box(
|
|
modifier = Modifier
|
|
modifier = Modifier
|
|
- .fillMaxWidth()
|
|
|
|
- .height(95.dp)
|
|
|
|
- .background(color = Color(0xffD9D9D9)),
|
|
|
|
- horizontalArrangement = Arrangement.Center,
|
|
|
|
- verticalAlignment = Alignment.CenterVertically
|
|
|
|
- ) {
|
|
|
|
- Text(
|
|
|
|
- text = "Профиль",
|
|
|
|
- fontWeight = FontWeight.W800,
|
|
|
|
- color = Color.Black,
|
|
|
|
- fontSize = 25.sp
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
|
|
+ .fillMaxSize()
|
|
|
|
+ .background(
|
|
|
|
+ brush = Brush.verticalGradient(
|
|
|
|
+ colors = listOf(
|
|
|
|
+ Color(0xFF666666).copy(alpha = 0.85f),
|
|
|
|
+ Color(0xFF666666).copy(alpha = 0.1f)
|
|
|
|
+ ),
|
|
|
|
+ startY = 0.0f,
|
|
|
|
+ endY = 1500.0f
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ Column(modifier = Modifier.fillMaxSize()) {
|
|
|
|
+ Row(
|
|
|
|
+ modifier = Modifier
|
|
|
|
+ .fillMaxWidth()
|
|
|
|
+ .height(95.dp)
|
|
|
|
+ .background(color = Color(0xffD9D9D9)),
|
|
|
|
+ horizontalArrangement = Arrangement.Center,
|
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
|
+ ) {
|
|
|
|
+ Text(
|
|
|
|
+ text = "Профиль",
|
|
|
|
+ fontWeight = FontWeight.W800,
|
|
|
|
+ color = Color.Black,
|
|
|
|
+ fontSize = 25.sp
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
|
|
- Spacer(modifier = Modifier.height(60.dp))
|
|
|
|
- Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
|
|
|
|
|
|
+ Spacer(modifier = Modifier.height(60.dp))
|
|
|
|
+ Row(
|
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
|
+ horizontalArrangement = Arrangement.Center
|
|
|
|
+ ) {
|
|
|
|
|
|
- EditProfileString(search = "", onValueChange = {}, enabled = true)
|
|
|
|
- }
|
|
|
|
|
|
+ EditProfileString(search = firstName.value,
|
|
|
|
+ onValueChange = {firstName.value = it}, enabled = true)
|
|
|
|
+ }
|
|
|
|
|
|
- Spacer(modifier = Modifier.height(30.dp))
|
|
|
|
|
|
+ Spacer(modifier = Modifier.height(30.dp))
|
|
|
|
|
|
- Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
|
|
|
|
|
|
+ Row(
|
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
|
+ horizontalArrangement = Arrangement.Center
|
|
|
|
+ ) {
|
|
|
|
|
|
- EditProfileString(search = "", onValueChange = {}, enabled = true)
|
|
|
|
- }
|
|
|
|
|
|
+ EditProfileString(search = birthDate.value,
|
|
|
|
+ onValueChange = {birthDate.value = it}, enabled = true)
|
|
|
|
+ }
|
|
|
|
|
|
- Spacer(modifier = Modifier.height(30.dp))
|
|
|
|
|
|
+ Spacer(modifier = Modifier.height(30.dp))
|
|
|
|
|
|
- Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
|
|
|
|
|
|
+ Row(
|
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
|
+ horizontalArrangement = Arrangement.Center
|
|
|
|
+ ) {
|
|
|
|
|
|
- OutlinedTextField(
|
|
|
|
- value = mSelectedText,
|
|
|
|
- onValueChange = { mSelectedText = it },
|
|
|
|
- modifier = Modifier
|
|
|
|
- .height(50.dp)
|
|
|
|
- .width(316.dp)
|
|
|
|
- .onGloballyPositioned { coordinates ->
|
|
|
|
- mTextFieldSize = coordinates.size.toSize()
|
|
|
|
|
|
+ OutlinedTextField(
|
|
|
|
+ value = mSelectedText,
|
|
|
|
+ onValueChange = { },
|
|
|
|
+ modifier = Modifier
|
|
|
|
+ .height(50.dp)
|
|
|
|
+ .width(316.dp)
|
|
|
|
+ .onGloballyPositioned { coordinates ->
|
|
|
|
+ mTextFieldSize = coordinates.size.toSize()
|
|
|
|
+ },
|
|
|
|
+ shape = RoundedCornerShape(20),
|
|
|
|
+ colors = TextFieldDefaults.colors(
|
|
|
|
+ focusedContainerColor = Color(0xFFF2D6FA),
|
|
|
|
+ focusedIndicatorColor = Color(0xFF4C2259),
|
|
|
|
+ focusedTextColor = Color.Black,
|
|
|
|
+ disabledIndicatorColor = Color.Transparent,
|
|
|
|
+ unfocusedIndicatorColor = Color.Transparent,
|
|
|
|
+ cursorColor = Color.Black,
|
|
|
|
+ focusedSupportingTextColor = Color.Black
|
|
|
|
+ ),
|
|
|
|
+ label = {
|
|
|
|
+ Text(
|
|
|
|
+ "Пол",
|
|
|
|
+ fontWeight = FontWeight.W600,
|
|
|
|
+ color = Color.Black
|
|
|
|
+ )
|
|
},
|
|
},
|
|
- shape = RoundedCornerShape(20),
|
|
|
|
- colors = TextFieldDefaults.colors(
|
|
|
|
- focusedContainerColor = Color(0xFFF2D6FA),
|
|
|
|
- focusedIndicatorColor = Color(0xFF4C2259),
|
|
|
|
- focusedTextColor = Color.Black,
|
|
|
|
- disabledIndicatorColor = Color.Transparent,
|
|
|
|
- unfocusedIndicatorColor = Color.Transparent,
|
|
|
|
- cursorColor = Color.Black,
|
|
|
|
- focusedSupportingTextColor = Color.Black
|
|
|
|
- ),
|
|
|
|
- label = {
|
|
|
|
- Text(
|
|
|
|
- "Пол",
|
|
|
|
- fontWeight = FontWeight.W600,
|
|
|
|
- color = Color.Black
|
|
|
|
- )
|
|
|
|
- },
|
|
|
|
- trailingIcon = {
|
|
|
|
- Icon(icon, "contentDescription",
|
|
|
|
- Modifier.clickable { expanded = !expanded })
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- DropdownMenu(
|
|
|
|
- expanded = expanded,
|
|
|
|
- onDismissRequest = { expanded = false },
|
|
|
|
- modifier = Modifier
|
|
|
|
- .width(with(LocalDensity.current) { mTextFieldSize.width.toDp() })
|
|
|
|
- ) {
|
|
|
|
- genders.forEach { label ->
|
|
|
|
- DropdownMenuItem(onClick = {
|
|
|
|
- mSelectedText = label
|
|
|
|
- expanded = false
|
|
|
|
- }) {
|
|
|
|
- Text(text = label)
|
|
|
|
|
|
+ trailingIcon = {
|
|
|
|
+ Icon(icon, "contentDescription",
|
|
|
|
+ Modifier.clickable { expanded = !expanded })
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ DropdownMenu(
|
|
|
|
+ expanded = expanded,
|
|
|
|
+ onDismissRequest = { expanded = false },
|
|
|
|
+ modifier = Modifier
|
|
|
|
+ .width(with(LocalDensity.current) { mTextFieldSize.width.toDp() })
|
|
|
|
+ ) {
|
|
|
|
+ genders.value.forEach { label ->
|
|
|
|
+ DropdownMenuItem(text = {
|
|
|
|
+ Text(
|
|
|
|
+ text = label.genderTitle,
|
|
|
|
+ fontSize = 15.sp, fontWeight = FontWeight.Normal
|
|
|
|
+ )
|
|
|
|
+ },
|
|
|
|
+ onClick = {
|
|
|
|
+ mSelectedText = label.genderTitle
|
|
|
|
+ genderId.value = label.id
|
|
|
|
+ expanded = false
|
|
|
|
+ }
|
|
|
|
+ )
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -213,8 +237,6 @@ fun MyProfile(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
Spacer(modifier = Modifier.height(110.dp))
|
|
Spacer(modifier = Modifier.height(110.dp))
|
|
|
|
|
|
Row(
|
|
Row(
|
|
@@ -228,7 +250,8 @@ fun MyProfile(
|
|
.width(278.dp)
|
|
.width(278.dp)
|
|
.height(45.dp),
|
|
.height(45.dp),
|
|
shape = RoundedCornerShape(20),
|
|
shape = RoundedCornerShape(20),
|
|
- colors = ButtonDefaults.buttonColors(containerColor = Color(0xff78EE99))
|
|
|
|
|
|
+ colors = ButtonDefaults
|
|
|
|
+ .buttonColors(containerColor = Color(0xff78EE99))
|
|
)
|
|
)
|
|
{
|
|
{
|
|
Text(
|
|
Text(
|
|
@@ -248,12 +271,13 @@ fun MyProfile(
|
|
verticalAlignment = Alignment.CenterVertically
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
) {
|
|
Button(
|
|
Button(
|
|
- onClick = { },
|
|
|
|
|
|
+ onClick = {viewModel.singOut(context) },
|
|
modifier = Modifier
|
|
modifier = Modifier
|
|
.width(278.dp)
|
|
.width(278.dp)
|
|
.height(45.dp),
|
|
.height(45.dp),
|
|
shape = RoundedCornerShape(20),
|
|
shape = RoundedCornerShape(20),
|
|
- colors = ButtonDefaults.buttonColors(containerColor = Color(0xffFC5050))
|
|
|
|
|
|
+ colors = ButtonDefaults
|
|
|
|
+ .buttonColors(containerColor = Color(0xffFC5050))
|
|
)
|
|
)
|
|
{
|
|
{
|
|
Text(
|
|
Text(
|
|
@@ -271,12 +295,11 @@ fun MyProfile(
|
|
modifier = Modifier
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.fillMaxWidth()
|
|
.height(95.dp)
|
|
.height(95.dp)
|
|
- //.align(Alignment.End)
|
|
|
|
.background(color = Color(0xff718588)),
|
|
.background(color = Color(0xff718588)),
|
|
horizontalArrangement = Arrangement.SpaceEvenly
|
|
horizontalArrangement = Arrangement.SpaceEvenly
|
|
) {
|
|
) {
|
|
IconButton(
|
|
IconButton(
|
|
- onClick = { /*TODO*/ },
|
|
|
|
|
|
+ onClick = { },
|
|
modifier = Modifier.size(120.dp)
|
|
modifier = Modifier.size(120.dp)
|
|
) {
|
|
) {
|
|
Icon(
|
|
Icon(
|
|
@@ -286,7 +309,7 @@ fun MyProfile(
|
|
)
|
|
)
|
|
}
|
|
}
|
|
IconButton(
|
|
IconButton(
|
|
- onClick = { /*TODO*/ },
|
|
|
|
|
|
+ onClick = { navController.navigate(Screens.PlantsCatalogScreen.route) },
|
|
modifier = Modifier.size(120.dp)
|
|
modifier = Modifier.size(120.dp)
|
|
) {
|
|
) {
|
|
Icon(
|
|
Icon(
|
|
@@ -296,7 +319,7 @@ fun MyProfile(
|
|
)
|
|
)
|
|
}
|
|
}
|
|
IconButton(
|
|
IconButton(
|
|
- onClick = { /*TODO*/ },
|
|
|
|
|
|
+ onClick = { navController.navigate(Screens.ProfileScreen.route) },
|
|
modifier = Modifier.size(120.dp)
|
|
modifier = Modifier.size(120.dp)
|
|
) {
|
|
) {
|
|
Icon(
|
|
Icon(
|
|
@@ -310,4 +333,41 @@ fun MyProfile(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+ if (f.value) {
|
|
|
|
+ when (userState) {
|
|
|
|
+ is UserState.Loading -> {
|
|
|
|
+ CircularProgressIndicator()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ is UserState.Success -> {
|
|
|
|
+ val message = (userState as UserState.Success).message
|
|
|
|
+ Toast.makeText(context, "Данные успещно сохранены!", Toast.LENGTH_SHORT).show()
|
|
|
|
+ f.value = false
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ is UserState.Error -> {
|
|
|
|
+ val message = (userState as UserState.Error).message
|
|
|
|
+ f.value = false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (out.value) {
|
|
|
|
+ when (userState) {
|
|
|
|
+ is UserState.Loading -> {
|
|
|
|
+ CircularProgressIndicator()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ is UserState.Success -> {
|
|
|
|
+ navController.navigate(Screens.ChoiceScreen.route)
|
|
|
|
+ out.value = false
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ is UserState.Error -> {
|
|
|
|
+ val message = (userState as UserState.Error).message
|
|
|
|
+ Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
|
|
|
+ out.value = false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|