|
|
@ -27,6 +27,7 @@ import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.OutlinedTextField
|
|
|
|
import androidx.compose.material3.OutlinedTextField
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
@ -44,9 +45,11 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
|
import coil.compose.AsyncImage
|
|
|
|
import coil.compose.AsyncImage
|
|
|
|
import com.example.what_the_fantasy.Logs.LogsUsers
|
|
|
|
import com.example.what_the_fantasy.Logs.LogsUsers
|
|
|
|
import com.example.what_the_fantasy.R
|
|
|
|
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.model.User
|
|
|
|
import com.example.what_the_fantasy.data.services.IServices
|
|
|
|
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.ErrorMessageProfileComponent
|
|
|
@ -54,7 +57,10 @@ import com.example.what_the_fantasy.ui.components.NavBar
|
|
|
|
import com.example.what_the_fantasy.ui.components.SpaceHeightComponent
|
|
|
|
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.TitlePageComponent
|
|
|
|
import com.example.what_the_fantasy.ui.components.VisibleIconPasswordComponent
|
|
|
|
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.theme.gradienBox
|
|
|
|
|
|
|
|
import com.example.what_the_fantasy.ui.viewModels.AuthUserViewModel
|
|
|
|
|
|
|
|
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ProfilPage(index: Int,
|
|
|
|
fun ProfilPage(index: Int,
|
|
|
@ -66,6 +72,8 @@ fun ProfilPage(index: Int,
|
|
|
|
services: IServices
|
|
|
|
services: IServices
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
val user = services.getUserById(index) ?: return
|
|
|
|
val user = services.getUserById(index) ?: return
|
|
|
|
|
|
|
|
val currentUserVM : CurrentUserViewModel = viewModel()
|
|
|
|
|
|
|
|
val currentUserState by currentUserVM.currentUserState.collectAsState()
|
|
|
|
|
|
|
|
|
|
|
|
NavBar(onProfile = true,
|
|
|
|
NavBar(onProfile = true,
|
|
|
|
index = index,
|
|
|
|
index = index,
|
|
|
@ -99,21 +107,21 @@ fun ProfilPage(index: Int,
|
|
|
|
ImageProfil(user.imgUrl, 120)
|
|
|
|
ImageProfil(user.imgUrl, 120)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
|
|
|
|
EditUsername(user.username, index, services)// Édition du Username
|
|
|
|
EditUsername(currentUserState.username, index, currentUserVM)// Édition du Username
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
|
|
|
|
EditEmail(user.email,index, services)// Édition du Email
|
|
|
|
EditEmail(currentUserState.email,index, currentUserVM)// Édition du Email
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
|
|
|
|
|
|
|
|
EditPasswd(index, services)
|
|
|
|
EditPasswd(index, currentUserVM)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
|
|
|
|
// Bouton
|
|
|
|
// Bouton
|
|
|
|
//ButtonProfile(R.string.ButtonAddQuoteprofile, 18, Color.Black, Color.White,navUnLog) // Pas encore de navigation definie
|
|
|
|
ButtonProfile(R.string.ButtonAddQuoteprofile, 18, MaterialTheme.colorScheme.background,navSubmitQuote) // Pas encore de navigation definie
|
|
|
|
//SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
ButtonLanguage(R.string.ButtonLanguageprofile, 18, MaterialTheme.colorScheme.onPrimary, MaterialTheme.colorScheme.background,services, user)
|
|
|
|
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
ButtonUnLog(R.string.ButtonUnlogprofile, 18, MaterialTheme.colorScheme.onPrimary, MaterialTheme.colorScheme.background,navUnLog)
|
|
|
|
ButtonLanguage(R.string.ButtonLanguageprofile, 18, MaterialTheme.colorScheme.background,currentUserVM, currentUserState)
|
|
|
|
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
ButtonUnLog(R.string.ButtonUnlogprofile, 18, navUnLog)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -136,13 +144,13 @@ fun ImageProfil(imgProfil : String, size :Int){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun EditEmail(userEmail: String, index: Int, service: IServices) {
|
|
|
|
fun EditEmail(emailState: String, index: Int, currentUserVM: CurrentUserViewModel) {
|
|
|
|
var email by remember { mutableStateOf(userEmail) }
|
|
|
|
var email by remember { mutableStateOf(emailState) }
|
|
|
|
var isEditingEmail by remember { mutableStateOf(false) }
|
|
|
|
var isEditingEmail by remember { mutableStateOf(false) }
|
|
|
|
var emailError by remember { mutableStateOf(false) }
|
|
|
|
var emailError by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
|
|
fun onDoneEditing() {
|
|
|
|
fun onDoneEditing() {
|
|
|
|
isEditingEmail =!service.EditEmail(email, index)
|
|
|
|
isEditingEmail =!currentUserVM.editEmail(email, index)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -223,12 +231,12 @@ fun DisplayEmail(email: String, onEdit: () -> Unit) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun EditUsername(userName: String, index: Int, service : IServices) {
|
|
|
|
fun EditUsername(usernameState: String, index: Int, currentUserVM : CurrentUserViewModel) {
|
|
|
|
var username by remember { mutableStateOf(userName) }
|
|
|
|
var username by remember { mutableStateOf(usernameState) }
|
|
|
|
var isEditingUsername by remember { mutableStateOf(false) }
|
|
|
|
var isEditingUsername by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
|
|
fun onDoneEditing() {
|
|
|
|
fun onDoneEditing() {
|
|
|
|
isEditingUsername= !service.EditUsername(username, index)
|
|
|
|
isEditingUsername= !currentUserVM.editUsername(username, index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isEditingUsername) {
|
|
|
|
if (isEditingUsername) {
|
|
|
@ -292,7 +300,7 @@ fun DisplayUsername(username: String, onEdit: () -> Unit) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun EditPasswd(index: Int, service: IServices) {
|
|
|
|
fun EditPasswd(index: Int, currentUserVM: CurrentUserViewModel) {
|
|
|
|
var password by remember { mutableStateOf("*******") } // Mot de passe actuel (affiché comme un masque)
|
|
|
|
var password by remember { mutableStateOf("*******") } // Mot de passe actuel (affiché comme un masque)
|
|
|
|
var isEditingPassword by remember { mutableStateOf(false) }
|
|
|
|
var isEditingPassword by remember { mutableStateOf(false) }
|
|
|
|
var newPassword by remember { mutableStateOf("") }
|
|
|
|
var newPassword by remember { mutableStateOf("") }
|
|
|
@ -303,7 +311,7 @@ fun EditPasswd(index: Int, service: IServices) {
|
|
|
|
// Fonction pour finaliser l'édition du mot de passe et appeler la méthode EditPasswd2
|
|
|
|
// Fonction pour finaliser l'édition du mot de passe et appeler la méthode EditPasswd2
|
|
|
|
fun onDoneEditing() {
|
|
|
|
fun onDoneEditing() {
|
|
|
|
// Appeler EditPasswd pour mettre à jour le mot de passe de l'utilisateur
|
|
|
|
// Appeler EditPasswd pour mettre à jour le mot de passe de l'utilisateur
|
|
|
|
service.EditPasswd(newPassword, index)
|
|
|
|
currentUserVM.editPassword(newPassword, index)
|
|
|
|
isEditingPassword = false
|
|
|
|
isEditingPassword = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -322,12 +330,12 @@ fun EditPasswd(index: Int, service: IServices) {
|
|
|
|
passwordError = passwordError,
|
|
|
|
passwordError = passwordError,
|
|
|
|
onDone = {
|
|
|
|
onDone = {
|
|
|
|
if (!passwordError && newPassword.isNotEmpty()) {
|
|
|
|
if (!passwordError && newPassword.isNotEmpty()) {
|
|
|
|
onDoneEditing() // Appeler la fonction onDoneEditing() pour mettre à jour le mot de passe
|
|
|
|
onDoneEditing() // pour mettre à jour le mot de passe
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
DisplayPassword(onEdit = { isEditingPassword = true }) // Afficher l'option pour modifier le mot de passe
|
|
|
|
DisplayPassword(onEdit = { isEditingPassword = true }) // pour modifier le mot de passe
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -446,7 +454,7 @@ fun DisplayPassword(onEdit: () -> Unit) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ButtonUnLog(textResId : Int, size :Int, colorTexte : Color, colorButton : Color,navController: () -> Unit){
|
|
|
|
fun ButtonUnLog(textResId : Int, size :Int,navController: () -> Unit){
|
|
|
|
val text = stringResource(id = textResId)
|
|
|
|
val text = stringResource(id = textResId)
|
|
|
|
val logsUser = LogsUsers() //gestion des logs pour les utilisateurs
|
|
|
|
val logsUser = LogsUsers() //gestion des logs pour les utilisateurs
|
|
|
|
|
|
|
|
|
|
|
@ -463,23 +471,22 @@ fun ButtonUnLog(textResId : Int, size :Int, colorTexte : Color, colorButton : Co
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ButtonLanguage(textResId : Int, size :Int, colorTexte : Color, colorButton : Color, service: IServices, user : User){
|
|
|
|
fun ButtonLanguage(textResId : Int, size :Int, colorButton : Color, currentUserVM: CurrentUserViewModel, currentUserState : CurrentUserState){
|
|
|
|
val text = stringResource(id = textResId)
|
|
|
|
val text = stringResource(id = textResId)
|
|
|
|
val currentLangage = remember { mutableStateOf(user.langage) }
|
|
|
|
|
|
|
|
Button(
|
|
|
|
Button(
|
|
|
|
onClick = {
|
|
|
|
onClick = {
|
|
|
|
service.ChangeLangage(user)
|
|
|
|
currentUserVM.editLangue(10) // a mettre a la place : currentUserState.id
|
|
|
|
currentLangage.value = user.langage
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = colorButton),
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = colorButton),
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text("${text} (${currentLangage.value})", fontSize = size.sp, color = MaterialTheme.colorScheme.primary)
|
|
|
|
Text("${text} (${currentUserState.langue})", fontSize = size.sp, color = MaterialTheme.colorScheme.primary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ButtonProfil(textResId : Int, size :Int, colorTexte : Color, colorButton : Color,navController: () -> Unit){
|
|
|
|
fun ButtonProfile(textResId : Int, size :Int, colorButton : Color,navController: () -> Unit){
|
|
|
|
val text = stringResource(id = textResId)
|
|
|
|
val text = stringResource(id = textResId)
|
|
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
Button(
|
|
|
@ -489,6 +496,6 @@ fun ButtonProfil(textResId : Int, size :Int, colorTexte : Color, colorButton : C
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = colorButton),
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = colorButton),
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text(text, fontSize = size.sp, color = colorTexte)
|
|
|
|
Text(text, fontSize = size.sp, color = MaterialTheme.colorScheme.primary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|