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

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.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<List<User>>(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
)
}
}
}
}
}