From c3e82ff61b88194bb43b35bb472d6407af72f7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 24 Dec 2023 17:54:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D1=87=D0=B5=D0=BC=20=D1=8F=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=20=D0=B4=D0=B5=D0=BB=D0=B0=D1=8E,=20=D0=B5?= =?UTF-8?q?=D1=81=D0=BB=D0=B8=20=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=8C=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D1=82?= =?UTF-8?q?=D1=8C=20=D1=80=D0=BE=D0=BB=D0=B8...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entities/composeui/UserProfile.kt | 117 ++++++++++++++---- 1 file changed, 90 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt index 4710701..9b96155 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt @@ -2,6 +2,8 @@ package com.example.myapplication.database.entities.composeui import android.annotation.SuppressLint import android.util.Log +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -12,13 +14,19 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Warning import androidx.compose.material3.Button +import androidx.compose.material3.Card +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Switch import androidx.compose.material3.SwitchDefaults @@ -37,6 +45,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.PasswordVisualTransformation +import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel @@ -62,6 +71,9 @@ fun UserProfile( var password by remember { mutableStateOf("") } var isRegistration by remember { mutableStateOf(false) } var isAuto by remember { mutableStateOf(false) } + var isPasswordVisible by remember { mutableStateOf(false) } + + var isCardVisible by remember { mutableStateOf(false) } val coroutineScope = rememberCoroutineScope() @@ -72,15 +84,10 @@ fun UserProfile( } entryUserViewModel.setUserList() - val users_entry = mutableStateOf>(entryUserViewModel.userList) - var getUser by remember { mutableStateOf(currentUserViewModel.user) } - // Проверяем, авторизован пользователь или нет if (getUser?.uid != null) { - LoginScreenProfile(currentUserViewModel, navController) - } else { LazyColumn { @@ -125,14 +132,16 @@ fun UserProfile( RoundedCornerShape(18.dp) ) .padding(start = 13.dp, top = 8.dp), - visualTransformation = PasswordVisualTransformation() + visualTransformation = if (isPasswordVisible) VisualTransformation.None else PasswordVisualTransformation() + ) if (isRegistration) { Button( onClick = { coroutineScope.launch { - val registrationSuccessful = registerUserViewModel.registerUser(username, password) + val registrationSuccessful = + registerUserViewModel.registerUser(username, password) if (registrationSuccessful) { navController?.navigate(Screen.LoginScreen.route) } else { @@ -147,13 +156,13 @@ fun UserProfile( Text("Регистрация") } Text( - text = "Уже есть аккаунт? Войти", + text = "Войти", modifier = Modifier .clickable { isRegistration = false } .align(Alignment.CenterHorizontally), - color = MaterialTheme.colorScheme.onBackground + color = MaterialTheme.colorScheme.onSurface ) } else { Button( @@ -173,13 +182,13 @@ fun UserProfile( Text("Вход") } Text( - text = "Нет аккаунта? Зарегистрироваться", + text = "Зарегистрироваться", modifier = Modifier .clickable { isRegistration = true } .align(Alignment.CenterHorizontally), - color = MaterialTheme.colorScheme.onBackground + color = MaterialTheme.colorScheme.onSurface ) } val switchColors = SwitchDefaults.colors( @@ -188,30 +197,84 @@ fun UserProfile( uncheckedThumbColor = MaterialTheme.colorScheme.primary, // Change the color when the switch is unchecked uncheckedTrackColor = MaterialTheme.colorScheme.onPrimary // Change the color of the track when the switch is unchecked ) - Row( + Column( modifier = Modifier .fillMaxWidth() - .padding(16.dp), - horizontalArrangement = Arrangement.End ) { + // Заголовок Text( - "Темная тема", modifier = Modifier - .align(Alignment.CenterVertically) - .padding(5.dp) + text = "Настройки", + modifier = Modifier + .fillMaxWidth() + .clickable { isCardVisible = !isCardVisible } + .padding(16.dp), + textAlign = TextAlign.Center, + color = MaterialTheme.colorScheme.onSurface ) - val coroutine = rememberCoroutineScope() + // Анимированная видимость Card + AnimatedVisibility(visible = isCardVisible) { + Card( + border = BorderStroke(2.dp, MaterialTheme.colorScheme.onBackground), + modifier = Modifier + .background(MaterialTheme.colorScheme.background) + .fillMaxWidth() + .padding(16.dp) + ) { + Column( + modifier = Modifier + .background(MaterialTheme.colorScheme.background) + .fillMaxWidth() + .padding(16.dp), + verticalArrangement = Arrangement.Center + ) { + Text( + "Темная тема", + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(5.dp), + color = MaterialTheme.colorScheme.onSurface + ) - Switch( - checked = isDarkTheme.value, - onCheckedChange = { - isDarkTheme.value = !isDarkTheme.value - coroutine.launch { - dataStoreManager.saveSettings(SettingData(isDarkTheme = isDarkTheme.value)) + val coroutine = rememberCoroutineScope() + + Switch( + checked = isDarkTheme.value, + onCheckedChange = { + isDarkTheme.value = !isDarkTheme.value + coroutine.launch { + dataStoreManager.saveSettings( + SettingData( + isDarkTheme = isDarkTheme.value + ) + ) + } + }, + colors = switchColors, + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(5.dp) + ) + + Text( + "Показывать содержимое пароля", + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(5.dp), + color = MaterialTheme.colorScheme.onSurface + ) + + Switch( + checked = isPasswordVisible, + onCheckedChange = { isPasswordVisible = it }, + colors = switchColors, + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(5.dp) + ) } - }, - colors = switchColors - ) + } + } } } }