|
|
@ -1,6 +1,9 @@
|
|
|
|
package com.example.what_the_fantasy.ui.screens
|
|
|
|
package com.example.what_the_fantasy.ui.screens
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
|
|
|
|
import android.util.Patterns
|
|
|
|
|
|
|
|
import android.widget.ImageView
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
import androidx.activity.enableEdgeToEdge
|
|
|
|
import androidx.activity.enableEdgeToEdge
|
|
|
@ -54,16 +57,24 @@ import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
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.navigation.NavController
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
|
|
|
|
import coil.compose.AsyncImage
|
|
|
|
import com.example.what_the_fantasy.R
|
|
|
|
import com.example.what_the_fantasy.R
|
|
|
|
|
|
|
|
import com.example.what_the_fantasy.data.local.QuestionStub
|
|
|
|
|
|
|
|
import com.example.what_the_fantasy.data.local.UserStub
|
|
|
|
|
|
|
|
import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent
|
|
|
|
|
|
|
|
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.theme.What_The_FantasyTheme
|
|
|
|
import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ProfilPage() {
|
|
|
|
fun ProfilPage(navController: NavController) {
|
|
|
|
val gradient = Brush.linearGradient(
|
|
|
|
val gradient = Brush.linearGradient(
|
|
|
|
colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé
|
|
|
|
colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé
|
|
|
|
start = Offset(0f, 1000f), // Départ en bas à gauche
|
|
|
|
start = Offset(0f, 1000f), // Départ en bas à gauche
|
|
|
|
end = Offset(1000f, 0f) // Fin en haut à droite
|
|
|
|
end = Offset(1000f, 0f) // Fin en haut à droite
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
val user = UserStub.allUsers
|
|
|
|
|
|
|
|
val index = 2 // Pour changer l'utilisateur pour le moment
|
|
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
@ -82,30 +93,27 @@ fun ProfilPage() {
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
// Titre
|
|
|
|
// Titre
|
|
|
|
TitleProfil(R.string.titleProfile, 20, Color.White)
|
|
|
|
TitlePageComponent(R.string.titleProfile, 20, Color.White)
|
|
|
|
SpaceProfil(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
|
|
|
|
// Image de profil
|
|
|
|
// Image de profil
|
|
|
|
val id = R.drawable.ic_launcher_foreground
|
|
|
|
ImageProfil(user[index].imgUrl, 120, 2, Color.White)
|
|
|
|
ImageProfil(id, 120, 2, Color.White)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditUsername(user[index].username)// Édition du Username
|
|
|
|
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
|
|
|
|
SpaceProfil(16)
|
|
|
|
EditEmail(user[index].email)// Édition du Email
|
|
|
|
|
|
|
|
|
|
|
|
EditUsername()// Édition du Username
|
|
|
|
|
|
|
|
SpaceProfil(16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditEmail()// Édition du Email
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
|
|
|
|
|
|
|
|
EditPasswd()
|
|
|
|
EditPasswd()
|
|
|
|
SpaceProfil(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
|
|
|
|
// Bouton
|
|
|
|
// Bouton
|
|
|
|
ButtonProfile(R.string.ButtonAddQuoteprofile,18, Color.Black, Color.White)
|
|
|
|
ButtonProfile(R.string.ButtonAddQuoteprofile,18, Color.Black, Color.White)
|
|
|
|
SpaceProfil(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
ButtonProfile(R.string.ButtonLanguageprofile,18, Color.Black, Color.White)
|
|
|
|
ButtonProfile(R.string.ButtonLanguageprofile,18, Color.Black, Color.White)
|
|
|
|
SpaceProfil(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
ButtonProfile(R.string.ButtonUnlogprofile, 18, Color.Black, Color.White)
|
|
|
|
ButtonProfile(R.string.ButtonUnlogprofile, 18, Color.Black, Color.White)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -113,254 +121,322 @@ fun ProfilPage() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun SpaceProfil(height : Int){
|
|
|
|
|
|
|
|
Spacer(
|
|
|
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
|
|
|
.height(height.dp)) // Ajoute un espacement
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun TitleProfil(titleResId : Int, size : Int, color : Color){
|
|
|
|
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = title,
|
|
|
|
|
|
|
|
fontSize = size.sp,
|
|
|
|
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
|
|
|
|
color = color
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ImageProfil(imgProfil : Int, size :Int, sizeBorber : Int, colorBorder : Color){
|
|
|
|
fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : Color){
|
|
|
|
Image(
|
|
|
|
|
|
|
|
painter = painterResource(imgProfil),
|
|
|
|
AsyncImage(
|
|
|
|
|
|
|
|
model = imgProfil,
|
|
|
|
contentDescription = "Photo de profil",
|
|
|
|
contentDescription = "Photo de profil",
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.size(size.dp)
|
|
|
|
.size(size.dp)
|
|
|
|
.clip(CircleShape)
|
|
|
|
.clip(CircleShape)
|
|
|
|
.border(sizeBorber.dp, colorBorder, CircleShape)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun EditEmail(){
|
|
|
|
fun EditEmail(userEmail: String) {
|
|
|
|
var email by remember { mutableStateOf("user@example.com") }
|
|
|
|
var email by remember { mutableStateOf(userEmail) }
|
|
|
|
var isEditingEmail by remember { mutableStateOf(false) } // État d'édition
|
|
|
|
var isEditingEmail by remember { mutableStateOf(false) }
|
|
|
|
var emailError by remember { mutableStateOf(false) }
|
|
|
|
var emailError by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
|
|
if (isEditingEmail) {
|
|
|
|
if (isEditingEmail) {
|
|
|
|
OutlinedTextField(
|
|
|
|
EmailEditingField(
|
|
|
|
value = email,
|
|
|
|
email = email,
|
|
|
|
onValueChange = {
|
|
|
|
onEmailChange = { newEmail ->
|
|
|
|
email = it
|
|
|
|
email = newEmail
|
|
|
|
emailError = !android.util.Patterns.EMAIL_ADDRESS.matcher(it).matches()
|
|
|
|
emailError = !Patterns.EMAIL_ADDRESS.matcher(newEmail).matches()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
onDone = {
|
|
|
|
textStyle = TextStyle(color = Color.White, fontSize = 18.sp),
|
|
|
|
if (!emailError) isEditingEmail = false
|
|
|
|
singleLine = true,
|
|
|
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
|
|
|
keyboardType = KeyboardType.Email, // ✅ Clavier spécialisé pour email
|
|
|
|
|
|
|
|
imeAction = ImeAction.Done
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
keyboardActions = KeyboardActions(
|
|
|
|
|
|
|
|
onDone = { if (!emailError) isEditingEmail = false } // ✅ Fermer si l'email est valide
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
|
|
|
IconButton(onClick = { if (!emailError) isEditingEmail = false }) {
|
|
|
|
|
|
|
|
Icon(imageVector = Icons.Default.Check, contentDescription = "Valider")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
isError = emailError // ✅ Afficher l'erreur si l'email est invalide
|
|
|
|
emailError = emailError
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if (emailError) {
|
|
|
|
|
|
|
|
val text = stringResource(id = R.string.ErrorEmailprofile)
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = text,
|
|
|
|
|
|
|
|
color = Color.Red,
|
|
|
|
|
|
|
|
fontSize = 12.sp,
|
|
|
|
|
|
|
|
modifier = Modifier.padding(top = 4.dp)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Row(
|
|
|
|
DisplayEmail(email = email, onEdit = { isEditingEmail = true })
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
}
|
|
|
|
modifier = Modifier.clickable { isEditingEmail = true }
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(
|
|
|
|
@Composable
|
|
|
|
text = email,
|
|
|
|
fun EmailEditingField(
|
|
|
|
fontSize = 18.sp,
|
|
|
|
email: String,
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
onEmailChange: (String) -> Unit,
|
|
|
|
color = Color.White
|
|
|
|
onDone: () -> Unit,
|
|
|
|
)
|
|
|
|
emailError: Boolean
|
|
|
|
Icon(
|
|
|
|
) {
|
|
|
|
imageVector = Icons.Default.Edit,
|
|
|
|
OutlinedTextField(
|
|
|
|
contentDescription = "Modifier",
|
|
|
|
value = email,
|
|
|
|
tint = Color.White,
|
|
|
|
onValueChange = onEmailChange,
|
|
|
|
modifier = Modifier.size(16.dp).padding(start = 8.dp)
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
)
|
|
|
|
textStyle = TextStyle(color = Color.White, fontSize = 18.sp),
|
|
|
|
}
|
|
|
|
singleLine = true,
|
|
|
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
|
|
|
keyboardType = KeyboardType.Email,
|
|
|
|
|
|
|
|
imeAction = ImeAction.Done
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
keyboardActions = KeyboardActions(
|
|
|
|
|
|
|
|
onDone = { onDone() }
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
|
|
|
IconButton(onClick = { if (!emailError) onDone() }) {
|
|
|
|
|
|
|
|
Icon(imageVector = Icons.Default.Check, contentDescription = "Valider")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isError = emailError
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (emailError) {
|
|
|
|
|
|
|
|
ErrorMessageProfileComponent(R.string.ErrorEmailprofile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun EditUsername(){
|
|
|
|
fun DisplayEmail(email: String, onEdit: () -> Unit) {
|
|
|
|
var username by remember { mutableStateOf("Username") }
|
|
|
|
Row(
|
|
|
|
var isEditingUsername by remember { mutableStateOf(false) } // État d'édition
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
|
|
|
|
modifier = Modifier.clickable { onEdit() }
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = email,
|
|
|
|
|
|
|
|
fontSize = 18.sp,
|
|
|
|
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
|
|
|
|
color = Color.White
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Icon(
|
|
|
|
|
|
|
|
imageVector = Icons.Default.Edit,
|
|
|
|
|
|
|
|
contentDescription = "Modifier",
|
|
|
|
|
|
|
|
tint = Color.White,
|
|
|
|
|
|
|
|
modifier = Modifier.size(16.dp).padding(start = 8.dp)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun EditUsername(userName: String) {
|
|
|
|
|
|
|
|
var username by remember { mutableStateOf(userName) }
|
|
|
|
|
|
|
|
var isEditingUsername by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
|
|
if (isEditingUsername) {
|
|
|
|
if (isEditingUsername) {
|
|
|
|
OutlinedTextField(
|
|
|
|
UsernameEditingField(
|
|
|
|
value = username,
|
|
|
|
username = username,
|
|
|
|
onValueChange = { username = it },
|
|
|
|
onUsernameChange = { username = it },
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
onDone = { isEditingUsername = false }
|
|
|
|
textStyle = TextStyle(color = Color.White, fontSize = 18.sp),
|
|
|
|
|
|
|
|
singleLine = true,
|
|
|
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
|
|
|
imeAction = ImeAction.Done
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
keyboardActions = KeyboardActions(
|
|
|
|
|
|
|
|
onDone = { isEditingUsername = false } // Quand on appuie sur "Done"
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
|
|
|
IconButton(onClick = { isEditingUsername = false }) {
|
|
|
|
|
|
|
|
Icon(imageVector = Icons.Default.Check, contentDescription = "Valider")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Row(
|
|
|
|
DisplayUsername(username = username, onEdit = { isEditingUsername = true })
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
}
|
|
|
|
modifier = Modifier.clickable { isEditingUsername = true }
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(
|
|
|
|
@Composable
|
|
|
|
text = username,
|
|
|
|
fun UsernameEditingField(
|
|
|
|
fontSize = 18.sp,
|
|
|
|
username: String,
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
onUsernameChange: (String) -> Unit,
|
|
|
|
color = Color.White
|
|
|
|
onDone: () -> Unit
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
Icon(
|
|
|
|
OutlinedTextField(
|
|
|
|
imageVector = Icons.Default.Edit,
|
|
|
|
value = username,
|
|
|
|
contentDescription = "Modifier",
|
|
|
|
onValueChange = onUsernameChange,
|
|
|
|
tint = Color.White,
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
modifier = Modifier.size(16.dp).padding(start = 8.dp)
|
|
|
|
textStyle = TextStyle(color = Color.White, fontSize = 18.sp),
|
|
|
|
)
|
|
|
|
singleLine = true,
|
|
|
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
|
|
|
imeAction = ImeAction.Done
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
keyboardActions = KeyboardActions(
|
|
|
|
|
|
|
|
onDone = { onDone() } // Quand on appuie sur "Done", on met fin à l'édition
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
|
|
|
IconButton(onClick = { onDone() }) {
|
|
|
|
|
|
|
|
Icon(imageVector = Icons.Default.Check, contentDescription = "Valider")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun DisplayUsername(username: String, onEdit: () -> Unit) {
|
|
|
|
|
|
|
|
Row(
|
|
|
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
|
|
|
|
modifier = Modifier.clickable { onEdit() }
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = username,
|
|
|
|
|
|
|
|
fontSize = 18.sp,
|
|
|
|
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
|
|
|
|
color = Color.White
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Icon(
|
|
|
|
|
|
|
|
imageVector = Icons.Default.Edit,
|
|
|
|
|
|
|
|
contentDescription = "Modifier",
|
|
|
|
|
|
|
|
tint = Color.White,
|
|
|
|
|
|
|
|
modifier = Modifier.size(16.dp).padding(start = 8.dp)
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun EditPasswd(){
|
|
|
|
fun EditPasswd() {
|
|
|
|
var password by remember { mutableStateOf("*******") }
|
|
|
|
var password by remember { mutableStateOf("*******") }
|
|
|
|
var isEditingPassword by remember { mutableStateOf(false) }
|
|
|
|
var isEditingPassword by remember { mutableStateOf(false) }
|
|
|
|
var newPassword by remember { mutableStateOf("") }
|
|
|
|
var newPassword by remember { mutableStateOf("") }
|
|
|
|
var confirmPassword by remember { mutableStateOf("") }
|
|
|
|
var confirmPassword by remember { mutableStateOf("") }
|
|
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
|
|
var passwordError by remember { mutableStateOf(false) }
|
|
|
|
var passwordError by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
|
|
if (isEditingPassword) {
|
|
|
|
if (isEditingPassword) {
|
|
|
|
Column {
|
|
|
|
PasswordEditingFields(
|
|
|
|
val text = stringResource(id = R.string.NewPasswdprofile)
|
|
|
|
newPassword = newPassword,
|
|
|
|
OutlinedTextField(
|
|
|
|
confirmPassword = confirmPassword,
|
|
|
|
value = newPassword,
|
|
|
|
onNewPasswordChange = { newPassword = it },
|
|
|
|
onValueChange = { newPassword = it },
|
|
|
|
onConfirmPasswordChange = {
|
|
|
|
label = { Text(text) },
|
|
|
|
confirmPassword = it
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
passwordError = newPassword != it
|
|
|
|
textStyle = TextStyle(color = Color.White, fontSize = 18.sp),
|
|
|
|
},
|
|
|
|
singleLine = true,
|
|
|
|
passwordVisible = passwordVisible,
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
onPasswordVisibilityChange = { passwordVisible = it },
|
|
|
|
keyboardType = KeyboardType.Password,
|
|
|
|
passwordError = passwordError,
|
|
|
|
imeAction = ImeAction.Next
|
|
|
|
onDone = {
|
|
|
|
),
|
|
|
|
if (!passwordError && newPassword.isNotEmpty()) {
|
|
|
|
visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(),
|
|
|
|
password = newPassword
|
|
|
|
trailingIcon = {
|
|
|
|
isEditingPassword = false
|
|
|
|
IconButton(onClick = { passwordVisible = !passwordVisible }) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
|
|
|
|
val textConfirm = stringResource(id = R.string.ConfirmNewPasswdprofile)
|
|
|
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
|
|
|
value = confirmPassword,
|
|
|
|
|
|
|
|
onValueChange = {
|
|
|
|
|
|
|
|
confirmPassword = it
|
|
|
|
|
|
|
|
passwordError = newPassword != it
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
label = { Text(textConfirm) },
|
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
|
|
|
textStyle = TextStyle(color = Color.White, fontSize = 18.sp),
|
|
|
|
|
|
|
|
singleLine = true,
|
|
|
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
|
|
|
keyboardType = KeyboardType.Password,
|
|
|
|
|
|
|
|
imeAction = ImeAction.Done
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
keyboardActions = KeyboardActions(
|
|
|
|
|
|
|
|
onDone = { if (!passwordError && newPassword.isNotEmpty()) {
|
|
|
|
|
|
|
|
password = newPassword
|
|
|
|
|
|
|
|
isEditingPassword = false
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(),
|
|
|
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
|
|
|
IconButton(onClick = { passwordVisible = !passwordVisible }) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isError = passwordError
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (passwordError) {
|
|
|
|
|
|
|
|
val text = stringResource(id = R.string.Errorpasswdprofile)
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = text,
|
|
|
|
|
|
|
|
color = Color.Red,
|
|
|
|
|
|
|
|
fontSize = 12.sp,
|
|
|
|
|
|
|
|
modifier = Modifier.padding(top = 4.dp)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
DisplayPassword(onEdit = { isEditingPassword = true })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun PasswordEditingFields(
|
|
|
|
|
|
|
|
newPassword: String,
|
|
|
|
|
|
|
|
confirmPassword: String,
|
|
|
|
|
|
|
|
onNewPasswordChange: (String) -> Unit,
|
|
|
|
|
|
|
|
onConfirmPasswordChange: (String) -> Unit,
|
|
|
|
|
|
|
|
passwordVisible: Boolean,
|
|
|
|
|
|
|
|
onPasswordVisibilityChange: (Boolean) -> Unit,
|
|
|
|
|
|
|
|
passwordError: Boolean,
|
|
|
|
|
|
|
|
onDone: () -> Unit
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
|
|
|
val text = stringResource(id = R.string.NewPasswdprofile)
|
|
|
|
|
|
|
|
PasswordTextField(
|
|
|
|
|
|
|
|
value = newPassword,
|
|
|
|
|
|
|
|
onValueChange = onNewPasswordChange,
|
|
|
|
|
|
|
|
label = text,
|
|
|
|
|
|
|
|
passwordVisible = passwordVisible,
|
|
|
|
|
|
|
|
onPasswordVisibilityChange = onPasswordVisibilityChange
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
onClick = {
|
|
|
|
|
|
|
|
if (!passwordError && newPassword.isNotEmpty()) {
|
|
|
|
val textConfirm = stringResource(id = R.string.ConfirmNewPasswdprofile)
|
|
|
|
password = newPassword
|
|
|
|
PasswordTextField(
|
|
|
|
isEditingPassword = false
|
|
|
|
value = confirmPassword,
|
|
|
|
}
|
|
|
|
onValueChange = onConfirmPasswordChange,
|
|
|
|
},
|
|
|
|
label = textConfirm,
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = Color.White),
|
|
|
|
passwordVisible = passwordVisible,
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
|
onPasswordVisibilityChange = onPasswordVisibilityChange,
|
|
|
|
) {
|
|
|
|
isError = passwordError,
|
|
|
|
val text = stringResource(id = R.string.ButtonSaveprofile)
|
|
|
|
onDone = onDone
|
|
|
|
Text(text, fontSize = 18.sp, color = Color.Black)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (passwordError) {
|
|
|
|
} else {
|
|
|
|
ErrorMessageProfileComponent(R.string.Errorpasswdprofile)
|
|
|
|
Row(
|
|
|
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
|
|
|
|
modifier = Modifier.clickable { isEditingPassword = true }
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = password,
|
|
|
|
|
|
|
|
fontSize = 18.sp,
|
|
|
|
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
|
|
|
|
color = Color.White
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Icon(
|
|
|
|
|
|
|
|
imageVector = Icons.Default.Edit,
|
|
|
|
|
|
|
|
contentDescription = "Modifier",
|
|
|
|
|
|
|
|
tint = Color.White,
|
|
|
|
|
|
|
|
modifier = Modifier.size(16.dp).padding(start = 8.dp)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SaveButton(onClick = onDone)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun PasswordTextField(
|
|
|
|
|
|
|
|
value: String,
|
|
|
|
|
|
|
|
onValueChange: (String) -> Unit,
|
|
|
|
|
|
|
|
label: String,
|
|
|
|
|
|
|
|
passwordVisible: Boolean,
|
|
|
|
|
|
|
|
onPasswordVisibilityChange: (Boolean) -> Unit,
|
|
|
|
|
|
|
|
isError: Boolean = false,
|
|
|
|
|
|
|
|
onDone: (() -> Unit)? = null
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
|
|
|
value = value,
|
|
|
|
|
|
|
|
onValueChange = onValueChange,
|
|
|
|
|
|
|
|
label = { Text(label) },
|
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
|
|
|
textStyle = TextStyle(color = Color.White, fontSize = 18.sp),
|
|
|
|
|
|
|
|
singleLine = true,
|
|
|
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
|
|
|
keyboardType = KeyboardType.Password,
|
|
|
|
|
|
|
|
imeAction = if (onDone != null) ImeAction.Done else ImeAction.Next
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
keyboardActions = onDone?.let {
|
|
|
|
|
|
|
|
KeyboardActions(onDone = { it() })
|
|
|
|
|
|
|
|
} ?: KeyboardActions.Default,
|
|
|
|
|
|
|
|
visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(),
|
|
|
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
|
|
|
IconButton(onClick = { onPasswordVisibilityChange(!passwordVisible) }) {
|
|
|
|
|
|
|
|
// Ajout d'une icône pour montrer/masquer le mot de passe
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isError = isError
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun SaveButton(onClick: () -> Unit) {
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
|
|
|
onClick = onClick,
|
|
|
|
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = Color.White),
|
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
val text = stringResource(id = R.string.ButtonSaveprofile)
|
|
|
|
|
|
|
|
Text(text,
|
|
|
|
|
|
|
|
fontSize = 18.sp,
|
|
|
|
|
|
|
|
color = Color.Black)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun DisplayPassword(onEdit: () -> Unit) {
|
|
|
|
|
|
|
|
Row(
|
|
|
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
|
|
|
|
modifier = Modifier.clickable { onEdit() }
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "*****",
|
|
|
|
|
|
|
|
fontSize = 18.sp,
|
|
|
|
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
|
|
|
|
color = Color.White
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Icon(
|
|
|
|
|
|
|
|
imageVector = Icons.Default.Edit,
|
|
|
|
|
|
|
|
contentDescription = "Modifier",
|
|
|
|
|
|
|
|
tint = Color.White,
|
|
|
|
|
|
|
|
modifier = Modifier.size(16.dp).padding(start = 8.dp)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ButtonProfile(textResId : Int, size :Int, colorTexte : Color, colorButton : Color){
|
|
|
|
fun ButtonProfile(textResId : Int, size :Int, colorTexte : Color, colorButton : Color){
|
|
|
|