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/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/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 995918e..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) { @@ -49,17 +58,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 +103,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 true + } + } + return false + } + + fun isEmailExist(email : String) : Boolean{ + val userStub = getAllUsers() + for (user in userStub) { + if (user.email == email) { + 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/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 6f13ca9..57b8e47 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 @@ -39,6 +39,9 @@ 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) + @Serializable data object Search @@ -77,7 +80,8 @@ 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)) } + navQuote = { quoteId -> navController.navigate(OneQuote(quoteId,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 008a191..4286524 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 @@ -12,11 +12,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 @@ -27,12 +30,17 @@ fun AccueilPage( navFavorite: (Int) -> Unit, navQuiz: (Int) -> Unit, navProfil: (Int) -> Unit, - navQuote: (Int) -> Unit + navQuote: (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, @@ -50,7 +58,7 @@ fun AccueilPage( item{ Column { Text( - text = "▶ Citation du jour ◀", + text = titleDalyQuote, color = Color.White, fontSize = 24.sp, modifier = Modifier @@ -62,7 +70,7 @@ fun AccueilPage( QuoteLittle(dailyQuote) } Text( - text = "▶ Suggestions ◀", + text = titleSuggestion, color = Color.White, fontSize = 24.sp, modifier = Modifier @@ -72,10 +80,13 @@ fun AccueilPage( ) } items(quotes) { quote -> + Column(Modifier.clickable {navQuote(quote.id)} ) { - QuoteLittle(quote) - Spacer(modifier = Modifier.height(16.dp)) + if(quote.language == user.language){ + QuoteLittle(quote) + Spacer(modifier = Modifier.height(16.dp)) + } } } if (itemCount < QuoteStub.allQuotes.size) { 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 08ce333..467075d 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 @@ -10,9 +10,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 @@ -31,7 +33,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 = { }, @@ -48,7 +50,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/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) { 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