Pārlūkot izejas kodu

addedTheFunctionOfUpdatingUserProfileData

x1tosi 6 dienas atpakaļ
vecāks
revīzija
a625c0aba4

+ 0 - 1
ProjectInAndroidStudio/.idea/misc.xml

@@ -1,4 +1,3 @@
-<?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="ExternalStorageConfigurationManager" enabled="true" />
   <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">

+ 145 - 7
ProjectInAndroidStudio/app/src/main/java/com/example/uniqwearappproj/MainViewModel.kt

@@ -2,7 +2,9 @@ package com.example.uniqwearappproj
 
 import android.util.Log
 import androidx.compose.runtime.State
+import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.setValue
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import com.example.uniqwearappproj.Domain.Constants
@@ -14,13 +16,21 @@ import io.github.jan.supabase.storage.storage
 import kotlinx.coroutines.launch
 
 class MainViewModel: ViewModel()  {
+    //переменная для результата входа и регистрации
     var authResult = mutableStateOf("")
+    //uid текущего пользователя
     var currentUserUid = mutableStateOf<String?>(null)
 
     var profileCreated = mutableStateOf(false)
-
+    //Для Storage
     val basket = Constants.supabase.storage["pic"]
 
+    //Переменные для обновления данных users
+    var dateOfBirth by mutableStateOf<String?>(null)
+    var fname by mutableStateOf<String?>(null)
+    var sname by mutableStateOf<String?>(null)
+    var mname by mutableStateOf<String?>(null)
+    var photoUrl by mutableStateOf<String?>(null)
 
     private val _user = mutableStateOf(listOf<users>())
     val user: State<List<users>> = _user
@@ -140,20 +150,148 @@ class MainViewModel: ViewModel()  {
 
 
 
+//    fun addAvatarr(byteArray: ByteArray) {
+//        viewModelScope.launch {
+//            try {
+//                val basket = Constants.supabase.storage["pic"]
+//                basket.upload(
+//                    "${Constants.supabase.auth.currentUserOrNull()!!.email}.jpg",
+//                    byteArray
+//                )
+//                Log.d("addAvatar", "Avatar successfully uploaded")
+//            } catch (e: Exception) {
+//                Log.e("addAvatar", "Error uploading avatar: ${e.message}")
+//            }
+//        }
+//    }
+
     fun addAvatarr(byteArray: ByteArray) {
         viewModelScope.launch {
             try {
                 val basket = Constants.supabase.storage["pic"]
-                basket.upload(
-                    "${Constants.supabase.auth.currentUserOrNull()!!.email}.jpg",
-                    byteArray
-                )
-                Log.d("addAvatar", "Avatar successfully uploaded")
+                if(byteArray.isNotEmpty()){
+                    try {
+                        basket.upload(
+                            "${Constants.supabase.auth.currentUserOrNull()!!.email}.jpg",
+                            byteArray,
+                            options = { }
+                        )
+                        Constants.supabase.from("users").update(
+                            {
+                                users::photo_url setTo basket.publicUrl("${Constants.supabase.auth.currentUserOrNull()!!.email}.jpg")
+
+                            }
+                        ) {
+                            filter {
+                                users::uid eq Constants.supabase.auth.currentUserOrNull()!!.id
+                            }
+                        }
+                    }catch (e: Exception){
+                        basket.update(
+                            "${Constants.supabase.auth.currentUserOrNull()!!.email}.jpg",
+                            byteArray,
+                            options = { }
+                        )
+                        Constants.supabase.from("users").update(
+                            {
+                                users::photo_url setTo basket.publicUrl("${Constants.supabase.auth.currentUserOrNull()!!.email}.jpg")
+
+                            }
+                        ) {
+                            filter {
+                                users::uid eq Constants.supabase.auth.currentUserOrNull()!!.id
+                            }
+                        }
+                    }
+                }
             } catch (e: Exception) {
-                Log.e("addAvatar", "Error uploading avatar: ${e.message}")
+                Log.d("my_tag", e.message!!)
             }
         }
     }
 
 
+    fun updateNameUserProfile(fname: String) {
+        viewModelScope.launch {
+            try {
+
+                Constants.supabase.from("users").update(
+                    {
+                        users::first_name setTo fname
+                    }
+                ) {
+                    filter {
+                        users::uid eq Constants.supabase.auth.currentUserOrNull()!!.id
+                    }
+                }
+                Log.d("my_tag", "Success update profile")
+
+            } catch (e: Exception) {
+                Log.d("my_tag", e.message!!)
+            }
+        }
+    }
+
+    fun updateLastNameUserProfile(value: String) {
+        viewModelScope.launch {
+            try {
+
+                Constants.supabase.from("users").update(
+                    {
+                        users::last_name setTo sname
+                    }
+                ) {
+                    filter {
+                        users::uid eq Constants.supabase.auth.currentUserOrNull()!!.id
+                    }
+                }
+                Log.d("my_tag", "Success update profile")
+
+            } catch (e: Exception) {
+                Log.d("my_tag", e.message!!)
+            }
+        }
+    }
+
+    fun updateMiddleNameUserProfile(value: String) {
+        viewModelScope.launch {
+            try {
+
+                Constants.supabase.from("users").update(
+                    {
+                        users::middle_name setTo mname
+                    }
+                ) {
+                    filter {
+                        users::uid eq Constants.supabase.auth.currentUserOrNull()!!.id
+                    }
+                }
+                Log.d("my_tag", "Success update profile")
+
+            } catch (e: Exception) {
+                Log.d("my_tag", e.message!!)
+            }
+        }
+    }
+
+    fun updateDOBUserProfile(value: String) {
+        viewModelScope.launch {
+            try {
+
+                Constants.supabase.from("users").update(
+                    {
+                        users::date_of_birth setTo dateOfBirth
+                    }
+                ) {
+                    filter {
+                        users::uid eq Constants.supabase.auth.currentUserOrNull()!!.id
+                    }
+                }
+                Log.d("my_tag", "Success update profile")
+
+            } catch (e: Exception) {
+                Log.d("my_tag", e.message!!)
+            }
+        }
+    }
 }

+ 58 - 0
ProjectInAndroidStudio/app/src/main/java/com/example/uniqwearappproj/Resources/ImageToBitmapProfilePic.kt

@@ -0,0 +1,58 @@
+package com.example.uniqwearappproj.Resources
+
+import android.net.Uri
+import androidx.activity.compose.ManagedActivityResultLauncher
+import androidx.activity.result.PickVisualMediaRequest
+import androidx.activity.result.contract.ActivityResultContracts
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ImageBitmap
+import androidx.compose.ui.layout.ContentScale
+import androidx.compose.ui.unit.dp
+
+@Composable
+fun ImageForBitmap(image: ImageBitmap, launcher: ManagedActivityResultLauncher<PickVisualMediaRequest, Uri?>) {
+    Box(
+        modifier = Modifier
+            .width(200.dp)
+            .height(200.dp)
+            .clip(RoundedCornerShape(50.dp))
+    ) {
+        Button(
+            onClick = {
+                launcher.launch(
+                    PickVisualMediaRequest(
+                        ActivityResultContracts.PickVisualMedia.ImageOnly
+                    )
+                )
+            },
+            colors = ButtonDefaults.buttonColors(
+                containerColor = Color.White,
+                disabledContainerColor = Color.White
+            ), modifier = Modifier
+                .width(100.dp)
+                .height(100.dp),
+            contentPadding = PaddingValues(0.dp)
+        ) {
+            Image(
+                modifier = Modifier
+                    .height(200.dp)
+                    .width(200.dp),
+                bitmap = image,
+                contentDescription = "",
+                contentScale = ContentScale.Crop
+            )
+        }
+    }
+}
+

+ 2 - 1
ProjectInAndroidStudio/app/src/main/java/com/example/uniqwearappproj/Screens/registrationScreenNext.kt

@@ -279,7 +279,8 @@ fun RegistrationNextScreen(navController: NavHostController, MainViewModel: Main
                             fontWeight = FontWeight.Normal
                         )
                     )
-                })
+                }
+            )
             Spacer(modifier = Modifier.height(16.dp)) // Отступ между текстовыми полями
             Button(onClick = { launcher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) },
                 modifier = Modifier

+ 354 - 48
ProjectInAndroidStudio/app/src/main/java/com/example/uniqwearappproj/Screens/userProfileScreen.kt

@@ -1,7 +1,13 @@
 package com.example.uniqwearappproj.Screens
 
+import android.graphics.BitmapFactory
+import androidx.activity.compose.rememberLauncherForActivityResult
+import androidx.activity.result.PickVisualMediaRequest
+import androidx.activity.result.contract.ActivityResultContracts
+import androidx.compose.animation.AnimatedVisibility
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.Column
@@ -18,9 +24,13 @@ import androidx.compose.foundation.layout.statusBars
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.shape.CircleShape
 import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
 import androidx.compose.material3.CircularProgressIndicator
 import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
+import androidx.compose.material3.LocalTextStyle
+import androidx.compose.material3.OutlinedTextField
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.getValue
@@ -32,10 +42,13 @@ import androidx.compose.ui.draw.clip
 import androidx.compose.ui.geometry.Offset
 import androidx.compose.ui.graphics.Brush
 import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.ImageBitmap
+import androidx.compose.ui.graphics.asImageBitmap
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.res.painterResource
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController
 import coil.compose.AsyncImagePainter
@@ -47,9 +60,10 @@ import com.example.uniqwearappproj.R
 
 @Composable
 fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel) {
-    val flag = remember { mutableStateOf(true) }
 
+    val flag = remember { mutableStateOf(true) }
     val context = LocalContext.current
+    //Переменная для кнопки обновления
 
     val user by viewModel.user
 
@@ -70,11 +84,24 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
         val date_of_birth = remember {
             mutableStateOf(user.last().date_of_birth)
         }
-        val photoUrl = rememberAsyncImagePainter(
+        val photoUrlSB = rememberAsyncImagePainter(
             model = ImageRequest.Builder(LocalContext.current).data(user.last().photo_url)
                 .size(200, 200).build()
         ).state
+        val newProfilePicUser = remember { mutableStateOf(byteArrayOf()) }
+        val newBitMapAvatar = remember { mutableStateOf<ImageBitmap?>(null) }
+        val launcher =
+            rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
+                if (uri == null) return@rememberLauncherForActivityResult
+                newProfilePicUser.value = bitmapToByteArray(context, uri)
+
+            }
 
+        val isNameEnabled = remember { mutableStateOf(false) }
+        val isLastNameEnabled = remember { mutableStateOf(false) }
+        val isMiddleNameEnabled = remember { mutableStateOf(false) }
+        val isDateOfBirthEnabled = remember { mutableStateOf(false) }
+        val isPhotoUrlEnabled = remember { mutableStateOf(false) }
 
         Column() {
             // Слой градиента 1
@@ -121,8 +148,8 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                 ) {
                     Column(
                         modifier = Modifier
-                            .fillMaxWidth(),
-//                            .padding(16.dp),
+                            .fillMaxWidth()
+                            .padding(16.dp),
                         horizontalAlignment = Alignment.CenterHorizontally
                     ) {
                         Row(
@@ -142,39 +169,58 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                 modifier = Modifier.size(50.dp)
                             )
                         }
-                        Row(modifier = Modifier
-                            .fillMaxWidth()
-                            .padding(8.dp),
+                        Row(
+                            modifier = Modifier
+                                .fillMaxWidth()
+                                .padding(8.dp),
                             verticalAlignment = Alignment.CenterVertically,
-                            horizontalArrangement = Arrangement.Center) {
-                            if (photoUrl is AsyncImagePainter.State.Success){
-                                // User profile image
-                                Box(
-                                    modifier = Modifier
-                                        .size(200.dp)
-                                        .clip(CircleShape)
-                                        .background(Color.Gray),
-                                    contentAlignment = Alignment.Center
-                                ) {
-                                    Image(
-                                        painter = photoUrl.painter!!,  // Use the painter here
-                                        contentDescription = "User Profile Picture",
-                                        modifier = Modifier.size(200.dp)
-                                    )
+                            horizontalArrangement = Arrangement.Center
+                        ) {
+                            if (newProfilePicUser.value.isEmpty()) {
+                                if (photoUrlSB is AsyncImagePainter.State.Success) {
+                                    // User profile image
+                                    Box(
+                                        modifier = Modifier
+                                            .size(200.dp)
+                                            .clip(CircleShape)
+                                            .background(Color.Gray),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        Image(
+                                            painter = photoUrlSB.painter!!,  // Use the painter here
+                                            contentDescription = "User Profile Picture",
+                                            modifier = Modifier.size(200.dp)
+                                        )
+                                    }
                                 }
-                            }
-                            if (photoUrl is AsyncImagePainter.State.Loading){
-                                Box(
-                                    modifier = Modifier
-                                        .size(200.dp)
-                                        .clip(CircleShape)
-                                        .background(Color.Gray),
-                                    contentAlignment = Alignment.Center
-                                ) {
-                                    CircularProgressIndicator()
+                                if (photoUrlSB is AsyncImagePainter.State.Loading) {
+                                    Box(
+                                        modifier = Modifier
+                                            .size(200.dp)
+                                            .clip(CircleShape)
+                                            .background(Color.Gray),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        CircularProgressIndicator()
+                                    }
                                 }
-                            }
-                            if (photoUrl is AsyncImagePainter.State.Error){
+                                if (photoUrlSB is AsyncImagePainter.State.Error) {
+                                    Box(
+                                        modifier = Modifier
+                                            .size(200.dp)
+                                            .clip(CircleShape)
+                                            .background(Color.Gray),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        Image(
+                                            painter = painterResource(R.drawable.placeholder_avatar),
+                                            contentDescription = "User Profile Picture",
+                                            modifier = Modifier.size(200.dp)
+                                        )
+                                    }
+                                }
+                            } else {
+                                newBitMapAvatar.value = ByteArrayImage(newProfilePicUser.value)
                                 Box(
                                     modifier = Modifier
                                         .size(200.dp)
@@ -183,23 +229,36 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                     contentAlignment = Alignment.Center
                                 ) {
                                     Image(
-                                        painter = painterResource(R.drawable.placeholder_avatar),
+                                        bitmap = newBitMapAvatar.value!!,
                                         contentDescription = "User Profile Picture",
                                         modifier = Modifier.size(200.dp)
                                     )
                                 }
                             }
+
+
                             Spacer(modifier = Modifier.width(8.dp))
                             Box(
                                 modifier = Modifier
                                     .size(50.dp)
-                                    .background(color = Color(0xFF5F5EB7), RoundedCornerShape(10.dp))
+                                    .background(
+                                        color = Color(0xFF5F5EB7),
+                                        RoundedCornerShape(10.dp)
+                                    )
                                     .padding(16.dp),
                                 contentAlignment = Alignment.Center
                             ) {
                                 Icon(
                                     modifier = Modifier
-                                        .size(25.dp),
+                                        .size(25.dp)
+                                        .clickable {
+                                            launcher.launch(
+                                                PickVisualMediaRequest(
+                                                    ActivityResultContracts.PickVisualMedia.ImageOnly
+                                                )
+                                            )
+                                            isPhotoUrlEnabled.value = !isPhotoUrlEnabled.value
+                                        },
                                     painter = painterResource(id = R.drawable.edit),
                                     contentDescription = "Edit First Name",
                                     tint = Color.White
@@ -215,6 +274,31 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                 .padding(vertical = 16.dp),
                             horizontalAlignment = Alignment.CenterHorizontally
                         ) {
+                            AnimatedVisibility(
+                                visible = isPhotoUrlEnabled.value,
+                                Modifier.padding(8.dp)
+                            ) {
+                                Column(horizontalAlignment = Alignment.CenterHorizontally) {
+                                    Button(
+                                        onClick = {
+                                            viewModel.addAvatarr(newProfilePicUser.value)
+                                            isPhotoUrlEnabled.value =
+                                                false // Скрываем поле после сохранения
+                                        },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .padding(top = 8.dp),
+                                        colors = ButtonDefaults.buttonColors(
+                                            containerColor = Color(
+                                                0xFF5F5EB7
+                                            )
+                                        ),
+                                        shape = RoundedCornerShape(10.dp)
+                                    ) {
+                                        Text("Сохранить", color = Color.White, fontSize = 16.sp)
+                                    }
+                                }
+                            }
                             // Имя
                             Row(
                                 modifier = Modifier
@@ -248,14 +332,58 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                     contentAlignment = Alignment.Center
                                 ) {
                                     Icon(
-                                        modifier = Modifier
-                                            .size(25.dp),
                                         painter = painterResource(id = R.drawable.edit),
                                         contentDescription = "Edit First Name",
-                                        tint = Color.White
+                                        tint = Color.White,
+                                        modifier = Modifier
+                                            .size(25.dp)
+                                            .clickable {
+                                                isNameEnabled.value = !isNameEnabled.value
+                                            }
+                                    )
+                                }
+                            }
+                            AnimatedVisibility(
+                                visible = isNameEnabled.value,
+                                Modifier.padding(8.dp)
+                            ) {
+                                Column(horizontalAlignment = Alignment.CenterHorizontally) {
+                                    OutlinedTextField(
+                                        value = name.value,
+                                        onValueChange = { name.value = it },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .background(
+                                                Color(0xFFD9D9D9),
+                                                RoundedCornerShape(10.dp)
+                                            ),
+                                        label = { Text("Введите имя", color = Color.Black) },
+                                        textStyle = LocalTextStyle.current.copy(
+                                            fontSize = 16.sp,
+                                            color = Color.Black
+                                        )
                                     )
+                                    Button(
+                                        onClick = {
+                                            viewModel.updateNameUserProfile(name.value)
+                                            isNameEnabled.value =
+                                                false // Скрываем поле после сохранения
+                                        },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .padding(top = 8.dp),
+                                        colors = ButtonDefaults.buttonColors(
+                                            containerColor = Color(
+                                                0xFF5F5EB7
+                                            )
+                                        ),
+                                        shape = RoundedCornerShape(10.dp)
+                                    ) {
+                                        Text("Сохранить", color = Color.White, fontSize = 16.sp)
+                                    }
                                 }
                             }
+
                             // Фамилия
                             Row(
                                 modifier = Modifier
@@ -290,13 +418,56 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                 ) {
                                     Icon(
                                         modifier = Modifier
-                                            .size(25.dp),
+                                            .size(25.dp)
+                                            .clickable {
+                                                isLastNameEnabled.value = !isLastNameEnabled.value
+                                            },
                                         painter = painterResource(id = R.drawable.edit),
                                         contentDescription = "Edit Last Name",
                                         tint = Color.White
                                     )
                                 }
                             }
+                            AnimatedVisibility(
+                                visible = isLastNameEnabled.value,
+                                Modifier.padding(8.dp)
+                            ) {
+                                Column(horizontalAlignment = Alignment.CenterHorizontally) {
+                                    OutlinedTextField(
+                                        value = name.value,
+                                        onValueChange = { name.value = it },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .background(
+                                                Color(0xFFD9D9D9),
+                                                RoundedCornerShape(10.dp)
+                                            ),
+                                        label = { Text("Введите фамилию", color = Color.Black) },
+                                        textStyle = LocalTextStyle.current.copy(
+                                            fontSize = 16.sp,
+                                            color = Color.Black
+                                        )
+                                    )
+                                    Button(
+                                        onClick = {
+                                            viewModel.updateLastNameUserProfile(second_name.value)
+                                            isLastNameEnabled.value =
+                                                false // Скрываем поле после сохранения
+                                        },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .padding(top = 8.dp),
+                                        colors = ButtonDefaults.buttonColors(
+                                            containerColor = Color(
+                                                0xFF5F5EB7
+                                            )
+                                        ),
+                                        shape = RoundedCornerShape(10.dp)
+                                    ) {
+                                        Text("Сохранить", color = Color.White, fontSize = 16.sp)
+                                    }
+                                }
+                            }
 
                             // Отчество
                             Row(
@@ -332,13 +503,57 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                 ) {
                                     Icon(
                                         modifier = Modifier
-                                            .size(25.dp),
+                                            .size(25.dp)
+                                            .clickable {
+                                                isMiddleNameEnabled.value =
+                                                    !isMiddleNameEnabled.value
+                                            },/*TODO*/
                                         painter = painterResource(id = R.drawable.edit),
                                         contentDescription = "Edit Middle Name",
                                         tint = Color.White
                                     )
                                 }
                             }
+                            AnimatedVisibility(
+                                visible = isMiddleNameEnabled.value,
+                                Modifier.padding(8.dp)
+                            ) {
+                                Column(horizontalAlignment = Alignment.CenterHorizontally) {
+                                    OutlinedTextField(
+                                        value = name.value,
+                                        onValueChange = { name.value = it },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .background(
+                                                Color(0xFFD9D9D9),
+                                                RoundedCornerShape(10.dp)
+                                            ),
+                                        label = { Text("Введите отчество", color = Color.Black) },
+                                        textStyle = LocalTextStyle.current.copy(
+                                            fontSize = 16.sp,
+                                            color = Color.Black
+                                        )
+                                    )
+                                    Button(
+                                        onClick = {
+                                            viewModel.updateMiddleNameUserProfile(patronymic.value)
+                                            isMiddleNameEnabled.value =
+                                                false // Скрываем поле после сохранения
+                                        },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .padding(top = 8.dp),
+                                        colors = ButtonDefaults.buttonColors(
+                                            containerColor = Color(
+                                                0xFF5F5EB7
+                                            )
+                                        ),
+                                        shape = RoundedCornerShape(10.dp)
+                                    ) {
+                                        Text("Сохранить", color = Color.White, fontSize = 16.sp)
+                                    }
+                                }
+                            }
 
                             // Дата рождения
                             Row(
@@ -374,13 +589,57 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                 ) {
                                     Icon(
                                         modifier = Modifier
-                                            .size(25.dp),
+                                            .size(25.dp)
+                                            .clickable {
+                                                isDateOfBirthEnabled.value =
+                                                    !isDateOfBirthEnabled.value
+                                            },
                                         painter = painterResource(id = R.drawable.edit),
                                         contentDescription = "Edit Date of Birth",
                                         tint = Color.White
                                     )
                                 }
                             }
+                            AnimatedVisibility(
+                                visible = isDateOfBirthEnabled.value,
+                                Modifier.padding(8.dp)
+                            ) {
+                                Column(horizontalAlignment = Alignment.CenterHorizontally) {
+                                    OutlinedTextField(
+                                        value = name.value,
+                                        onValueChange = { name.value = it },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .background(
+                                                Color(0xFFD9D9D9),
+                                                RoundedCornerShape(10.dp)
+                                            ),
+                                        label = { Text("Введите дату рождения", color = Color.Black) },
+                                        textStyle = LocalTextStyle.current.copy(
+                                            fontSize = 16.sp,
+                                            color = Color.Black
+                                        )
+                                    )
+                                    Button(
+                                        onClick = {
+                                            viewModel.updateDOBUserProfile(date_of_birth.value)
+                                            isDateOfBirthEnabled.value =
+                                                false // Скрываем поле после сохранения
+                                        },
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .padding(top = 8.dp),
+                                        colors = ButtonDefaults.buttonColors(
+                                            containerColor = Color(
+                                                0xFF5F5EB7
+                                            )
+                                        ),
+                                        shape = RoundedCornerShape(10.dp)
+                                    ) {
+                                        Text("Сохранить", color = Color.White, fontSize = 16.sp)
+                                    }
+                                }
+                            }
                         }
                     }
 
@@ -405,7 +664,10 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                     shape = RoundedCornerShape(10.dp)
                                 )
                         ) {
-                            Box(contentAlignment = Alignment.Center, modifier = Modifier.size(64.dp)) {
+                            Box(
+                                contentAlignment = Alignment.Center,
+                                modifier = Modifier.size(64.dp)
+                            ) {
                                 Icon(
                                     painter = painterResource(id = R.drawable.ivector),
                                     contentDescription = "Go to Main",
@@ -423,7 +685,10 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                     shape = RoundedCornerShape(10.dp)
                                 )
                         ) {
-                            Box(contentAlignment = Alignment.Center, modifier = Modifier.size(64.dp)) {
+                            Box(
+                                contentAlignment = Alignment.Center,
+                                modifier = Modifier.size(64.dp)
+                            ) {
                                 Icon(
                                     painter = painterResource(id = R.drawable.add),
                                     contentDescription = "Go to create",
@@ -441,7 +706,10 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                     shape = RoundedCornerShape(10.dp)
                                 )
                         ) {
-                            Box(contentAlignment = Alignment.Center, modifier = Modifier.size(64.dp)) {
+                            Box(
+                                contentAlignment = Alignment.Center,
+                                modifier = Modifier.size(64.dp)
+                            ) {
                                 Icon(
                                     painter = painterResource(id = R.drawable.cart),
                                     contentDescription = "Go to Cart",
@@ -459,7 +727,10 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                                     shape = RoundedCornerShape(10.dp)
                                 )
                         ) {
-                            Box(contentAlignment = Alignment.Center, modifier = Modifier.size(64.dp)) {
+                            Box(
+                                contentAlignment = Alignment.Center,
+                                modifier = Modifier.size(64.dp)
+                            ) {
                                 Icon(
                                     painter = painterResource(id = R.drawable.account_circle),
                                     contentDescription = "Go to profile",
@@ -472,11 +743,46 @@ fun UserProfileScreen(navController: NavHostController, viewModel: MainViewModel
                 }
             }
         }
-    } else{
+    } else {
         CircularProgressIndicator()
     }
 }
 
+fun ByteArrayImage(byteArray: ByteArray): ImageBitmap {
+    // Конвертируем массив байтов в Bitmap с уменьшением масштаба
+    val options = BitmapFactory.Options().apply {
+        inJustDecodeBounds = true // Сначала считываем только размеры изображения
+    }
+    BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size, options)
+
+    // Рассчитываем inSampleSize для уменьшения изображения
+    options.inSampleSize = calculateInSampleSize(options, reqWidth = 300, reqHeight = 200)
+    options.inJustDecodeBounds = false // Теперь декодируем само изображение
+
+    // Декодируем уменьшенное изображение
+    val bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size, options)
+
+    // Преобразуем Bitmap в ImageBitmap
+    return bitmap.asImageBitmap()
+
+
+}
+
+
+fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, reqHeight: Int): Int {
+    val (height: Int, width: Int) = options.outHeight to options.outWidth
+    var inSampleSize = 1
+
+    if (height > reqHeight || width > reqWidth) {
+        val halfHeight: Int = height / 2
+        val halfWidth: Int = width / 2
+
+        while (halfHeight / inSampleSize >= reqHeight && halfWidth / inSampleSize >= reqWidth) {
+            inSampleSize *= 2
+        }
+    }
+    return inSampleSize
+}
 
 @Preview(showBackground = true)
 @Composable

BIN
Скриншоты дизайна/Страницы создания принта на одежде.png