Какой то кринж, но рабочий кринж
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,8 +69,18 @@ fun UserProfile(
|
|||||||
entryUserViewModel.setUserList()
|
entryUserViewModel.setUserList()
|
||||||
val users_entry = mutableStateOf<List<User>>(entryUserViewModel.userList)
|
val users_entry = mutableStateOf<List<User>>(entryUserViewModel.userList)
|
||||||
|
|
||||||
|
var getUser by remember { mutableStateOf(currentUserViewModel.user) }
|
||||||
|
|
||||||
|
// Проверяем, авторизован пользователь или нет
|
||||||
|
if (getUser?.uid != null) {
|
||||||
|
// Пользователь авторизован, отображаем страницу профиля
|
||||||
|
// Замените на ваш код для страницы профиля
|
||||||
|
// Например, использовать другой @Composable или навигировать на другой экран
|
||||||
|
Text("Это страница профиля")
|
||||||
|
} else {
|
||||||
|
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
item {
|
item(key = isAuto) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
@ -80,7 +98,10 @@ fun UserProfile(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.size(36.dp)
|
.size(36.dp)
|
||||||
.background(MaterialTheme.colorScheme.onBackground, RoundedCornerShape(18.dp))
|
.background(
|
||||||
|
MaterialTheme.colorScheme.onBackground,
|
||||||
|
RoundedCornerShape(18.dp)
|
||||||
|
)
|
||||||
.padding(start = 13.dp, top = 8.dp)
|
.padding(start = 13.dp, top = 8.dp)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -95,7 +116,10 @@ fun UserProfile(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.size(36.dp)
|
.size(36.dp)
|
||||||
.background(MaterialTheme.colorScheme.onBackground, RoundedCornerShape(18.dp))
|
.background(
|
||||||
|
MaterialTheme.colorScheme.onBackground,
|
||||||
|
RoundedCornerShape(18.dp)
|
||||||
|
)
|
||||||
.padding(start = 13.dp, top = 8.dp),
|
.padding(start = 13.dp, top = 8.dp),
|
||||||
visualTransformation = PasswordVisualTransformation()
|
visualTransformation = PasswordVisualTransformation()
|
||||||
)
|
)
|
||||||
@ -107,7 +131,10 @@ fun UserProfile(
|
|||||||
if (password.isNotEmpty() && username.isNotEmpty()) {
|
if (password.isNotEmpty() && username.isNotEmpty()) {
|
||||||
users.value.forEach { user ->
|
users.value.forEach { user ->
|
||||||
if (user.login == username) {
|
if (user.login == username) {
|
||||||
Log.d("User already exist. User id: ", user.uid.toString())
|
Log.d(
|
||||||
|
"User already exist. User id: ",
|
||||||
|
user.uid.toString()
|
||||||
|
)
|
||||||
isExist = true
|
isExist = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,7 +150,11 @@ fun UserProfile(
|
|||||||
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(
|
||||||
|
Log.ASSERT,
|
||||||
|
"UsersList",
|
||||||
|
users.value.toString()
|
||||||
|
)
|
||||||
users.value?.forEach { user ->
|
users.value?.forEach { user ->
|
||||||
if (user.password == password) {
|
if (user.password == password) {
|
||||||
currentUserViewModel.setArgument(user.uid.toString())
|
currentUserViewModel.setArgument(user.uid.toString())
|
||||||
@ -158,7 +189,9 @@ fun UserProfile(
|
|||||||
users_entry.value.forEach { user ->
|
users_entry.value.forEach { user ->
|
||||||
if (user.password == password) {
|
if (user.password == password) {
|
||||||
currentUserViewModel.setArgument(user.uid.toString())
|
currentUserViewModel.setArgument(user.uid.toString())
|
||||||
Log.d("Авторизация","Успешно")
|
navController?.navigate(Screen.LoginScreen.route)
|
||||||
|
/* navController?.navigate(Screen.UserProfile.route)
|
||||||
|
navController?.popBackStack()*/
|
||||||
//navController.navigate(route = Graph.passUserId(user.id.toString())) {
|
//navController.navigate(route = Graph.passUserId(user.id.toString())) {
|
||||||
} else {
|
} else {
|
||||||
Log.d("Авторизация", "Пароль не совпадает")
|
Log.d("Авторизация", "Пароль не совпадает")
|
||||||
@ -218,6 +251,36 @@ fun UserProfile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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)
|
||||||
|
Loading…
Reference in New Issue
Block a user