Зачем я это делаю, если надо делать отчеты и добавлять роли...

This commit is contained in:
Кашин Максим 2023-12-24 17:54:42 +04:00
parent 0456d68b16
commit c3e82ff61b

View File

@ -2,6 +2,8 @@ package com.example.myapplication.database.entities.composeui
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.util.Log import android.util.Log
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable 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.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField 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.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.MaterialTheme
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults 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.TextStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation 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.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
@ -62,6 +71,9 @@ fun UserProfile(
var password by remember { mutableStateOf("") } var password by remember { mutableStateOf("") }
var isRegistration by remember { mutableStateOf(false) } var isRegistration by remember { mutableStateOf(false) }
var isAuto 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() val coroutineScope = rememberCoroutineScope()
@ -72,15 +84,10 @@ fun UserProfile(
} }
entryUserViewModel.setUserList() entryUserViewModel.setUserList()
val users_entry = mutableStateOf<List<User>>(entryUserViewModel.userList)
var getUser by remember { mutableStateOf(currentUserViewModel.user) } var getUser by remember { mutableStateOf(currentUserViewModel.user) }
// Проверяем, авторизован пользователь или нет
if (getUser?.uid != null) { if (getUser?.uid != null) {
LoginScreenProfile(currentUserViewModel, navController) LoginScreenProfile(currentUserViewModel, navController)
} else { } else {
LazyColumn { LazyColumn {
@ -125,14 +132,16 @@ fun UserProfile(
RoundedCornerShape(18.dp) RoundedCornerShape(18.dp)
) )
.padding(start = 13.dp, top = 8.dp), .padding(start = 13.dp, top = 8.dp),
visualTransformation = PasswordVisualTransformation() visualTransformation = if (isPasswordVisible) VisualTransformation.None else PasswordVisualTransformation()
) )
if (isRegistration) { if (isRegistration) {
Button( Button(
onClick = { onClick = {
coroutineScope.launch { coroutineScope.launch {
val registrationSuccessful = registerUserViewModel.registerUser(username, password) val registrationSuccessful =
registerUserViewModel.registerUser(username, password)
if (registrationSuccessful) { if (registrationSuccessful) {
navController?.navigate(Screen.LoginScreen.route) navController?.navigate(Screen.LoginScreen.route)
} else { } else {
@ -147,13 +156,13 @@ fun UserProfile(
Text("Регистрация") Text("Регистрация")
} }
Text( Text(
text = "Уже есть аккаунт? Войти", text = "Войти",
modifier = Modifier modifier = Modifier
.clickable { .clickable {
isRegistration = false isRegistration = false
} }
.align(Alignment.CenterHorizontally), .align(Alignment.CenterHorizontally),
color = MaterialTheme.colorScheme.onBackground color = MaterialTheme.colorScheme.onSurface
) )
} else { } else {
Button( Button(
@ -173,13 +182,13 @@ fun UserProfile(
Text("Вход") Text("Вход")
} }
Text( Text(
text = "Нет аккаунта? Зарегистрироваться", text = "Зарегистрироваться",
modifier = Modifier modifier = Modifier
.clickable { .clickable {
isRegistration = true isRegistration = true
} }
.align(Alignment.CenterHorizontally), .align(Alignment.CenterHorizontally),
color = MaterialTheme.colorScheme.onBackground color = MaterialTheme.colorScheme.onSurface
) )
} }
val switchColors = SwitchDefaults.colors( val switchColors = SwitchDefaults.colors(
@ -188,16 +197,43 @@ fun UserProfile(
uncheckedThumbColor = MaterialTheme.colorScheme.primary, // Change the color when the switch is unchecked 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 uncheckedTrackColor = MaterialTheme.colorScheme.onPrimary // Change the color of the track when the switch is unchecked
) )
Row( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
) {
// Заголовок
Text(
text = "Настройки",
modifier = Modifier
.fillMaxWidth()
.clickable { isCardVisible = !isCardVisible }
.padding(16.dp), .padding(16.dp),
horizontalArrangement = Arrangement.End textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.onSurface
)
// Анимированная видимость 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( Text(
"Темная тема", modifier = Modifier "Темная тема",
.align(Alignment.CenterVertically) modifier = Modifier
.padding(5.dp) .align(Alignment.CenterHorizontally)
.padding(5.dp),
color = MaterialTheme.colorScheme.onSurface
) )
val coroutine = rememberCoroutineScope() val coroutine = rememberCoroutineScope()
@ -207,11 +243,38 @@ fun UserProfile(
onCheckedChange = { onCheckedChange = {
isDarkTheme.value = !isDarkTheme.value isDarkTheme.value = !isDarkTheme.value
coroutine.launch { coroutine.launch {
dataStoreManager.saveSettings(SettingData(isDarkTheme = isDarkTheme.value)) dataStoreManager.saveSettings(
SettingData(
isDarkTheme = isDarkTheme.value
)
)
} }
}, },
colors = switchColors 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)
)
}
}
}
} }
} }
} }