From 5ed3f5f1ec56a6e909c524716a07314a75c562c2 Mon Sep 17 00:00:00 2001 From: "leni.beaulaton" Date: Sat, 29 Mar 2025 16:58:23 +0100 Subject: [PATCH] init en cours --- .../what_the_fantasy/ui/screens/ProfilPage.kt | 11 +++------- .../ui/states/CurrentUserState.kt | 2 +- .../ui/viewModels/CurrentUserViewModel.kt | 22 ++++++++++++++++--- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt index 877603a..1980730 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt @@ -49,8 +49,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel import coil.compose.AsyncImage import com.example.what_the_fantasy.Logs.LogsUsers import com.example.what_the_fantasy.R -import com.example.what_the_fantasy.data.model.SrcLanguage -import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent import com.example.what_the_fantasy.ui.components.NavBar @@ -58,8 +56,6 @@ import com.example.what_the_fantasy.ui.components.SpaceHeightComponent import com.example.what_the_fantasy.ui.components.TitlePageComponent import com.example.what_the_fantasy.ui.components.VisibleIconPasswordComponent import com.example.what_the_fantasy.ui.states.CurrentUserState -import com.example.what_the_fantasy.ui.theme.gradienBox -import com.example.what_the_fantasy.ui.viewModels.AuthUserViewModel import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel @Composable @@ -71,7 +67,6 @@ fun ProfilPage(index: Int, navSubmitQuote: () -> Unit, services: IServices ) { - val user = services.getUserById(index) ?: return val currentUserVM : CurrentUserViewModel = viewModel() val currentUserState by currentUserVM.currentUserState.collectAsState() @@ -104,7 +99,7 @@ fun ProfilPage(index: Int, SpaceHeightComponent(16) // Image de profil - ImageProfil(user.imgUrl, 120) + ImageProfil(currentUserState.imagePath, 120) SpaceHeightComponent(16) EditUsername(currentUserState.username, index, currentUserVM)// Édition du Username @@ -476,12 +471,12 @@ fun ButtonLanguage(textResId : Int, size :Int, colorButton : Color, currentUserV Button( onClick = { - currentUserVM.editLangue(10) // a mettre a la place : currentUserState.id + currentUserVM.editLangue(currentUserState.id) }, colors = ButtonDefaults.buttonColors(containerColor = colorButton), modifier = Modifier.fillMaxWidth(), ) { - Text("${text} (${currentUserState.langue})", fontSize = size.sp, color = MaterialTheme.colorScheme.primary) + Text("${text} (${currentUserState.langage})", fontSize = size.sp, color = MaterialTheme.colorScheme.primary) } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/states/CurrentUserState.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/states/CurrentUserState.kt index 290b6c5..cc1a7f6 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/states/CurrentUserState.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/states/CurrentUserState.kt @@ -9,5 +9,5 @@ data class CurrentUserState ( var email : String="", var password : String="", var confirmPassword : String="", - val langue : SrcLanguage = SrcLanguage.vo + val langage : SrcLanguage = SrcLanguage.vo ) \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/CurrentUserViewModel.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/CurrentUserViewModel.kt index 5cf381b..6a65d70 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/CurrentUserViewModel.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/CurrentUserViewModel.kt @@ -1,20 +1,33 @@ package com.example.what_the_fantasy.ui.viewModels import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.example.what_the_fantasy.data.model.SrcLanguage -import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.services.ServicesStub import com.example.what_the_fantasy.ui.states.CurrentUserState import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch class CurrentUserViewModel : ViewModel(){ private val services = ServicesStub() // faire repository qui gère les services Stub et API private val _currentUserState = MutableStateFlow(CurrentUserState()) var currentUserState : StateFlow = _currentUserState.asStateFlow() + init{ + viewModelScope.launch { + services.getUserById(10)?.let { // A changer : renvoie le meme user pour le moment + setId(it.id) + setUsername(it.username) + setEmail(it.email) + setPassword(it.password) + setLangue(it.langage) + setImage(it.imgUrl) + } + } + } fun setId(id : Int){ _currentUserState.update {it.copy(id = id)} @@ -37,7 +50,10 @@ class CurrentUserViewModel : ViewModel(){ } fun setLangue(langue : SrcLanguage){ - _currentUserState.update {it.copy(langue = langue)} + _currentUserState.update {it.copy(langage = langue)} + } + fun setImage(imagePath : String){ + _currentUserState.update {it.copy(imagePath = imagePath)} } @@ -67,7 +83,7 @@ class CurrentUserViewModel : ViewModel(){ val langage = services.ChangeLangage(index) _currentUserState.update { - it.copy(langue = langage) + it.copy(langage = langage) } } } \ No newline at end of file