From 6ae5a08fc1293389a9db539150f9f4f18460323b Mon Sep 17 00:00:00 2001 From: beaulaton Date: Wed, 12 Mar 2025 14:19:30 +0100 Subject: [PATCH] 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