|
@@ -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
|