Какой то кринж, но рабочий кринж
This commit is contained in:
parent
ef9a391caf
commit
212ef57bff
@ -52,6 +52,7 @@ import com.example.myapplication.database.entities.composeui.AppViewModelProvide
|
|||||||
import com.example.myapplication.database.entities.composeui.BikeList
|
import com.example.myapplication.database.entities.composeui.BikeList
|
||||||
import com.example.myapplication.database.entities.composeui.BikeView
|
import com.example.myapplication.database.entities.composeui.BikeView
|
||||||
import com.example.myapplication.database.entities.composeui.CurrentUserViewModel
|
import com.example.myapplication.database.entities.composeui.CurrentUserViewModel
|
||||||
|
import com.example.myapplication.database.entities.composeui.LoginScreen
|
||||||
import com.example.myapplication.database.entities.composeui.RentList
|
import com.example.myapplication.database.entities.composeui.RentList
|
||||||
import com.example.myapplication.database.entities.composeui.RentView
|
import com.example.myapplication.database.entities.composeui.RentView
|
||||||
import com.example.myapplication.database.entities.composeui.UserProfile
|
import com.example.myapplication.database.entities.composeui.UserProfile
|
||||||
@ -188,7 +189,8 @@ fun Navhost(
|
|||||||
composable(Screen.BikeList.route) { BikeList(navController, currentUserViewModel = currentUserViewModel) }
|
composable(Screen.BikeList.route) { BikeList(navController, currentUserViewModel = currentUserViewModel) }
|
||||||
composable(Screen.RentList.route) { RentList(navController, currentUserViewModel = currentUserViewModel) }
|
composable(Screen.RentList.route) { RentList(navController, currentUserViewModel = currentUserViewModel) }
|
||||||
composable(Screen.Cart.route) { Cart(currentUserViewModel = currentUserViewModel) }
|
composable(Screen.Cart.route) { Cart(currentUserViewModel = currentUserViewModel) }
|
||||||
composable(Screen.UserProfile.route) { UserProfile(isDarkTheme, dataStore, currentUserViewModel = currentUserViewModel) }
|
composable(Screen.UserProfile.route) { UserProfile(navController,isDarkTheme, dataStore, currentUserViewModel = currentUserViewModel) }
|
||||||
|
composable(Screen.LoginScreen.route) { LoginScreen(navController) }
|
||||||
composable(
|
composable(
|
||||||
Screen.BikeEdit.route,
|
Screen.BikeEdit.route,
|
||||||
arguments = listOf(navArgument("id") { type = NavType.IntType })
|
arguments = listOf(navArgument("id") { type = NavType.IntType })
|
||||||
|
@ -18,6 +18,9 @@ enum class Screen(
|
|||||||
BikeList(
|
BikeList(
|
||||||
"Bike-list", R.string.Bike_main_title, Icons.Filled.Home
|
"Bike-list", R.string.Bike_main_title, Icons.Filled.Home
|
||||||
),
|
),
|
||||||
|
LoginScreen(
|
||||||
|
"Login-screen", R.string.Profile_title, Icons.Filled.Home
|
||||||
|
),
|
||||||
BikeEdit(
|
BikeEdit(
|
||||||
"Bike-edit/{id}", R.string.Bike_view_title, showInBottomBar = false
|
"Bike-edit/{id}", R.string.Bike_view_title, showInBottomBar = false
|
||||||
),
|
),
|
||||||
|
@ -7,8 +7,10 @@ import androidx.compose.foundation.clickable
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
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.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
|
||||||
@ -29,9 +31,13 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.TextStyle
|
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.PasswordVisualTransformation
|
||||||
|
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
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import com.example.myapplication.composeui.navigation.Screen
|
||||||
import com.example.myapplication.database.entities.model.User
|
import com.example.myapplication.database.entities.model.User
|
||||||
import com.example.myapplication.datastore.DataStoreManager
|
import com.example.myapplication.datastore.DataStoreManager
|
||||||
import com.example.myapplication.datastore.SettingData
|
import com.example.myapplication.datastore.SettingData
|
||||||
@ -40,6 +46,7 @@ import kotlinx.coroutines.launch
|
|||||||
@SuppressLint("UnrememberedMutableState")
|
@SuppressLint("UnrememberedMutableState")
|
||||||
@Composable
|
@Composable
|
||||||
fun UserProfile(
|
fun UserProfile(
|
||||||
|
navController: NavController?,
|
||||||
isDarkTheme: MutableState<Boolean>,
|
isDarkTheme: MutableState<Boolean>,
|
||||||
dataStoreManager: DataStoreManager,
|
dataStoreManager: DataStoreManager,
|
||||||
registerUserViewModel: RegisterUserViewModel = viewModel(factory = AppViewModelProvider.Factory),
|
registerUserViewModel: RegisterUserViewModel = viewModel(factory = AppViewModelProvider.Factory),
|
||||||
@ -49,6 +56,7 @@ fun UserProfile(
|
|||||||
var username by remember { mutableStateOf("") }
|
var username by remember { mutableStateOf("") }
|
||||||
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) }
|
||||||
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
@ -61,164 +69,219 @@ fun UserProfile(
|
|||||||
entryUserViewModel.setUserList()
|
entryUserViewModel.setUserList()
|
||||||
val users_entry = mutableStateOf<List<User>>(entryUserViewModel.userList)
|
val users_entry = mutableStateOf<List<User>>(entryUserViewModel.userList)
|
||||||
|
|
||||||
LazyColumn {
|
var getUser by remember { mutableStateOf(currentUserViewModel.user) }
|
||||||
item {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "Логин",
|
|
||||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
|
||||||
)
|
|
||||||
BasicTextField(
|
|
||||||
value = username,
|
|
||||||
textStyle = TextStyle(color = MaterialTheme.colorScheme.background),
|
|
||||||
onValueChange = { newValue -> username = newValue },
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.size(36.dp)
|
|
||||||
.background(MaterialTheme.colorScheme.onBackground, RoundedCornerShape(18.dp))
|
|
||||||
.padding(start = 13.dp, top = 8.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
Text(
|
// Проверяем, авторизован пользователь или нет
|
||||||
text = "Пароль",
|
if (getUser?.uid != null) {
|
||||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
// Пользователь авторизован, отображаем страницу профиля
|
||||||
)
|
// Замените на ваш код для страницы профиля
|
||||||
BasicTextField(
|
// Например, использовать другой @Composable или навигировать на другой экран
|
||||||
value = password,
|
Text("Это страница профиля")
|
||||||
textStyle = TextStyle(color = MaterialTheme.colorScheme.background),
|
} else {
|
||||||
onValueChange = { newValue -> password = newValue },
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.size(36.dp)
|
|
||||||
.background(MaterialTheme.colorScheme.onBackground, RoundedCornerShape(18.dp))
|
|
||||||
.padding(start = 13.dp, top = 8.dp),
|
|
||||||
visualTransformation = PasswordVisualTransformation()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (isRegistration) {
|
LazyColumn {
|
||||||
Button(
|
item(key = isAuto) {
|
||||||
onClick = {
|
Column(
|
||||||
var isExist = false;
|
modifier = Modifier
|
||||||
if (password.isNotEmpty() && username.isNotEmpty()) {
|
.fillMaxSize()
|
||||||
users.value.forEach { user ->
|
.padding(16.dp),
|
||||||
if (user.login == username) {
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
Log.d("User already exist. User id: ", user.uid.toString())
|
) {
|
||||||
isExist = true
|
Text(
|
||||||
}
|
text = "Логин",
|
||||||
}
|
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||||
if (!isExist) {
|
)
|
||||||
val newUser = User(null, username, password)
|
BasicTextField(
|
||||||
coroutineScope.launch {
|
value = username,
|
||||||
val insertResult = async {
|
textStyle = TextStyle(color = MaterialTheme.colorScheme.background),
|
||||||
registerUserViewModel.insertUser(newUser)
|
onValueChange = { newValue -> username = newValue },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.size(36.dp)
|
||||||
|
.background(
|
||||||
|
MaterialTheme.colorScheme.onBackground,
|
||||||
|
RoundedCornerShape(18.dp)
|
||||||
|
)
|
||||||
|
.padding(start = 13.dp, top = 8.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "Пароль",
|
||||||
|
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||||
|
)
|
||||||
|
BasicTextField(
|
||||||
|
value = password,
|
||||||
|
textStyle = TextStyle(color = MaterialTheme.colorScheme.background),
|
||||||
|
onValueChange = { newValue -> password = newValue },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.size(36.dp)
|
||||||
|
.background(
|
||||||
|
MaterialTheme.colorScheme.onBackground,
|
||||||
|
RoundedCornerShape(18.dp)
|
||||||
|
)
|
||||||
|
.padding(start = 13.dp, top = 8.dp),
|
||||||
|
visualTransformation = PasswordVisualTransformation()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isRegistration) {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
var isExist = false;
|
||||||
|
if (password.isNotEmpty() && username.isNotEmpty()) {
|
||||||
|
users.value.forEach { user ->
|
||||||
|
if (user.login == username) {
|
||||||
|
Log.d(
|
||||||
|
"User already exist. User id: ",
|
||||||
|
user.uid.toString()
|
||||||
|
)
|
||||||
|
isExist = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!isExist) {
|
||||||
|
val newUser = User(null, username, password)
|
||||||
|
coroutineScope.launch {
|
||||||
|
val insertResult = async {
|
||||||
|
registerUserViewModel.insertUser(newUser)
|
||||||
|
}
|
||||||
|
|
||||||
insertResult.await()
|
insertResult.await()
|
||||||
|
|
||||||
registerUserViewModel.setUserList()
|
registerUserViewModel.setUserList()
|
||||||
registerUserViewModel.users.observeForever { userList ->
|
registerUserViewModel.users.observeForever { userList ->
|
||||||
users.value = userList
|
users.value = userList
|
||||||
Log.println(Log.ASSERT, "UsersList", users.value.toString())
|
Log.println(
|
||||||
users.value?.forEach { user ->
|
Log.ASSERT,
|
||||||
if (user.password == password) {
|
"UsersList",
|
||||||
currentUserViewModel.setArgument(user.uid.toString())
|
users.value.toString()
|
||||||
//navController.navigate(route = Graph.passUserId(user.id.toString()))
|
)
|
||||||
|
users.value?.forEach { user ->
|
||||||
|
if (user.password == password) {
|
||||||
|
currentUserViewModel.setArgument(user.uid.toString())
|
||||||
|
//navController.navigate(route = Graph.passUserId(user.id.toString()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.fillMaxWidth()
|
||||||
.fillMaxWidth()
|
.padding(8.dp)
|
||||||
.padding(8.dp)
|
) {
|
||||||
) {
|
Text("Регистрация")
|
||||||
Text("Регистрация")
|
}
|
||||||
}
|
Text(
|
||||||
Text(
|
text = "Уже есть аккаунт? Войти",
|
||||||
text = "Уже есть аккаунт? Войти",
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.clickable {
|
||||||
.clickable {
|
isRegistration = false
|
||||||
isRegistration = false
|
|
||||||
}
|
|
||||||
.align(Alignment.CenterHorizontally),
|
|
||||||
color = MaterialTheme.colorScheme.onBackground
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
Log.d("Кнопка","Тык")
|
|
||||||
if (password.isNotEmpty()) {
|
|
||||||
users_entry.value.forEach { user ->
|
|
||||||
if (user.password == password) {
|
|
||||||
currentUserViewModel.setArgument(user.uid.toString())
|
|
||||||
Log.d("Авторизация","Успешно")
|
|
||||||
//navController.navigate(route = Graph.passUserId(user.id.toString())) {
|
|
||||||
}else{
|
|
||||||
Log.d("Авторизация","Пароль не совпадает")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
.align(Alignment.CenterHorizontally),
|
||||||
},
|
color = MaterialTheme.colorScheme.onBackground
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
Log.d("Кнопка", "Тык")
|
||||||
|
if (password.isNotEmpty()) {
|
||||||
|
users_entry.value.forEach { user ->
|
||||||
|
if (user.password == password) {
|
||||||
|
currentUserViewModel.setArgument(user.uid.toString())
|
||||||
|
navController?.navigate(Screen.LoginScreen.route)
|
||||||
|
/* navController?.navigate(Screen.UserProfile.route)
|
||||||
|
navController?.popBackStack()*/
|
||||||
|
//navController.navigate(route = Graph.passUserId(user.id.toString())) {
|
||||||
|
} else {
|
||||||
|
Log.d("Авторизация", "Пароль не совпадает")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(8.dp)
|
||||||
|
) {
|
||||||
|
Text("Вход")
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = "Нет аккаунта? Зарегистрироваться",
|
||||||
|
modifier = Modifier
|
||||||
|
.clickable {
|
||||||
|
isRegistration = true
|
||||||
|
}
|
||||||
|
.align(Alignment.CenterHorizontally),
|
||||||
|
color = MaterialTheme.colorScheme.onBackground
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val switchColors = SwitchDefaults.colors(
|
||||||
|
checkedThumbColor = MaterialTheme.colorScheme.primary, // Change the color when the switch is checked
|
||||||
|
checkedTrackColor = MaterialTheme.colorScheme.secondary, // Change the color of the track when the switch is checked
|
||||||
|
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(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(8.dp)
|
.padding(16.dp),
|
||||||
|
horizontalArrangement = Arrangement.End
|
||||||
) {
|
) {
|
||||||
Text("Вход")
|
Text(
|
||||||
|
"Темная тема", modifier = Modifier
|
||||||
|
.align(Alignment.CenterVertically)
|
||||||
|
.padding(5.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
val coroutine = rememberCoroutineScope()
|
||||||
|
|
||||||
|
Switch(
|
||||||
|
checked = isDarkTheme.value,
|
||||||
|
onCheckedChange = {
|
||||||
|
isDarkTheme.value = !isDarkTheme.value
|
||||||
|
coroutine.launch {
|
||||||
|
dataStoreManager.saveSettings(SettingData(isDarkTheme = isDarkTheme.value))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
colors = switchColors
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Text(
|
|
||||||
text = "Нет аккаунта? Зарегистрироваться",
|
|
||||||
modifier = Modifier
|
|
||||||
.clickable {
|
|
||||||
isRegistration = true
|
|
||||||
}
|
|
||||||
.align(Alignment.CenterHorizontally),
|
|
||||||
color = MaterialTheme.colorScheme.onBackground
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val switchColors = SwitchDefaults.colors(
|
|
||||||
checkedThumbColor = MaterialTheme.colorScheme.primary, // Change the color when the switch is checked
|
|
||||||
checkedTrackColor = MaterialTheme.colorScheme.secondary, // Change the color of the track when the switch is checked
|
|
||||||
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(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.End
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
"Темная тема", modifier = Modifier
|
|
||||||
.align(Alignment.CenterVertically)
|
|
||||||
.padding(5.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
val coroutine = rememberCoroutineScope()
|
|
||||||
|
|
||||||
Switch(
|
|
||||||
checked = isDarkTheme.value,
|
|
||||||
onCheckedChange = {
|
|
||||||
isDarkTheme.value = !isDarkTheme.value
|
|
||||||
coroutine.launch {
|
|
||||||
dataStoreManager.saveSettings(SettingData(isDarkTheme = isDarkTheme.value))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
colors = switchColors
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LoginScreen(navController: NavController?) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Text("Соедение с ЛК УлГТУ произошло успешно.", fontWeight = FontWeight.Bold)
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
Text(
|
||||||
|
"Для дальнейшей работы, нажмите кнопку \"Готово\".",
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
Log.d("Кнопка", "Тык")
|
||||||
|
navController?.navigate(Screen.BikeList.route)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(8.dp)
|
||||||
|
) {
|
||||||
|
Text("Готово")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
/*@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
@Composable
|
@Composable
|
||||||
|
Loading…
Reference in New Issue
Block a user