From 6ae5a08fc1293389a9db539150f9f4f18460323b Mon Sep 17 00:00:00 2001 From: beaulaton Date: Wed, 12 Mar 2025 14:19:30 +0100 Subject: [PATCH 1/3] Traduction page favori/Accueil + langue user pour la suggestion des citations dans l'accueil (vo-fr) --- .../what_the_fantasy/data/local/QuoteStub.kt | 2 +- .../what_the_fantasy/data/local/UserStub.kt | 4 +- .../data/services/ServicesStub.kt | 39 ++++++++++++++----- .../ui/components/QuoteLittle.kt | 9 +++-- .../ui/navigations/AppNavigator.kt | 3 +- .../ui/screens/AccueilPage.kt | 17 ++++++-- .../ui/screens/FavoritePage.kt | 6 ++- .../app/src/main/res/values-fr/strings.xml | 8 +++- .../app/src/main/res/values/strings.xml | 8 +++- 9 files changed, 68 insertions(+), 28 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt index 2922816..bb29474 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt @@ -125,7 +125,7 @@ object QuoteStub { source = "Spider-Man", imgUrl = CharacterStub.aragorn.imgUrl, date = 2000, - type = SrcType.Movie, + type = SrcType.Series, ) val quote12 = Quote( id = 12, diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt index da7fe1c..cbfe386 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt @@ -16,8 +16,6 @@ object UserStub { User(8, "Eowyn777", "eowyn@example.com", "2022-04-11", "https://img.freepik.com/vecteurs-libre/personnage-guerriere-femme-fantaisie_1045-192.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4", SrcLanguage.vo),//1234 User(9, "Saruman888", "saruman@example.com", "2021-08-15", "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4", SrcLanguage.vo),//1234 User(10, "Faramir222", "faramir@example.com", "2023-02-08", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4", SrcLanguage.vo),//1234 - User(11, "dev", "testeur@example.com", "2023-02-08", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4", SrcLanguage.fr)//1234 + User(11, "dev", "testeur@example.com", "2023-02-08", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4", SrcLanguage.vo)//1234 ) - - } \ No newline at end of file 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 995918e..14ca39d 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 @@ -49,17 +49,16 @@ class ServicesStub : IServices { val userStub = services.getAllUsers() val nbUser = userStub.size - for (user in userStub) { - if (user.username == username) { - return false - } - } - val user = User(nbUser+1,username, email, date,randomImage(userStub), passwordhash, SrcLanguage.vo) - users.add(user)//ajout au stub - //Afficher tous les users - logsUser.logDebugDisplayUsers(users, "CreateUser") - return true + if(isUsernameExist(username) && isEmailExist(email)){ + val user = User(nbUser+1,username, email, date,randomImage(userStub), passwordhash, SrcLanguage.vo) + users.add(user)//ajout au stub + + //Afficher tous les users + logsUser.logDebugDisplayUsers(users, "CreateUser") + return true + } + return false } override fun getAllUsers(): List = users @@ -95,4 +94,24 @@ class ServicesStub : IServices { fun randomImage(usersImage : List) : String{ return "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg" } + + fun isUsernameExist(username : String) : Boolean{ + val userStub = getAllUsers() + for (user in userStub) { + if (user.username == username) { + return false + } + } + return true + } + + fun isEmailExist(email : String) : Boolean{ + val userStub = getAllUsers() + for (user in userStub) { + if (user.email == email) { + return false + } + } + return true + } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/QuoteLittle.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/QuoteLittle.kt index 2c7324a..aca0e44 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/QuoteLittle.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/QuoteLittle.kt @@ -16,17 +16,20 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import coil.compose.rememberAsyncImagePainter -import coil.compose.rememberImagePainter +import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.ui.theme.colorBackground import com.example.what_the_fantasy.ui.theme.gradienBox @Composable fun QuoteLittle(quote: Quote, modifier: Modifier = Modifier) { + val Character = stringResource(R.string.CharacterQuote) + Row( modifier = modifier .fillMaxWidth() @@ -73,14 +76,14 @@ fun QuoteLittle(quote: Quote, modifier: Modifier = Modifier) { Spacer(modifier = Modifier.height(8.dp)) Text( - text = "Film : ${quote.source}", + text = "${quote.type} : ${quote.source}", color = Color.White, fontSize = 12.sp, maxLines = 1, overflow = TextOverflow.Ellipsis ) Text( - text = "Personnage : ${quote.character}", + text = "${Character}: ${quote.character}", color = Color.White, fontSize = 12.sp, maxLines = 1, diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt index d4c6fb4..a2161e9 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt @@ -76,7 +76,8 @@ fun AppNavigator() { index = accueil.userIndex, navFavorite = { navController.navigate(Favorite(accueil.userIndex)) }, navQuiz = { navController.navigate(QuizMenu(accueil.userIndex)) }, - navProfil = { navController.navigate(Profil(accueil.userIndex)) } + navProfil = { navController.navigate(Profil(accueil.userIndex)) }, + services = services ) } composable { diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt index 666e669..07a357b 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt @@ -11,11 +11,14 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.DailyQuoteStub import com.example.what_the_fantasy.data.local.QuoteStub +import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.QuoteLittle import com.example.what_the_fantasy.ui.theme.colorBackground @@ -25,12 +28,16 @@ fun AccueilPage( index: Int, navFavorite: (Int) -> Unit, navQuiz: (Int) -> Unit, - navProfil: (Int) -> Unit + navProfil: (Int) -> Unit, + services: IServices ) { var itemCount by remember { mutableStateOf(15) } val dailyQuote = DailyQuoteStub.dailyQuote val quotes = QuoteStub.allQuotes.take(itemCount) + val user = services.getUserById(index) ?: return + val titleDalyQuote = stringResource(R.string.TitleHomeDailyQuote) + val titleSuggestion = stringResource(R.string.TitleHomeSuggestion) NavBar( onAccueil = true, index = index, @@ -48,7 +55,7 @@ fun AccueilPage( item{ Column { Text( - text = "▶ Citation du jour ◀", + text = titleDalyQuote, color = Color.White, fontSize = 24.sp, modifier = Modifier @@ -60,7 +67,7 @@ fun AccueilPage( QuoteLittle(dailyQuote) } Text( - text = "▶ Suggestions ◀", + text = titleSuggestion, color = Color.White, fontSize = 24.sp, modifier = Modifier @@ -70,7 +77,9 @@ fun AccueilPage( ) } items(quotes) { quote -> - QuoteLittle(quote) + if(quote.language == user.language){ + QuoteLittle(quote) + } } if (itemCount < QuoteStub.allQuotes.size) { item { diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt index 3ba32aa..1a8cc79 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/FavoritePage.kt @@ -9,9 +9,11 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.FavoriteStub import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.NavBar @@ -28,7 +30,7 @@ fun FavoritePage( ) { val user = services.getUserById(index) ?: return val quotes = FavoriteStub.getFavoritesByUser(user.id) - + val TitlePage = stringResource(R.string.TitleFavorite) NavBar(onFavorite = true, index = index, navControllerFavorite = { }, @@ -45,7 +47,7 @@ fun FavoritePage( LazyColumn { item{ Text( - text = "▶ Favoris ◀", + text = TitlePage, color = Color.White, fontSize = 24.sp, modifier = Modifier diff --git a/What_The_Fantasy/app/src/main/res/values-fr/strings.xml b/What_The_Fantasy/app/src/main/res/values-fr/strings.xml index 47d0063..02b41a5 100644 --- a/What_The_Fantasy/app/src/main/res/values-fr/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values-fr/strings.xml @@ -30,7 +30,7 @@ Email invalide Les mots de passe ne correspondent pas Le nom d\'utilisateur ne peut pas être vide - Le nom d\'utilisateur n\'est pas disponible + Le nom d\'utilisateur ou l\'email ne sont pas disponibles Vous devez mettre un mot de passe //Page Profil @@ -51,5 +51,9 @@ //Page Favori - Favoris + ▶ Favoris ◀ + + //Page Accueil + ▶ Citation du jour ◀ + ▶ Suggestions ◀ \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/res/values/strings.xml b/What_The_Fantasy/app/src/main/res/values/strings.xml index 0771fb9..028b28a 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -29,7 +29,7 @@ Invalid email Passwords do not match Username cannot be empty - Username is not available + Username or email are not available You must put a password //Page Profil @@ -48,6 +48,10 @@ Character //Page Favori - Favorites + ▶ Favorites ◀ + + //Page Accueil + ▶ Quote of the day ◀ + ▶ Suggestions ◀ \ No newline at end of file -- 2.36.3 From 19544a67cc9dc800596e14d048e3362efe0239e6 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Wed, 12 Mar 2025 15:03:56 +0100 Subject: [PATCH 2/3] Gestion du changement de user/email => pas 2 fois les memes --- .../what_the_fantasy/Logs/LogsUsers.kt | 4 +-- .../data/services/IServices.kt | 4 +-- .../data/services/ServicesAPI.kt | 4 +-- .../data/services/ServicesStub.kt | 29 ++++++++++++------- .../what_the_fantasy/ui/screens/ProfilPage.kt | 7 ++--- 5 files changed, 28 insertions(+), 20 deletions(-) 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) { -- 2.36.3 From 313be9d17e64dacb5f4414bec41a82ac65d186a7 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Wed, 12 Mar 2025 15:12:42 +0100 Subject: [PATCH 3/3] Citation accueil lien --- .../example/what_the_fantasy/ui/navigations/AppNavigator.kt | 4 ++++ .../com/example/what_the_fantasy/ui/screens/AccueilPage.kt | 1 + 2 files changed, 5 insertions(+) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt index a2161e9..0f18cb6 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt @@ -36,6 +36,9 @@ data class Quiz(val userIndex: Int, val idQuiz: Int) @Serializable data class QuizEnd(val userIndex: Int, val idQuiz: Int, val pts: Int) +@Serializable +data class OneQuote(val quoteId: Int, val userIndex: Int) + @Serializable data class Quote(val quoteId: Int, val userIndex: Int) @@ -77,6 +80,7 @@ fun AppNavigator() { navFavorite = { navController.navigate(Favorite(accueil.userIndex)) }, navQuiz = { navController.navigate(QuizMenu(accueil.userIndex)) }, navProfil = { navController.navigate(Profil(accueil.userIndex)) }, + navQuote = { quoteId -> navController.navigate(OneQuote(quoteId,accueil.userIndex)) }, services = services ) } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt index 07a357b..58abed0 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/AccueilPage.kt @@ -29,6 +29,7 @@ fun AccueilPage( navFavorite: (Int) -> Unit, navQuiz: (Int) -> Unit, navProfil: (Int) -> Unit, + navQuote: (Int) -> Unit, services: IServices ) { var itemCount by remember { mutableStateOf(15) } -- 2.36.3