init en cours

pull/51/head
Leni BEAULATON 3 weeks ago
parent 1830ededb9
commit 5ed3f5f1ec

@ -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)
}
}

@ -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
)

@ -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> = _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)
}
}
}
Loading…
Cancel
Save