parent
1d9d3edc69
commit
1830ededb9
@ -0,0 +1,73 @@
|
||||
package com.example.what_the_fantasy.ui.viewModels
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
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
|
||||
|
||||
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()
|
||||
|
||||
|
||||
fun setId(id : Int){
|
||||
_currentUserState.update {it.copy(id = id)}
|
||||
}
|
||||
|
||||
fun setUsername(username : String){
|
||||
_currentUserState.update {it.copy(username = username)}
|
||||
}
|
||||
|
||||
fun setEmail(email : String){
|
||||
_currentUserState.update {it.copy(email = email)}
|
||||
}
|
||||
|
||||
fun setPassword(password : String){
|
||||
_currentUserState.update {it.copy(password = password)}
|
||||
}
|
||||
|
||||
fun setConfirmPassword(password : String){
|
||||
_currentUserState.update {it.copy(confirmPassword = password)}
|
||||
}
|
||||
|
||||
fun setLangue(langue : SrcLanguage){
|
||||
_currentUserState.update {it.copy(langue = langue)}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fun editUsername(username : String, index : Int) : Boolean{
|
||||
_currentUserState.update {it.copy(username = username)}
|
||||
return services.EditUsername(username, index)
|
||||
}
|
||||
|
||||
fun editEmail(email : String, index : Int) : Boolean{
|
||||
_currentUserState.update {
|
||||
it.copy(email = email)
|
||||
}
|
||||
return services.EditEmail(email, index)
|
||||
}
|
||||
|
||||
fun editPassword(password : String, index : Int){
|
||||
services.EditPasswd(password, index)
|
||||
|
||||
_currentUserState.update {
|
||||
it.copy(password = password)
|
||||
}
|
||||
}
|
||||
|
||||
fun editLangue(index : Int){
|
||||
val langage = services.ChangeLangage(index)
|
||||
|
||||
_currentUserState.update {
|
||||
it.copy(langue = langage)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.example.what_the_fantasy.ui.viewModels
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.example.what_the_fantasy.data.services.ServicesStub
|
||||
import com.example.what_the_fantasy.ui.states.InfoUserState
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
class InfoUserViewModel : ViewModel(){
|
||||
private val services = ServicesStub() // faire repository qui gère les services Stub et API
|
||||
private val _userInfoState = MutableStateFlow(InfoUserState())
|
||||
val InfoUserState : StateFlow<InfoUserState> = _userInfoState.asStateFlow()
|
||||
|
||||
fun setUsername(username : String){
|
||||
_userInfoState.update { it.copy(username=username) }
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue