From 819ef8d73960b2229125b0ee73853705dd85b61c Mon Sep 17 00:00:00 2001 From: beaulaton Date: Fri, 21 Mar 2025 11:29:36 +0100 Subject: [PATCH] viewModel password fonctionne aussi --- .../what_the_fantasy/ui/screens/LoginPage.kt | 15 ++++++++------- .../ui/viewModels/AuthUserViewModel.kt | 4 ++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt index a8d0ba0..243e9dd 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt @@ -70,7 +70,9 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni SpaceHeightComponent(20) ConnexionButtonLogin(users,IdentifiantTextField(R.string.IdentifiantLogin, authState.username){ authUserVM.setUsername(it) - }, PassWdTextField(R.string.PasswdLogin), R.string.ButtonLogin,18,navControllerProfil) + }, PassWdTextField(R.string.PasswdLogin, authState.password){ + authUserVM.setPassword(it) + }, R.string.ButtonLogin,18,navControllerProfil) SpaceHeightComponent(16) CreateAccountButton(R.string.ButtonCreateLogin,12, MaterialTheme.colorScheme.primary, navControllerSignUp) } @@ -83,7 +85,6 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni @Composable fun IdentifiantTextField(textIdentifiantResId : Int, username : String, onValueChange: (String) -> Unit ) : String{ val textIdentifiant = stringResource(id = textIdentifiantResId) - //var identifiant by remember { mutableStateOf("") } Column(modifier = Modifier.padding(top = 16.dp)) { OutlinedTextField( @@ -101,14 +102,14 @@ fun IdentifiantTextField(textIdentifiantResId : Int, username : String, onValueC } @Composable -fun PassWdTextField(textpasswdResId : Int) : String{ +fun PassWdTextField(textpasswdResId : Int, password : String, onValueChange: (String) -> Unit) : String{ val textpasswd = stringResource(id = textpasswdResId) - var passwd by remember { mutableStateOf("") } var passwordVisible by remember { mutableStateOf(false) } + Column(modifier = Modifier.padding(top = 10.dp, bottom = 30.dp)) { OutlinedTextField( - value = passwd, - onValueChange = { passwd = it }, + value = password, + onValueChange = onValueChange, label = { Text(textpasswd) }, modifier = Modifier .fillMaxWidth() @@ -122,7 +123,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{ shape = RoundedCornerShape(16.dp) ) } - return passwd; + return password; } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/AuthUserViewModel.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/AuthUserViewModel.kt index 1321f12..59f1ef2 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/AuthUserViewModel.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/AuthUserViewModel.kt @@ -17,4 +17,8 @@ class AuthUserViewModel : ViewModel(){ fun setUsername(username : String){ _userState.update { it.copy(username=username) } } + + fun setPassword(password : String){ + _userState.update { it.copy(password=password) } + } } \ No newline at end of file