profilName #45

Merged
leni.beaulaton merged 4 commits from profilName into master 1 month ago

@ -10,7 +10,7 @@ class LogsUsers{
} }
} }
fun logDebugDisplayUser(user : User, titleLog : String){ fun logDebugDisplayUser(user : User?, titleLog : String){
Log.e(titleLog, "User created: ${user.username} => ${user.email}") Log.e(titleLog, "User created: ${user?.username} => ${user?.email}")
} }
} }

@ -125,7 +125,7 @@ object QuoteStub {
source = "Spider-Man", source = "Spider-Man",
imgUrl = CharacterStub.aragorn.imgUrl, imgUrl = CharacterStub.aragorn.imgUrl,
date = 2000, date = 2000,
type = SrcType.Movie, type = SrcType.Series,
) )
val quote12 = Quote( val quote12 = Quote(
id = 12, id = 12,

@ -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(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(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(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
) )
} }

@ -4,8 +4,8 @@ import com.example.what_the_fantasy.data.model.Quote
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
interface IServices { interface IServices {
fun EditUsername(username : String, index : Int) fun EditUsername(username : String, index : Int) : Boolean
fun EditEmail(email : String, index : Int) fun EditEmail(email : String, index : Int) : Boolean
fun EditPasswd(passwd : String, index : Int) fun EditPasswd(passwd : String, index : Int)
fun EditImage(imageURL : String, index : Int) fun EditImage(imageURL : String, index : Int)

@ -4,11 +4,11 @@ import com.example.what_the_fantasy.data.model.Quote
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
class ServicesAPI : IServices { class ServicesAPI : IServices {
override fun EditUsername(username: String, index : Int) { override fun EditUsername(username: String, index : Int) : Boolean {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
override fun EditEmail(email: String, index : Int) { override fun EditEmail(email: String, index : Int) : Boolean {
TODO("Not yet implemented") TODO("Not yet implemented")
} }

@ -14,20 +14,29 @@ import java.time.LocalDate
class ServicesStub : IServices { class ServicesStub : IServices {
val logsUser = LogsUsers() //gestion des logs pour les utilisateurs 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) val user = getUserById(index)
if(!isUsernameExist(username)){
user?.username = username user?.username = username
return true
}
//Afficher tous les users //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) val user = getUserById(index)
user?.email = email
if(!isEmailExist(email)){
user?.email = email
return true
}
//Afficher tous les users //Afficher tous les users
logsUser.logDebugDisplayUsers(getAllUsers(), "EmailUpdate") logsUser.logDebugDisplayUsers(getAllUsers(), "EmailUpdate")
return false
} }
override fun EditPasswd(passwd: String,index : Int) { override fun EditPasswd(passwd: String,index : Int) {
@ -49,11 +58,8 @@ class ServicesStub : IServices {
val userStub = services.getAllUsers() val userStub = services.getAllUsers()
val nbUser = userStub.size val nbUser = userStub.size
for (user in userStub) {
if (user.username == username) { if(!isUsernameExist(username) && !isEmailExist(email)){
return false
}
}
val user = User(nbUser+1,username, email, date,randomImage(userStub), passwordhash, SrcLanguage.vo) val user = User(nbUser+1,username, email, date,randomImage(userStub), passwordhash, SrcLanguage.vo)
users.add(user)//ajout au stub users.add(user)//ajout au stub
@ -61,6 +67,8 @@ class ServicesStub : IServices {
logsUser.logDebugDisplayUsers(users, "CreateUser") logsUser.logDebugDisplayUsers(users, "CreateUser")
return true return true
} }
return false
}
override fun getAllUsers(): List<User> = users override fun getAllUsers(): List<User> = users
@ -95,4 +103,24 @@ class ServicesStub : IServices {
fun randomImage(usersImage : List<User>) : String{ fun randomImage(usersImage : List<User>) : String{
return "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg" 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
}
} }

@ -16,17 +16,20 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
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 coil.compose.rememberAsyncImagePainter 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.data.model.Quote
import com.example.what_the_fantasy.ui.theme.colorBackground import com.example.what_the_fantasy.ui.theme.colorBackground
import com.example.what_the_fantasy.ui.theme.gradienBox import com.example.what_the_fantasy.ui.theme.gradienBox
@Composable @Composable
fun QuoteLittle(quote: Quote, modifier: Modifier = Modifier) { fun QuoteLittle(quote: Quote, modifier: Modifier = Modifier) {
val Character = stringResource(R.string.CharacterQuote)
Row( Row(
modifier = modifier modifier = modifier
.fillMaxWidth() .fillMaxWidth()
@ -73,14 +76,14 @@ fun QuoteLittle(quote: Quote, modifier: Modifier = Modifier) {
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
Text( Text(
text = "Film : ${quote.source}", text = "${quote.type} : ${quote.source}",
color = Color.White, color = Color.White,
fontSize = 12.sp, fontSize = 12.sp,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis overflow = TextOverflow.Ellipsis
) )
Text( Text(
text = "Personnage : ${quote.character}", text = "${Character}: ${quote.character}",
color = Color.White, color = Color.White,
fontSize = 12.sp, fontSize = 12.sp,
maxLines = 1, maxLines = 1,

@ -39,6 +39,9 @@ data class QuizEnd(val userIndex: Int, val idQuiz: Int, val pts: Int)
@Serializable @Serializable
data class OneQuote(val quoteId: Int, val userIndex: Int) data class OneQuote(val quoteId: Int, val userIndex: Int)
@Serializable
data class Quote(val quoteId: Int, val userIndex: Int)
@Serializable @Serializable
data object Search data object Search
@ -77,7 +80,8 @@ fun AppNavigator() {
navFavorite = { navController.navigate(Favorite(accueil.userIndex)) }, navFavorite = { navController.navigate(Favorite(accueil.userIndex)) },
navQuiz = { navController.navigate(QuizMenu(accueil.userIndex)) }, navQuiz = { navController.navigate(QuizMenu(accueil.userIndex)) },
navProfil = { navController.navigate(Profil(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<Favorite> { composable<Favorite> {

@ -12,11 +12,14 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
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 com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.local.DailyQuoteStub 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.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.NavBar
import com.example.what_the_fantasy.ui.components.QuoteLittle import com.example.what_the_fantasy.ui.components.QuoteLittle
import com.example.what_the_fantasy.ui.theme.colorBackground import com.example.what_the_fantasy.ui.theme.colorBackground
@ -27,12 +30,17 @@ fun AccueilPage(
navFavorite: (Int) -> Unit, navFavorite: (Int) -> Unit,
navQuiz: (Int) -> Unit, navQuiz: (Int) -> Unit,
navProfil: (Int) -> Unit, navProfil: (Int) -> Unit,
navQuote: (Int) -> Unit navQuote: (Int) -> Unit,
services: IServices
) { ) {
var itemCount by remember { mutableStateOf(15) } var itemCount by remember { mutableStateOf(15) }
val dailyQuote = DailyQuoteStub.dailyQuote val dailyQuote = DailyQuoteStub.dailyQuote
val quotes = QuoteStub.allQuotes.take(itemCount) 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( NavBar(
onAccueil = true, onAccueil = true,
index = index, index = index,
@ -50,7 +58,7 @@ fun AccueilPage(
item{ item{
Column { Column {
Text( Text(
text = "▶ Citation du jour ◀", text = titleDalyQuote,
color = Color.White, color = Color.White,
fontSize = 24.sp, fontSize = 24.sp,
modifier = Modifier modifier = Modifier
@ -62,7 +70,7 @@ fun AccueilPage(
QuoteLittle(dailyQuote) QuoteLittle(dailyQuote)
} }
Text( Text(
text = "▶ Suggestions ◀", text = titleSuggestion,
color = Color.White, color = Color.White,
fontSize = 24.sp, fontSize = 24.sp,
modifier = Modifier modifier = Modifier
@ -72,12 +80,15 @@ fun AccueilPage(
) )
} }
items(quotes) { quote -> items(quotes) { quote ->
Column(Modifier.clickable {navQuote(quote.id)} Column(Modifier.clickable {navQuote(quote.id)}
) { ) {
if(quote.language == user.language){
QuoteLittle(quote) QuoteLittle(quote)
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
} }
} }
}
if (itemCount < QuoteStub.allQuotes.size) { if (itemCount < QuoteStub.allQuotes.size) {
item { item {
LaunchedEffect(itemCount) { LaunchedEffect(itemCount) {

@ -10,9 +10,11 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
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 com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.local.FavoriteStub import com.example.what_the_fantasy.data.local.FavoriteStub
import com.example.what_the_fantasy.data.services.IServices 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.NavBar
@ -31,7 +33,7 @@ fun FavoritePage(
) { ) {
val user = services.getUserById(index) ?: return val user = services.getUserById(index) ?: return
val quotes = FavoriteStub.getFavoritesByUser(user.id) val quotes = FavoriteStub.getFavoritesByUser(user.id)
val TitlePage = stringResource(R.string.TitleFavorite)
NavBar(onFavorite = true, NavBar(onFavorite = true,
index = index, index = index,
navControllerFavorite = { }, navControllerFavorite = { },
@ -48,7 +50,7 @@ fun FavoritePage(
LazyColumn { LazyColumn {
item{ item{
Text( Text(
text = "▶ Favoris ◀", text = TitlePage,
color = Color.White, color = Color.White,
fontSize = 24.sp, fontSize = 24.sp,
modifier = Modifier modifier = Modifier

@ -156,8 +156,8 @@ fun EditEmail(userEmail: String, index: Int, service: IServices) {
var emailError by remember { mutableStateOf(false) } var emailError by remember { mutableStateOf(false) }
fun onDoneEditing() { fun onDoneEditing() {
service.EditEmail(email, index) isEditingEmail =!service.EditEmail(email, index)
isEditingEmail = false
} }
if (isEditingEmail) { if (isEditingEmail) {
@ -242,8 +242,7 @@ fun EditUsername(userName: String, index: Int, service : IServices) {
var isEditingUsername by remember { mutableStateOf(false) } var isEditingUsername by remember { mutableStateOf(false) }
fun onDoneEditing() { fun onDoneEditing() {
service.EditUsername(username, index) isEditingUsername= !service.EditUsername(username, index)
isEditingUsername = false
} }
if (isEditingUsername) { if (isEditingUsername) {

@ -30,7 +30,7 @@
<string name="ErrorEmailSignUp">Email invalide</string> <string name="ErrorEmailSignUp">Email invalide</string>
<string name="ErrorPasswordSignUp">Les mots de passe ne correspondent pas</string> <string name="ErrorPasswordSignUp">Les mots de passe ne correspondent pas</string>
<string name="ErrorUserEmptySignUp">Le nom d\'utilisateur ne peut pas être vide</string> <string name="ErrorUserEmptySignUp">Le nom d\'utilisateur ne peut pas être vide</string>
<string name="ErrorUserExistSignUp">Le nom d\'utilisateur n\'est pas disponible</string> <string name="ErrorUserExistSignUp">Le nom d\'utilisateur ou l\'email ne sont pas disponibles</string>
<string name="ErrorPasswordEmpty">Vous devez mettre un mot de passe</string> <string name="ErrorPasswordEmpty">Vous devez mettre un mot de passe</string>
//Page Profil //Page Profil
@ -51,5 +51,9 @@
//Page Favori //Page Favori
<string name="TitleFavorite">Favoris</string> <string name="TitleFavorite">▶ Favoris ◀</string>
//Page Accueil
<string name="TitleHomeDailyQuote">▶ Citation du jour ◀</string>
<string name="TitleHomeSuggestion">▶ Suggestions ◀</string>
</resources> </resources>

@ -29,7 +29,7 @@
<string name="ErrorEmailSignUp">Invalid email</string> <string name="ErrorEmailSignUp">Invalid email</string>
<string name="ErrorPasswordSignUp">Passwords do not match</string> <string name="ErrorPasswordSignUp">Passwords do not match</string>
<string name="ErrorUserEmptySignUp">Username cannot be empty</string> <string name="ErrorUserEmptySignUp">Username cannot be empty</string>
<string name="ErrorUserExistSignUp">Username is not available</string> <string name="ErrorUserExistSignUp">Username or email are not available</string>
<string name="ErrorPasswordEmpty">You must put a password</string> <string name="ErrorPasswordEmpty">You must put a password</string>
//Page Profil //Page Profil
@ -48,6 +48,10 @@
<string name="CharacterQuote">Character</string> <string name="CharacterQuote">Character</string>
//Page Favori //Page Favori
<string name="TitleFavorite">Favorites</string> <string name="TitleFavorite">▶ Favorites ◀</string>
//Page Accueil
<string name="TitleHomeDailyQuote">▶ Quote of the day ◀</string>
<string name="TitleHomeSuggestion">▶ Suggestions ◀</string>
</resources> </resources>
Loading…
Cancel
Save