diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/Logs/LogsUsers.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/Logs/LogsUsers.kt index 1ae774c..67a12c3 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/Logs/LogsUsers.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/Logs/LogsUsers.kt @@ -10,7 +10,7 @@ class LogsUsers{ } } - fun logDebugDisplayUser(user : User, titleLog : String){ - Log.e(titleLog, "User created: ${user.username} => ${user.email}") + fun logDebugDisplayUser(user : User?, titleLog : String){ + Log.e(titleLog, "User created: ${user?.username} => ${user?.email}") } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt index 620ba60..047d633 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt @@ -4,8 +4,8 @@ import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.User interface IServices { - fun EditUsername(username : String, index : Int) - fun EditEmail(email : String, index : Int) + fun EditUsername(username : String, index : Int) : Boolean + fun EditEmail(email : String, index : Int) : Boolean fun EditPasswd(passwd : String, index : Int) fun EditImage(imageURL : String, index : Int) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt index a04178b..4b126fd 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt @@ -4,11 +4,11 @@ import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.User class ServicesAPI : IServices { - override fun EditUsername(username: String, index : Int) { + override fun EditUsername(username: String, index : Int) : Boolean { TODO("Not yet implemented") } - override fun EditEmail(email: String, index : Int) { + override fun EditEmail(email: String, index : Int) : Boolean { TODO("Not yet implemented") } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt index 14ca39d..93b74fb 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt @@ -14,20 +14,29 @@ import java.time.LocalDate class ServicesStub : IServices { val logsUser = LogsUsers() //gestion des logs pour les utilisateurs - override fun EditUsername(username: String, index : Int) { + override fun EditUsername(username: String, index : Int) : Boolean{ val user = getUserById(index) - user?.username = username + + if(!isUsernameExist(username)){ + user?.username = username + return true + } //Afficher tous les users - logsUser.logDebugDisplayUsers(getAllUsers(), "UsernameUpdate") + logsUser.logDebugDisplayUser(user, "UsernameUpdate") + return false } - override fun EditEmail(email: String,index : Int) { + override fun EditEmail(email: String,index : Int) : Boolean { val user = getUserById(index) - user?.email = email + if(!isEmailExist(email)){ + user?.email = email + return true + } //Afficher tous les users logsUser.logDebugDisplayUsers(getAllUsers(), "EmailUpdate") + return false } override fun EditPasswd(passwd: String,index : Int) { @@ -50,7 +59,7 @@ class ServicesStub : IServices { val userStub = services.getAllUsers() val nbUser = userStub.size - if(isUsernameExist(username) && isEmailExist(email)){ + if(!isUsernameExist(username) && !isEmailExist(email)){ val user = User(nbUser+1,username, email, date,randomImage(userStub), passwordhash, SrcLanguage.vo) users.add(user)//ajout au stub @@ -99,19 +108,19 @@ class ServicesStub : IServices { val userStub = getAllUsers() for (user in userStub) { if (user.username == username) { - return false + return true } } - return true + return false } fun isEmailExist(email : String) : Boolean{ val userStub = getAllUsers() for (user in userStub) { if (user.email == email) { - return false + return true } } - return true + return false } } \ No newline at end of file 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 b122258..c1eea04 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 @@ -156,8 +156,8 @@ fun EditEmail(userEmail: String, index: Int, service: IServices) { var emailError by remember { mutableStateOf(false) } fun onDoneEditing() { - service.EditEmail(email, index) - isEditingEmail = false + isEditingEmail =!service.EditEmail(email, index) + } if (isEditingEmail) { @@ -242,8 +242,7 @@ fun EditUsername(userName: String, index: Int, service : IServices) { var isEditingUsername by remember { mutableStateOf(false) } fun onDoneEditing() { - service.EditUsername(username, index) - isEditingUsername = false + isEditingUsername= !service.EditUsername(username, index) } if (isEditingUsername) {