From 2f57ac9d826d221058ac5ef2b54b1f5b7b678458 Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Fri, 7 Mar 2025 12:01:15 +0100 Subject: [PATCH 1/9] debut mvvm et commentaire --- .../data/mvvm/AppViewModel.kt | 9 +++++++ .../what_the_fantasy/ui/screens/QuotePage.kt | 27 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/mvvm/AppViewModel.kt diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/mvvm/AppViewModel.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/mvvm/AppViewModel.kt new file mode 100644 index 0000000..2a845ae --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/mvvm/AppViewModel.kt @@ -0,0 +1,9 @@ +package com.example.what_the_fantasy.data.mvvm + +import androidx.lifecycle.ViewModel +import com.example.what_the_fantasy.data.model.Quiz +import com.example.what_the_fantasy.data.model.Quote + +class AppViewModel: ViewModel() { + +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt index 16dcfac..2a6aa15 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt @@ -20,6 +20,10 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -41,6 +45,8 @@ import com.example.what_the_fantasy.ui.theme.iconText import com.example.what_the_fantasy.ui.theme.likeIcon import com.example.what_the_fantasy.ui.theme.whiteBackcgroundText +var isCommentVisible by mutableStateOf(false) + @Composable fun QuotePage( quoteId : Int, @@ -51,6 +57,7 @@ fun QuotePage( navQuiz: (Int) -> Unit, navProfil:(Int) -> Unit) { + // utiliser ViewModel var quote = service.getQuote(quoteId) ?: return val context = LocalContext.current NavBar(onProfile = true, @@ -118,6 +125,13 @@ fun QuotePage( } } } + if(isCommentVisible){ + Box(modifier = Modifier.fillMaxWidth().background(Color.White)){ + Column { + + } + } + } } } @@ -175,7 +189,14 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ ) } IconButton( - onClick = { }, //Go to comment + onClick = { + if(isCommentVisible){ + isCommentVisible = false + } + else{ + isCommentVisible = true + } + }, //Go to comment modifier = Modifier.padding(start = 20.dp) ){ Icon( @@ -251,4 +272,6 @@ fun LikeInfo(likes : Int){ contentDescription = stringResource(R.string.favorite), tint = iconText, ) -} \ No newline at end of file +} + + From d554b87ab8b04b2c20720ddf09b08a464d472704 Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Mon, 17 Mar 2025 11:41:29 +0100 Subject: [PATCH 2/9] commentaire entity + stub / ajout get comment service / affichage ajout commentaire + liste commentaire / animation apparition commentaire --- .../data/local/CommentStub.kt | 39 +++++ .../what_the_fantasy/data/model/Comment.kt | 8 ++ .../data/services/IServices.kt | 3 +- .../data/services/ServicesAPI.kt | 5 + .../data/services/ServicesStub.kt | 4 + .../what_the_fantasy/ui/screens/QuotePage.kt | 135 +++++++++++++++--- .../app/src/main/res/values-fr/strings.xml | 1 + .../app/src/main/res/values/strings.xml | 1 + 8 files changed, 179 insertions(+), 17 deletions(-) create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/CommentStub.kt create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/Comment.kt diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/CommentStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/CommentStub.kt new file mode 100644 index 0000000..0009b0c --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/CommentStub.kt @@ -0,0 +1,39 @@ +package com.example.what_the_fantasy.data.local + +import com.example.what_the_fantasy.data.model.Comment +import com.example.what_the_fantasy.data.model.User + +object CommentStub { + val comments: MutableList = mutableListOf( + Comment("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"), + ) +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/Comment.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/Comment.kt new file mode 100644 index 0000000..2289d09 --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/Comment.kt @@ -0,0 +1,8 @@ +package com.example.what_the_fantasy.data.model + +data class Comment( + val content : String, + val user : String, + val date : String, + val img : String +) \ 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..8598128 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 @@ -1,5 +1,6 @@ package com.example.what_the_fantasy.data.services +import com.example.what_the_fantasy.data.model.Comment import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.User @@ -12,7 +13,7 @@ interface IServices { fun CreateUser(username : String, email : String, passwd : String, services : IServices) : Boolean fun getFavorite(username: String) fun getAllUsers(): List - + fun getComment(quoteId : Int) : List fun getUserById(id: Int): User? fun SearchQuote(quote : String) 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 facc895..5f85555 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 @@ -1,5 +1,6 @@ package com.example.what_the_fantasy.data.services +import com.example.what_the_fantasy.data.model.Comment import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.ui.navigations.Destination @@ -45,6 +46,10 @@ class ServicesAPI : IServices { TODO("Not yet implemented") } + override fun getComment(quoteId: Int): List { + TODO("Not yet implemented") + } + override fun getUserById(id: Int): User? { 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..354b228 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 @@ -5,7 +5,9 @@ import android.util.Log import com.example.what_the_fantasy.data.local.UserStub.users import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.Logs.LogsUsers +import com.example.what_the_fantasy.data.local.CommentStub.comments import com.example.what_the_fantasy.data.local.QuoteStub +import com.example.what_the_fantasy.data.model.Comment import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.SrcLanguage import com.example.what_the_fantasy.ui.components.hashPassword @@ -64,6 +66,8 @@ class ServicesStub : IServices { override fun getAllUsers(): List = users + override fun getComment(quoteId: Int): List = comments + override fun getUserById(id: Int): User? { return (users.find { it.id == id+1 }) } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt index 2a6aa15..91448c4 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt @@ -2,16 +2,30 @@ package com.example.what_the_fantasy.ui.screens import android.content.Context import android.content.Intent +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.shrinkVertically +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.automirrored.filled.Send import androidx.compose.material.icons.filled.Favorite import androidx.compose.material.icons.filled.FavoriteBorder import androidx.compose.material.icons.filled.MailOutline @@ -19,6 +33,7 @@ import androidx.compose.material.icons.filled.Share import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Text +import androidx.compose.material3.TextField import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -37,6 +52,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.R import coil.compose.AsyncImage +import com.example.what_the_fantasy.data.model.Comment 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.theme.colorBackground @@ -58,7 +74,7 @@ fun QuotePage( navProfil:(Int) -> Unit) { // utiliser ViewModel - var quote = service.getQuote(quoteId) ?: return + val quote = service.getQuote(quoteId) ?: return val context = LocalContext.current NavBar(onProfile = true, index = index, @@ -125,13 +141,27 @@ fun QuotePage( } } } - if(isCommentVisible){ - Box(modifier = Modifier.fillMaxWidth().background(Color.White)){ + AnimatedVisibility( + visible = isCommentVisible, + enter = expandVertically( + expandFrom = Alignment.CenterVertically + ) + fadeIn( + initialAlpha = 0.3f + ) + slideInVertically( + initialOffsetY = { -40 } + ), + exit = slideOutVertically() + shrinkVertically() + fadeOut() + ) { + Box(modifier = Modifier.fillMaxWidth().background(gradienBox).fillMaxSize()){ Column { - + AddComment(index) + LstComment(service.getComment(quoteId)) } } } + if(isCommentVisible){ + + } } } @@ -170,13 +200,13 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ val sendIntent = Intent().apply { action = Intent.ACTION_SEND // lien a changer quand le site sra deployer - putExtra(Intent.EXTRA_TEXT, "http://wfWebsite/quote/" + id.toString() ) + putExtra(Intent.EXTRA_TEXT, "http://wfWebsite/quote/$id") type = "text/plain" - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) // Ajout pour compatibilité + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } val shareIntent = Intent.createChooser(sendIntent, null) - shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) // Ajout aussi ici + shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(shareIntent) }, @@ -190,13 +220,8 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ } IconButton( onClick = { - if(isCommentVisible){ - isCommentVisible = false - } - else{ - isCommentVisible = true - } - }, //Go to comment + isCommentVisible = !isCommentVisible + }, modifier = Modifier.padding(start = 20.dp) ){ Icon( @@ -208,7 +233,7 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ if(isFavorite){ IconButton( - onClick = { }, //Go to comment + onClick = { }, //sup fav modifier = Modifier.padding(start = 20.dp) ){ Icon( @@ -221,7 +246,7 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ } else{ IconButton( - onClick = { }, //Go to comment + onClick = { }, //add fav modifier = Modifier.padding(start = 50.dp) ){ Icon( @@ -274,4 +299,82 @@ fun LikeInfo(likes : Int){ ) } +@Composable +fun AddComment(userId : Int){ + var text by remember { mutableStateOf("") } + Row{ + IconButton( + onClick = { isCommentVisible = !isCommentVisible}, + ){ + Icon( + Icons.AutoMirrored.Filled.ArrowBack, + contentDescription = stringResource(R.string.send), + tint = iconText + ) + } + TextField( + value = text, + onValueChange = { text = it }, + label = { Text(stringResource(R.string.comment)) }, + modifier = Modifier.drawBehind { + drawRoundRect( + Color.White, + cornerRadius = CornerRadius(15.dp.toPx()) + ) + } + .width(300.dp) + ) + IconButton( + onClick = { }, //send comment + ){ + Icon( + Icons.AutoMirrored.Filled.Send, + contentDescription = stringResource(R.string.send), + tint = iconText + ) + } + } +} + +@Composable +fun LstComment(lst : List){ + LazyColumn( + verticalArrangement = Arrangement.spacedBy(4.dp), + ) { + items( + items = lst, + ) { + Column( + modifier = Modifier.padding(5.dp) + .fillMaxSize() + .drawBehind { + drawRoundRect( + Color.White, + cornerRadius = CornerRadius(15.dp.toPx()) + ) + } + ) { + Row { + AsyncImage( + model = it.img, + contentDescription = stringResource(R.string.profilePict), + modifier = Modifier + .size(50.dp) + .clip(RoundedCornerShape(50)) + ) + Text( + text = it.user + " " + it.date, + modifier = Modifier.padding(start = 15.dp) + ) + } + Row { + Text( + text = it.content, + modifier = Modifier.padding(15.dp), + ) + } + } + } + } +} 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..680c90d 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 @@ -13,6 +13,7 @@ Favoris Likes Image de profil + Envoyer //Page Login Connexion au compte 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..dd450d6 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -12,6 +12,7 @@ favorite likes Profile picture + Send //Page Login Account login From afd5ca2a99d87a3fc0ac45f28cd1476e2847966b Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Wed, 19 Mar 2025 14:11:30 +0100 Subject: [PATCH 3/9] =?UTF-8?q?ajout=20des=20methode(pas=20encore=20implem?= =?UTF-8?q?enter)=20n=C3=A9c=C3=A9saire=20pour=20la=20fin=20de=20la=20page?= =?UTF-8?q?=20quote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/services/IServices.kt | 4 +++- .../data/services/ServicesAPI.kt | 12 ++++++++++ .../data/services/ServicesStub.kt | 13 +++++++++++ .../what_the_fantasy/ui/components/NavBar.kt | 2 +- .../what_the_fantasy/ui/screens/QuotePage.kt | 23 +++++++++---------- .../app/src/main/res/values/strings.xml | 6 ++--- 6 files changed, 43 insertions(+), 17 deletions(-) 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 8598128..d2d317a 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 @@ -9,7 +9,9 @@ interface IServices { fun EditEmail(email : String, index : Int) fun EditPasswd(passwd : String, index : Int) fun EditImage(imageURL : String, index : Int) - + fun AddFav(userId: Int, QuoteId : Int) + fun SupFav(userId: Int, QuoteId : Int) + fun AddComment(content : String) fun CreateUser(username : String, email : String, passwd : String, services : IServices) : Boolean fun getFavorite(username: String) fun getAllUsers(): List 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 5f85555..9aee3ba 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 @@ -22,6 +22,18 @@ class ServicesAPI : IServices { TODO("Not yet implemented") } + override fun AddFav(userId: Int, QuoteId: Int) { + TODO("Not yet implemented") + } + + override fun SupFav(userId: Int, QuoteId: Int) { + TODO("Not yet implemented") + } + + override fun AddComment(content: String) { + TODO("Not yet implemented") + } + override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : 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 354b228..b51c15f 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 @@ -45,6 +45,19 @@ class ServicesStub : IServices { TODO("Not yet implemented") } + override fun AddFav(userId: Int, QuoteId: Int) { + TODO("Not yet implemented") + } + + override fun SupFav(userId: Int, QuoteId: Int) { + TODO("Not yet implemented") + } + + override fun AddComment(content: String) { + TODO("Not yet implemented") + //comments.add(Comment(content = content,)) + } + override fun CreateUser(username: String, email: String, passwd: String, services : IServices) : Boolean { val date =dateDuJour() val passwordhash = hashPassword(passwd) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt index 8d89f41..391bb36 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt @@ -146,7 +146,7 @@ fun ButtonIconPainterInt(img : Painter, name : String, nav : (Int)->Unit,index: Icon(img, contentDescription = name, modifier = Modifier - .fillMaxSize() + .size(50.dp) ) } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt index 91448c4..094431b 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt @@ -108,9 +108,11 @@ fun QuotePage( // --/!\-- a modifier --/!\-- // isFavorite = service.isFavorite(id) // -------------------------- - true, + false, + userId = index, id = quoteId, - context = context + context = context, + service = service ) QuoteText( text = '"' + quote.content + '"' @@ -154,14 +156,11 @@ fun QuotePage( ) { Box(modifier = Modifier.fillMaxWidth().background(gradienBox).fillMaxSize()){ Column { - AddComment(index) + AddComment(index, service) LstComment(service.getComment(quoteId)) } } } - if(isCommentVisible){ - - } } } @@ -190,7 +189,7 @@ fun ImageQuote(imageUrl : String){ } @Composable -fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ +fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Context, service: IServices){ Row(modifier = Modifier .fillMaxWidth() ) { @@ -233,7 +232,7 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ if(isFavorite){ IconButton( - onClick = { }, //sup fav + onClick = { service.SupFav(userId = userId, QuoteId = id)}, //sup fav modifier = Modifier.padding(start = 20.dp) ){ Icon( @@ -246,7 +245,7 @@ fun FunctionalIcon(isFavorite: Boolean, id : Int, context : Context){ } else{ IconButton( - onClick = { }, //add fav + onClick = { service.AddFav(userId = userId, QuoteId = id)}, //add fav modifier = Modifier.padding(start = 50.dp) ){ Icon( @@ -300,9 +299,9 @@ fun LikeInfo(likes : Int){ } @Composable -fun AddComment(userId : Int){ +fun AddComment(userId : Int, service: IServices){ var text by remember { mutableStateOf("") } - Row{ + Row(modifier = Modifier.padding(bottom = 15.dp, top = 15.dp)){ IconButton( onClick = { isCommentVisible = !isCommentVisible}, ){ @@ -325,7 +324,7 @@ fun AddComment(userId : Int){ .width(300.dp) ) IconButton( - onClick = { }, //send comment + onClick = { service.AddComment(text)}, //send comment ){ Icon( Icons.AutoMirrored.Filled.Send, 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 dd450d6..f54602e 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -8,9 +8,9 @@ Character Source Share - comment - favorite - likes + Comment + Favorite + Likes Profile picture Send From a4e874b8fc0349f9f6fd5f702c6443314fe9c7ff Mon Sep 17 00:00:00 2001 From: brongniart Date: Wed, 19 Mar 2025 14:47:55 +0100 Subject: [PATCH 4/9] debut SearchPage --- .../data/services/IServices.kt | 3 + .../data/services/ServicesAPI.kt | 4 + .../data/services/ServicesStub.kt | 18 +++ .../what_the_fantasy/ui/components/NavBar.kt | 69 +++++----- .../ui/navigations/AppNavigator.kt | 33 +++-- .../ui/screens/AccueilPage.kt | 20 +-- .../ui/screens/FavoritePage.kt | 14 +-- .../what_the_fantasy/ui/screens/ProfilPage.kt | 12 +- .../ui/screens/QuizEndPage.kt | 16 +-- .../what_the_fantasy/ui/screens/QuizMenu.kt | 14 +-- .../what_the_fantasy/ui/screens/QuizPage.kt | 15 +-- .../what_the_fantasy/ui/screens/QuotePage.kt | 16 +-- .../what_the_fantasy/ui/screens/SearchPage.kt | 119 +++++++++++++++++- .../app/src/main/res/values-fr/strings.xml | 12 ++ .../app/src/main/res/values/strings.xml | 11 ++ 15 files changed, 284 insertions(+), 92 deletions(-) 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..d05e397 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 @@ -21,4 +21,7 @@ interface IServices { fun isFavorite(id : Int): Boolean + fun search(type : String ,search:String ,indexCount: Int): List + + } \ No newline at end of file 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..b92526c 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 @@ -47,4 +47,8 @@ class ServicesAPI : IServices { override fun getUserById(id: Int): User? { TODO("Not yet implemented") } + + override fun search(type : String ,search:String ,indexCount: Int): List{ + TODO("Not yet implemented") + } } \ 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..78de341 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 @@ -95,4 +95,22 @@ 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" } + + override fun search(type : String ,search:String ,indexCount: Int): List { + return (QuoteStub.allQuotes.filter { + when (type) { + "personnage" -> { + it.character.uppercase().contains(search.uppercase()) + } + + "titre" -> { + it.source.uppercase().contains(search.uppercase()) + } + + else -> { + it.content.uppercase().contains(search.uppercase()) + } + } + }.take(indexCount)) + } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt index 898376b..d750b22 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/NavBar.kt @@ -30,6 +30,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.example.what_the_fantasy.R import com.example.what_the_fantasy.ui.theme.* @@ -39,11 +40,11 @@ fun NavBar(onProfile : Boolean = false , onFavorite : Boolean = false , onAccueil : Boolean = false , onQuiz : Boolean = false , - index:Int, - navControllerProfil: (Int) -> Unit, - navControllerFavorite:(Int) -> Unit, - navControllerAccueil: (Int) -> Unit, - navControllerQuiz: (Int) -> Unit, + navControllerProfil: () -> Unit = {}, + navControllerFavorite:() -> Unit = {}, + navControllerAccueil: () -> Unit = {}, + navControllerQuiz: () -> Unit = {}, + navControllerSearch: () -> Unit = {}, content : @Composable ()-> Unit ) { @@ -63,26 +64,34 @@ fun NavBar(onProfile : Boolean = false , Arrangement.SpaceBetween, verticalAlignment = Alignment.Bottom ) { - ButtonIconVectorInt(Icons.Rounded.AccountCircle,"Profile",navControllerProfil,index,onProfile) - - - IconButton(onClick = { theme=!theme}, - modifier = Modifier.size(60.dp) - .clip(RoundedCornerShape(0)) - ) { - Icon(painterResource( - if(theme)R.drawable.dark_mode_toggle_icon - else R.drawable.light_mode_toggle_icon), - contentDescription = "Dark mode", - modifier = Modifier.fillMaxSize(), - tint = Color.White - ) + ButtonIconVector(Icons.Rounded.AccountCircle,stringResource(R.string.NavProfile),navControllerProfil,onProfile) + + Row{ + ButtonIconVector(Icons.Rounded.Search,stringResource(R.string.NavSearch),navControllerSearch,false) + + + IconButton(onClick = { theme=!theme}, + modifier = Modifier + .size(60.dp) + .clip(RoundedCornerShape(0)) + ) { + Icon(painterResource( + if(theme)R.drawable.dark_mode_toggle_icon + else R.drawable.light_mode_toggle_icon), + contentDescription = "Dark mode", + modifier = Modifier.fillMaxSize(), + tint = Color.White + ) + } + } } } - Box(modifier = Modifier.background(Color.Black).fillMaxHeight(0.90f)){ + Box(modifier = Modifier + .background(Color.Black) + .fillMaxHeight(0.90f)){ content() } @@ -96,20 +105,20 @@ fun NavBar(onProfile : Boolean = false , verticalAlignment = Alignment.CenterVertically ) { - ButtonIconPainterInt(painterResource( + ButtonIconPainter(painterResource( if(onFavorite)R.drawable.favorite_button_full else R.drawable.favorite_button_empty - ),"Favorite",navControllerFavorite,index,onFavorite) + ), stringResource(R.string.NavFavorite) ,navControllerFavorite,onFavorite) - ButtonIconPainterInt(painterResource( + ButtonIconPainter(painterResource( if(onAccueil)R.drawable.home_button_full else R.drawable.home_button_empty - ),"Accueil",navControllerAccueil,index,onAccueil) + ),stringResource(R.string.NavHome),navControllerAccueil,onAccueil) - ButtonIconPainterInt(painterResource( + ButtonIconPainter(painterResource( if(onQuiz)R.drawable.quiz_button_full else R.drawable.quiz_button_empty - ),"Quiz",navControllerQuiz,index,onQuiz) + ),stringResource(R.string.NavQuiz),navControllerQuiz,onQuiz) } } @@ -117,8 +126,8 @@ fun NavBar(onProfile : Boolean = false , } @Composable -fun ButtonIconVectorInt(img : ImageVector, name : String, nav : (Int)->Unit ,index: Int,onPage : Boolean){ - IconButton(onClick = {nav(index)}, +fun ButtonIconVector(img : ImageVector, name : String, nav : ()->Unit,onPage : Boolean){ + IconButton(onClick = {nav()}, enabled = !onPage, colors = IconButtonColors(Color.Transparent, colorButtonNav,//couleur quand il n'est pas selectionné Color.Transparent, colorButtonNavSelected),//couleur quand il est selectionné @@ -135,8 +144,8 @@ fun ButtonIconVectorInt(img : ImageVector, name : String, nav : (Int)->Unit ,ind @Composable -fun ButtonIconPainterInt(img : Painter, name : String, nav : (Int)->Unit,index: Int,onPage : Boolean){ - IconButton(onClick = {nav(index)}, +fun ButtonIconPainter(img : Painter, name : String, nav : ()->Unit,onPage : Boolean){ + IconButton(onClick = {nav()}, enabled = !onPage, colors = IconButtonColors(Color.Transparent,colorButtonNav,//couleur quand il n'est pas selectionné Color.Transparent, colorButtonNavSelected),//couleur quand il est selectionné 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..00ab78a 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 @@ -40,7 +40,7 @@ data class QuizEnd(val userIndex: Int, val idQuiz: Int, val pts: Int) data class OneQuote(val quoteId: Int, val userIndex: Int) @Serializable -data object Search +data class Search(val userIndex: Int,val type : String = "", val search: String = "") @Serializable data object SignUp @@ -73,11 +73,11 @@ fun AppNavigator() { composable { val accueil: Accueil = it.toRoute() AccueilPage( - index = accueil.userIndex, 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)) }, + navSearch = { navController.navigate(Search(accueil.userIndex))} ) } composable { @@ -88,6 +88,7 @@ fun AppNavigator() { navQuiz = { navController.navigate(QuizMenu(favorite.userIndex)) }, navProfil = { navController.navigate(Profil(favorite.userIndex)) }, navQuote = { quoteId -> navController.navigate(OneQuote(quoteId,favorite.userIndex)) }, + navSearch = { navController.navigate(Search(favorite.userIndex))}, services = services ) } @@ -103,6 +104,7 @@ fun AppNavigator() { popUpTo(profil) { inclusive = true } } }, + navSearch = { navController.navigate(Search(profil.userIndex))}, services = services ) } @@ -110,15 +112,28 @@ fun AppNavigator() { val quote: OneQuote = it.toRoute() QuotePage( quoteId = quote.quoteId, - index = quote.userIndex, navAccueil = { navController.navigate(Accueil(quote.userIndex)) }, navQuiz = { navController.navigate(QuizMenu(quote.userIndex)) }, navProfil = { navController.navigate(Profil(quote.userIndex)) }, navFavorite = { navController.navigate(Favorite(quote.userIndex)) }, + navSearch = { navController.navigate(Search(quote.userIndex))}, service = services ) } - composable { SearchPage() } + composable { + val search: Search = it.toRoute() + SearchPage( + navAccueil = { navController.navigate(Accueil(search.userIndex)) }, + navFavorite = { navController.navigate(Favorite(search.userIndex)) }, + navQuiz = { navController.navigate(QuizMenu(search.userIndex)) }, + navProfil = { navController.navigate(Profil(search.userIndex)) }, + navQuote = { quoteId -> navController.navigate(OneQuote(quoteId,search.userIndex)) }, + navSearch = {type,newSearch -> navController.navigate(Search(search.userIndex,type,newSearch))}, + services = services, + type = search.type, + search = search.search + ) + } composable { SignUpPage( navControllerLogin = { @@ -133,10 +148,10 @@ fun AppNavigator() { composable { val quizMenu: QuizMenu = it.toRoute() QuizMenu( - index = quizMenu.userIndex, navAccueil = { navController.navigate(Accueil(quizMenu.userIndex)) }, navFavorite = { navController.navigate(Favorite(quizMenu.userIndex)) }, navProfil = { navController.navigate(Profil(quizMenu.userIndex)) }, + navSearch = { navController.navigate(Search(quizMenu.userIndex))}, navControllerQuiz = { idQuiz -> navController.navigate(Quiz(quizMenu.userIndex, idQuiz)) } @@ -145,7 +160,6 @@ fun AppNavigator() { composable { val quiz: Quiz = it.toRoute() QuizPage( - index = quiz.userIndex, navAccueil = { navController.navigate(Accueil(quiz.userIndex)) }, navFavorite = { navController.navigate(Favorite(quiz.userIndex)) }, navProfil = { navController.navigate(Profil(quiz.userIndex)) }, @@ -153,6 +167,7 @@ fun AppNavigator() { navControllerQuizEnd = { idQuiz, pts -> navController.navigate(QuizEnd(quiz.userIndex, idQuiz, pts)) }, + navSearch = { navController.navigate(Search(quiz.userIndex))}, idQuiz = quiz.idQuiz ) } @@ -161,11 +176,11 @@ fun AppNavigator() { QuizEndPage( idQuiz = quizEnd.idQuiz, points = quizEnd.pts, - index = quizEnd.userIndex, navAccueil = { navController.navigate(Accueil(quizEnd.userIndex)) }, navFavorite = { navController.navigate(Favorite(quizEnd.userIndex)) }, navProfil = { navController.navigate(Profil(quizEnd.userIndex)) }, - navQuiz = { navController.navigate(QuizMenu(quizEnd.userIndex)) } + navQuiz = { navController.navigate(QuizMenu(quizEnd.userIndex)) }, + navSearch = { navController.navigate(Search(quizEnd.userIndex))} ) } } 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..7d512c4 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 @@ -23,10 +23,10 @@ import com.example.what_the_fantasy.ui.theme.colorBackground @Composable fun AccueilPage( - index: Int, - navFavorite: (Int) -> Unit, - navQuiz: (Int) -> Unit, - navProfil: (Int) -> Unit, + navFavorite: () -> Unit, + navQuiz: () -> Unit, + navProfil: () -> Unit, + navSearch: () -> Unit, navQuote: (Int) -> Unit ) { var itemCount by remember { mutableStateOf(15) } @@ -35,11 +35,10 @@ fun AccueilPage( NavBar( onAccueil = true, - index = index, navControllerFavorite = navFavorite, - navControllerAccueil = { }, navControllerProfil = navProfil, - navControllerQuiz = navQuiz + navControllerQuiz = navQuiz, + navControllerSearch = navSearch ) { Column( modifier = Modifier @@ -59,7 +58,11 @@ fun AccueilPage( textAlign = TextAlign.Center ) - QuoteLittle(dailyQuote) + Column(Modifier.clickable {navQuote(dailyQuote.id)} + ) { + QuoteLittle(dailyQuote) + } + } Text( text = "▶ Suggestions ◀", @@ -75,7 +78,6 @@ fun AccueilPage( Column(Modifier.clickable {navQuote(quote.id)} ) { 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..575c2fc 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 @@ -23,9 +23,10 @@ import com.example.what_the_fantasy.ui.theme.colorBackground @Composable fun FavoritePage( index: Int, - navAccueil: (Int) -> Unit, - navQuiz: (Int) -> Unit, - navProfil: (Int) -> Unit, + navAccueil: () -> Unit, + navQuiz: () -> Unit, + navProfil: () -> Unit, + navSearch: () -> Unit, navQuote: (Int) -> Unit, services: IServices ) { @@ -33,11 +34,10 @@ fun FavoritePage( val quotes = FavoriteStub.getFavoritesByUser(user.id) NavBar(onFavorite = true, - index = index, - navControllerFavorite = { }, navControllerAccueil = navAccueil, navControllerProfil = navProfil, - navControllerQuiz = navQuiz + navControllerQuiz = navQuiz, + navControllerSearch = navSearch ) { Box( modifier = Modifier @@ -60,8 +60,6 @@ fun FavoritePage( items(quotes) { quote -> Column (Modifier.clickable { navQuote( quote.id )} ){ QuoteLittle(quote) - - Spacer(modifier = Modifier.height(16.dp)) } } } 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..5cffacb 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 @@ -75,20 +75,20 @@ import com.example.what_the_fantasy.ui.theme.gradienBox @Composable fun ProfilPage(index: Int, - navFavorite: (Int) -> Unit, - navAccueil: (Int) -> Unit, - navQuiz: (Int) -> Unit, + navFavorite: () -> Unit, + navAccueil: () -> Unit, + navQuiz: () -> Unit, + navSearch: () -> Unit, navUnLog: () -> Unit, services: IServices ) { val user = services.getUserById(index) ?: return NavBar(onProfile = true, - index = index, navControllerFavorite = navFavorite, navControllerAccueil = navAccueil, - navControllerProfil = {}, - navControllerQuiz = navQuiz + navControllerQuiz = navQuiz, + navControllerSearch = navSearch ) { Box( diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt index 491db9a..280b661 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt @@ -38,17 +38,19 @@ val gradient = Brush.linearGradient( fun QuizEndPage( idQuiz: Int, points: Int, - index: Int, - navFavorite: (Int) -> Unit, - navAccueil: (Int) -> Unit, - navProfil:(Int) -> Unit, - navQuiz: (Int) -> Unit, + navFavorite: () -> Unit, + navAccueil: () -> Unit, + navProfil:() -> Unit, + navQuiz: () -> Unit, + navSearch: () -> Unit, ) { - NavBar(index = index, + NavBar( navControllerFavorite = navFavorite, navControllerAccueil = navAccueil, navControllerProfil = navProfil, - navControllerQuiz = navQuiz) { + navControllerQuiz = navQuiz, + navControllerSearch = navSearch + ) { Column( modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) ) { diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt index 99c50af..cedc17a 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt @@ -41,18 +41,18 @@ import com.example.what_the_fantasy.ui.components.NavBar @Composable -fun QuizMenu( index: Int, - navFavorite: (Int) -> Unit, - navAccueil: (Int) -> Unit, - navProfil:(Int) -> Unit, - navControllerQuiz: (Int) -> Unit +fun QuizMenu( + navFavorite: () -> Unit, + navAccueil: () -> Unit, + navProfil:() -> Unit, + navSearch: () -> Unit, + navControllerQuiz: (Int) -> Unit ) { NavBar(onQuiz = true, - index = index, navControllerFavorite = navFavorite, navControllerAccueil = navAccueil, navControllerProfil = navProfil, - navControllerQuiz = { } + navControllerSearch = navSearch ) { Column( diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizPage.kt index 05fdf2f..70946c0 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizPage.kt @@ -27,11 +27,11 @@ import com.example.what_the_fantasy.ui.components.NavBar @Composable fun QuizPage( - index: Int, - navFavorite: (Int) -> Unit, - navAccueil: (Int) -> Unit, - navProfil:(Int) -> Unit, - navQuiz: (Int) -> Unit, + navFavorite: () -> Unit, + navAccueil: () -> Unit, + navProfil:() -> Unit, + navQuiz: () -> Unit, + navSearch: () -> Unit, navControllerQuizEnd: (Int, Int) -> Unit, @@ -61,11 +61,12 @@ fun QuizPage( if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++ else navControllerQuizEnd(idQuiz, pts) // Retour menu } - NavBar(index = index, + NavBar( navControllerFavorite = navFavorite, navControllerAccueil = navAccueil, navControllerProfil = navProfil, - navControllerQuiz = navQuiz + navControllerQuiz = navQuiz, + navControllerSearch = navSearch ){ Column ( modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt index 16dcfac..15c0239 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt @@ -45,20 +45,20 @@ import com.example.what_the_fantasy.ui.theme.whiteBackcgroundText fun QuotePage( quoteId : Int, service : IServices, - index : Int, - navAccueil: (Int) -> Unit, - navFavorite:(Int) -> Unit, - navQuiz: (Int) -> Unit, - navProfil:(Int) -> Unit) + navAccueil: () -> Unit, + navFavorite:() -> Unit, + navQuiz: () -> Unit, + navSearch: () -> Unit, + navProfil:() -> Unit) { var quote = service.getQuote(quoteId) ?: return val context = LocalContext.current - NavBar(onProfile = true, - index = index, + NavBar( navControllerFavorite = navFavorite, navControllerAccueil = navAccueil, navControllerProfil = navProfil, - navControllerQuiz = navQuiz + navControllerQuiz = navQuiz, + navControllerSearch = navSearch ) { Box( modifier = Modifier diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt index 3d081c1..55c1200 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt @@ -1,8 +1,125 @@ package com.example.what_the_fantasy.ui.screens +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material3.Button +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +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.input.KeyboardType +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.data.services.ServicesStub 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 @Composable -fun SearchPage() { +fun SearchPage( + navFavorite: () -> Unit, + navAccueil: () -> Unit, + navProfil:() -> Unit, + navQuiz: () -> Unit, + navQuote: (Int) -> Unit, + navSearch: (String,String) -> Unit, + services: IServices, + + type : String, + search:String + ) { + var itemCount by remember { mutableStateOf(15) } + val quotes = services.search(type,search,itemCount) + var newSearch by remember { mutableStateOf(search) } + + NavBar( + onAccueil = true, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = navQuiz, + navControllerSearch = {navSearch("","")} + ) { + Column( + modifier = Modifier + .fillMaxSize() + .background(colorBackground) + ) { + + Text( + text = "▶ "+stringResource(R.string.TitleSearch)+" ◀", + color = Color.White, + fontSize = 24.sp, + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + textAlign = TextAlign.Center + ) + Row(){ + OutlinedTextField( + value = newSearch, + onValueChange = { newSearch = it }, + label = { Text(newSearch) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) // Bords arrondis + ) + Button(onClick = { navSearch("", newSearch) }) { + Text( + "Search", + color = Color.White + ) + } + } + LazyColumn(modifier = Modifier.weight(1f)) { + items(quotes) { quote -> + Column(Modifier.clickable {navQuote(quote.id)} + ) { + QuoteLittle(quote) + } + } + if (itemCount < QuoteStub.allQuotes.size) { + item { + LaunchedEffect(itemCount) { + itemCount += 15 + } + Box( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + contentAlignment = Alignment.Center + ) { + CircularProgressIndicator() + } + } + } + } + } + } } \ No newline at end of file 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..a1d3523 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 @@ -52,4 +52,16 @@ //Page Favori Favoris + + //NavBar + Favoris + Profile + Accueil + Quiz + Recherche + + //Page Search + Recherche + + \ 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..22139f1 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -50,4 +50,15 @@ //Page Favori Favorites + //NavBar + Favorite + Profile + Home + Quiz + Search + + //Page Search + Search + + \ No newline at end of file From da07d3fe25966c17f7c29a17ea514c5ccfb700b0 Mon Sep 17 00:00:00 2001 From: brongniart Date: Wed, 19 Mar 2025 17:37:19 +0100 Subject: [PATCH 5/9] finnition Search --- .../what_the_fantasy/data/model/SrcType.kt | 9 +- .../ui/navigations/AppNavigator.kt | 2 +- .../what_the_fantasy/ui/screens/LoginPage.kt | 2 + .../what_the_fantasy/ui/screens/SearchPage.kt | 82 ++++++++++++++++--- 4 files changed, 81 insertions(+), 14 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/SrcType.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/SrcType.kt index 6e8671f..a5c6112 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/SrcType.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/SrcType.kt @@ -1,7 +1,10 @@ package com.example.what_the_fantasy.data.model +import androidx.compose.ui.res.stringResource +import com.example.what_the_fantasy.R + enum class SrcType (val value: String) { - Movie("@string/movie"), - VideoGame("@string/videoGame"), - Series("@string/series"), + Movie("movie" ), + VideoGame("videoGame"), + Series("series"), } \ No newline at end of file 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 00ab78a..75f78b6 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 @@ -40,7 +40,7 @@ data class QuizEnd(val userIndex: Int, val idQuiz: Int, val pts: Int) data class OneQuote(val quoteId: Int, val userIndex: Int) @Serializable -data class Search(val userIndex: Int,val type : String = "", val search: String = "") +data class Search(val userIndex: Int,val type : String = "contenue", val search: String = "") @Serializable data object SignUp diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt index fca9d38..b90d6d4 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt @@ -98,6 +98,7 @@ fun IdentifiantTextField(textIdentifiantResId : Int) : String{ .fillMaxWidth() .padding(top = 8.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + maxLines = 1, shape = RoundedCornerShape(16.dp) // Bords arrondis ) } @@ -118,6 +119,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{ .fillMaxWidth() .padding(top = 8.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password), + maxLines = 1, visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(), trailingIcon = { IconButton(onClick = { passwordVisible = !passwordVisible }) { diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt index 55c1200..44ec1fe 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SearchPage.kt @@ -2,19 +2,34 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.IntrinsicSize import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.selection.selectable +import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Search import androidx.compose.material3.Button import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.RadioButton +import androidx.compose.material3.SearchBar import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -24,20 +39,27 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.input.pointer.motionEventSpy import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue 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.model.SrcType import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.data.services.ServicesStub 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 +import com.example.what_the_fantasy.ui.theme.colorNavBar @Composable fun SearchPage( @@ -54,7 +76,10 @@ fun SearchPage( ) { var itemCount by remember { mutableStateOf(15) } val quotes = services.search(type,search,itemCount) + var newSearch by remember { mutableStateOf(search) } + val filtre = listOf("contenue","personnage","titre") + val (newFiltre, onFiltreSelected) = remember { mutableStateOf(type) } NavBar( onAccueil = true, @@ -62,7 +87,7 @@ fun SearchPage( navControllerAccueil = navAccueil, navControllerProfil = navProfil, navControllerQuiz = navQuiz, - navControllerSearch = {navSearch("","")} + navControllerSearch = {navSearch("contenue","")} ) { Column( modifier = Modifier @@ -79,22 +104,59 @@ fun SearchPage( .padding(16.dp), textAlign = TextAlign.Center ) - Row(){ + Column (horizontalAlignment = Alignment.CenterHorizontally + ){ OutlinedTextField( value = newSearch, onValueChange = { newSearch = it }, - label = { Text(newSearch) }, + textStyle = TextStyle(color = Color.White), modifier = Modifier + .padding(top = 2.dp) .fillMaxWidth() - .padding(top = 8.dp), + .height(50.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), - shape = RoundedCornerShape(16.dp) // Bords arrondis + maxLines = 1, + shape = CircleShape, // Bords arrondis + trailingIcon = { + IconButton(onClick = { navSearch(newFiltre, newSearch) } , + modifier = Modifier + .size(50.dp) + .clip(CircleShape) + ) { + Icon(Icons.Rounded.Search, + contentDescription = stringResource(R.string.TitleSearch), + Modifier + .fillMaxSize() + .background(Color.Magenta,CircleShape) + ) + } + } ) - Button(onClick = { navSearch("", newSearch) }) { - Text( - "Search", - color = Color.White - ) + Row(horizontalArrangement = Arrangement.SpaceAround) { + filtre.forEach{ type -> + Row( + Modifier + .height(56.dp) + .selectable( + selected = (type == newFiltre), + onClick = { onFiltreSelected(type) }, + role = Role.RadioButton + ) + .padding(horizontal = 16.dp), + verticalAlignment = Alignment.CenterVertically + ) { + RadioButton( + selected = (type == newFiltre), + onClick = null // null recommended for accessibility with screen readers + ) + Text( + text = type, + style = MaterialTheme.typography.bodyLarge, + modifier = Modifier.padding(start = 16.dp), + color = Color.White + ) + } + } } } LazyColumn(modifier = Modifier.weight(1f)) { From eae5f8e085a4ef983acf2c73c8c9f4f3b1ba4db9 Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Mon, 24 Mar 2025 10:22:49 +0100 Subject: [PATCH 6/9] =?UTF-8?q?fin=20page=20quote=20(l=C3=A9g=C3=A8re=20mo?= =?UTF-8?q?dif=20=C3=A0=20faire=20avec=20les=20viewModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/what_the_fantasy/data/mvvm/AppViewModel.kt | 9 --------- .../what_the_fantasy/data/services/ServicesStub.kt | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/mvvm/AppViewModel.kt diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/mvvm/AppViewModel.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/mvvm/AppViewModel.kt deleted file mode 100644 index 2a845ae..0000000 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/mvvm/AppViewModel.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.example.what_the_fantasy.data.mvvm - -import androidx.lifecycle.ViewModel -import com.example.what_the_fantasy.data.model.Quiz -import com.example.what_the_fantasy.data.model.Quote - -class AppViewModel: ViewModel() { - -} \ 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 b51c15f..a546727 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 @@ -46,11 +46,11 @@ class ServicesStub : IServices { } override fun AddFav(userId: Int, QuoteId: Int) { - TODO("Not yet implemented") + return } override fun SupFav(userId: Int, QuoteId: Int) { - TODO("Not yet implemented") + return } override fun AddComment(content: String) { From 41af18d4437d16e3504746234b2a846e7f2ff5bd Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Mon, 24 Mar 2025 11:46:16 +0100 Subject: [PATCH 7/9] =?UTF-8?q?modif=20quote=20pour=20coh=C3=A9rence=20ave?= =?UTF-8?q?c=20master?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/local/FavoriteStub.kt | 2 +- .../data/services/IServices.kt | 2 +- .../data/services/ServicesAPI.kt | 2 +- .../data/services/ServicesStub.kt | 10 ++- .../what_the_fantasy/ui/screens/QuotePage.kt | 76 ++++++++----------- 5 files changed, 42 insertions(+), 50 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/FavoriteStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/FavoriteStub.kt index b092123..b977a10 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/FavoriteStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/FavoriteStub.kt @@ -6,7 +6,7 @@ import com.example.what_the_fantasy.data.model.Favorite object FavoriteStub { val favorites: MutableList = mutableListOf( - Favorite(users[0], mutableListOf(quotes[0], quotes[0], quotes[0])), // Aragorn123 aime ces citations + Favorite(users[0], mutableListOf(quotes[0], quotes[1], quotes[12])), // Aragorn123 aime ces citations Favorite(users[1], mutableListOf(quotes[5], quotes[6], quotes[7])), // Legolas456 aime ces citations Favorite(users[2], mutableListOf(quotes[8], quotes[9], quotes[10])), // Gandalf789 aime ces citations Favorite(users[3], mutableListOf(quotes[11], quotes[12], quotes[13])), // FrodoBaggins aime ces citations 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 142b022..0ff0c06 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 @@ -25,7 +25,7 @@ interface IServices { fun getQuote( id : Int): Quote? - fun isFavorite(id : Int): Boolean + fun isFavorite(id : Int, user: User): Boolean fun getAllFavorite(): List fun getAllQuote(): List } \ No newline at end of file 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 e8d6676..0155073 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 @@ -55,7 +55,7 @@ class ServicesAPI : IServices { TODO("Not yet implemented") } - override fun isFavorite(id: Int): Boolean { + override fun isFavorite(id: Int, user: User): 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 60607bb..8206708 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 @@ -76,6 +76,7 @@ class ServicesStub : IServices { } override fun AddComment(content: String) { + return TODO("Not yet implemented") //comments.add(Comment(content = content,)) } @@ -100,7 +101,7 @@ class ServicesStub : IServices { override fun getFavorite(user: User): List { val favorite = favorites - return favorite[0].quote + return favorite[user.id-1].quote //return emptyList() } @@ -119,11 +120,12 @@ class ServicesStub : IServices { } override fun getQuote(id: Int): Quote? { - return (quotes.find { it.id == id+1 }) + return (quotes.find { it.id == id }) } - override fun isFavorite(id: Int): Boolean { - TODO("Not yet implemented") + override fun isFavorite(id: Int, user: User): Boolean { + var quote = getFavorite(user) + return quote.find{ it.id == id } != null } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt index 094431b..db092f5 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuotePage.kt @@ -32,6 +32,7 @@ import androidx.compose.material.icons.filled.MailOutline import androidx.compose.material.icons.filled.Share import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.runtime.Composable @@ -76,7 +77,10 @@ fun QuotePage( // utiliser ViewModel val quote = service.getQuote(quoteId) ?: return val context = LocalContext.current - NavBar(onProfile = true, + val user = service.getUserById(index) ?: return + val favorite by remember { mutableStateOf(service.isFavorite(id = quoteId, user = user)) } + + NavBar( index = index, navControllerFavorite = navFavorite, navControllerAccueil = navAccueil, @@ -86,17 +90,15 @@ fun QuotePage( Box( modifier = Modifier .fillMaxSize() - .background(colorBackground), + .background(MaterialTheme.colorScheme.background), contentAlignment = Alignment.Center ) { Column(modifier = Modifier .padding(15.dp) - .drawBehind { - drawRoundRect( - gradienBox, - cornerRadius = CornerRadius(15.dp.toPx()), - ) - } + .background( + color = MaterialTheme.colorScheme.primary, + shape = RoundedCornerShape(15.dp) + ) ) { Row(modifier = Modifier.padding(15.dp)) { ImageQuote( @@ -105,10 +107,7 @@ fun QuotePage( Column { FunctionalIcon( - // --/!\-- a modifier --/!\-- - // isFavorite = service.isFavorite(id) - // -------------------------- - false, + isFavorite = favorite, userId = index, id = quoteId, context = context, @@ -154,7 +153,7 @@ fun QuotePage( ), exit = slideOutVertically() + shrinkVertically() + fadeOut() ) { - Box(modifier = Modifier.fillMaxWidth().background(gradienBox).fillMaxSize()){ + Box(modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.primary).fillMaxSize()){ Column { AddComment(index, service) LstComment(service.getComment(quoteId)) @@ -173,7 +172,7 @@ fun QuoteText(text: String ){ modifier = Modifier.padding(start = 10.dp, top = 15.dp), fontWeight = FontWeight(1000), fontSize = 20.sp, - color = iconText + color = MaterialTheme.colorScheme.onPrimary ) } @@ -214,7 +213,7 @@ fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Contex Icon( Icons.Default.Share, contentDescription = stringResource(R.string.share), - tint = iconText, + tint = MaterialTheme.colorScheme.onPrimary, ) } IconButton( @@ -226,7 +225,7 @@ fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Contex Icon( Icons.Default.MailOutline, contentDescription = stringResource(R.string.comment), - tint = iconText, + tint = MaterialTheme.colorScheme.onPrimary, ) } @@ -238,7 +237,7 @@ fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Contex Icon( Icons.Default.Favorite, contentDescription = stringResource(R.string.favorite), - tint = likeIcon, + tint = MaterialTheme.colorScheme.onPrimary, ) } @@ -251,7 +250,7 @@ fun FunctionalIcon(isFavorite: Boolean, userId : Int, id : Int, context : Contex Icon( Icons.Default.FavoriteBorder, contentDescription = stringResource(R.string.favorite), - tint = iconText + tint = MaterialTheme.colorScheme.onPrimary ) } } @@ -265,22 +264,20 @@ fun InfoQuoteText(nameId : Int, text : String){ text = stringResource(id = nameId), fontSize = 18.sp, fontWeight = FontWeight(500), - color = iconText + color = MaterialTheme.colorScheme.onPrimary ) Text( text = text, - color = whiteBackcgroundText, + color = MaterialTheme.colorScheme.onBackground, fontSize = 16.sp, fontWeight = FontWeight(400), modifier = Modifier - .drawBehind { - drawRoundRect( - Color(255,255,255), - cornerRadius = CornerRadius(15.dp.toPx()) - ) - } - .padding(5.dp), + .background( + color = MaterialTheme.colorScheme.background, + shape = RoundedCornerShape(15.dp) + ) + .padding(5.dp) ) } } @@ -289,12 +286,12 @@ fun InfoQuoteText(nameId : Int, text : String){ fun LikeInfo(likes : Int){ Text( text = likes.toString(), - color = iconText + color = MaterialTheme.colorScheme.onPrimary ) Icon( Icons.Default.Favorite, contentDescription = stringResource(R.string.favorite), - tint = iconText, + tint = MaterialTheme.colorScheme.onPrimary, ) } @@ -308,19 +305,14 @@ fun AddComment(userId : Int, service: IServices){ Icon( Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(R.string.send), - tint = iconText + tint = MaterialTheme.colorScheme.onPrimary ) } TextField( value = text, onValueChange = { text = it }, label = { Text(stringResource(R.string.comment)) }, - modifier = Modifier.drawBehind { - drawRoundRect( - Color.White, - cornerRadius = CornerRadius(15.dp.toPx()) - ) - } + modifier = Modifier .width(300.dp) ) IconButton( @@ -329,7 +321,7 @@ fun AddComment(userId : Int, service: IServices){ Icon( Icons.AutoMirrored.Filled.Send, contentDescription = stringResource(R.string.send), - tint = iconText + tint = MaterialTheme.colorScheme.onPrimary ) } } @@ -346,12 +338,10 @@ fun LstComment(lst : List){ Column( modifier = Modifier.padding(5.dp) .fillMaxSize() - .drawBehind { - drawRoundRect( - Color.White, - cornerRadius = CornerRadius(15.dp.toPx()) - ) - } + .background( + color = MaterialTheme.colorScheme.onPrimary, + shape = RoundedCornerShape(15.dp) + ) ) { Row { AsyncImage( From 00d9b12f56d4073ab8c17fd91b2a5ef88fb16906 Mon Sep 17 00:00:00 2001 From: tomivt Date: Fri, 28 Mar 2025 09:29:51 +0100 Subject: [PATCH 8/9] feat: Add Random Quiz --- .../data/local/QuestionStub.kt | 4 + .../ui/navigations/AppNavigator.kt | 20 ++- .../ui/screens/QuizEndPage.kt | 11 +- .../what_the_fantasy/ui/screens/QuizMenu.kt | 74 +++++++- .../what_the_fantasy/ui/screens/QuizRandom.kt | 159 ++++++++++++++++++ 5 files changed, 259 insertions(+), 9 deletions(-) create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizRandom.kt diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuestionStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuestionStub.kt index 19833ec..317518c 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuestionStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuestionStub.kt @@ -97,4 +97,8 @@ object QuestionStub { val allQuestions: List = listOf( question1, question2, question3, question4, question5, question6, question7, question8, question9, question10 ) + + val allQuestionsShuffled: List = listOf( + question1, question2, question3, question4, question5, question6, question7, question8, question9, question10 + ).shuffled() } \ No newline at end of file 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 7af2928..1e50e85 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 @@ -37,6 +37,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 QuizRandom(val userIndex: Int) + @Serializable data class OneQuote(val quoteId: Int, val userIndex: Int) @@ -199,7 +202,8 @@ fun AppNavigator() { navSearch = { navController.navigate(Search(quizMenu.userIndex))}, navControllerQuiz = { idQuiz -> navController.navigate(Quiz(quizMenu.userIndex, idQuiz)) - } + }, + navControllerRandomQuiz = { navController.navigate(QuizRandom(quizMenu.userIndex)) } ) } composable { @@ -228,6 +232,20 @@ fun AppNavigator() { navSearch = { navController.navigate(Search(quizEnd.userIndex))} ) } + + composable { + val quizRandom: QuizRandom = it.toRoute() + QuizRandom( + navAccueil = { navController.navigate(Accueil(quizRandom.userIndex)) }, + navFavorite = { navController.navigate(Favorite(quizRandom.userIndex)) }, + navProfil = { navController.navigate(Profil(quizRandom.userIndex)) }, + navQuiz = { navController.navigate(QuizMenu(quizRandom.userIndex)) }, + navSearch = { navController.navigate(Search(quizRandom.userIndex)) }, + navControllerQuizEnd = { idQuiz, pts -> + navController.navigate(QuizEnd(quizRandom.userIndex, idQuiz, pts)) + }, + ) + } } } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt index 6b4bcf9..cbd6c6d 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset +import androidx.compose.material3.MaterialTheme import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle @@ -15,6 +16,7 @@ import androidx.compose.ui.text.font.FontWeight 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.data.local.QuestionStub import com.example.what_the_fantasy.data.local.QuizStub import com.example.what_the_fantasy.ui.components.NavBar @@ -65,16 +67,16 @@ fun QuizEndPage( Spacer(modifier = Modifier.height(16.dp)) Column( modifier = Modifier - .background(brush = gradient, shape = RoundedCornerShape(20.dp)) + .background(color = MaterialTheme.colorScheme.onPrimary, shape = RoundedCornerShape(20.dp)) .padding(30.dp) .fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.SpaceEvenly ) { - val quiz = QuizStub.getQuizById(idQuiz) - val nbQuestions = quiz?.questions?.size + val quizName = if (idQuiz == -1) "Random Quiz" else QuizStub.getQuizById(idQuiz)?.name ?: "Quiz Inconnu" + Text( - text = "${quiz?.name}", + text = quizName, color = Color.White, style = TextStyle( fontSize = 25.sp, @@ -82,6 +84,7 @@ fun QuizEndPage( textAlign = TextAlign.Center ) ) + val nbQuestions = QuestionStub.allQuestionsShuffled.size Text( text = "Nombres de Questions : $nbQuestions", color = Color.White, diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt index 1131b43..5fb37bf 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt @@ -3,6 +3,7 @@ package com.example.what_the_fantasy.ui.screens import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -12,6 +13,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll @@ -38,7 +40,8 @@ fun QuizMenu( navAccueil: () -> Unit, navProfil:() -> Unit, navSearch: () -> Unit, - navControllerQuiz: (Int) -> Unit + navControllerQuiz: (Int) -> Unit, + navControllerRandomQuiz:() -> Unit ) { NavBar(onQuiz = true, navControllerFavorite = navFavorite, @@ -47,13 +50,16 @@ fun QuizMenu( navControllerSearch = navSearch ) { - Column( - modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background) + Row( + modifier = Modifier + .fillMaxSize() + .background(MaterialTheme.colorScheme.background) + .horizontalScroll(state = rememberScrollState()) ) { // Contenu princiapl Column( modifier = Modifier - .weight(0.9f) + .width(400.dp) .fillMaxSize() .padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally @@ -119,6 +125,66 @@ fun QuizMenu( } } } + + Column( + modifier = Modifier + .width(400.dp) + .fillMaxSize() + .padding(20.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = "▶ Mini-Jeux ◀", + color = MaterialTheme.colorScheme.onBackground, + style = TextStyle( + fontSize = 25.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + Spacer(Modifier.height(20.dp)) + Column( + modifier = Modifier + .background(MaterialTheme.colorScheme.onPrimary, shape = RoundedCornerShape(20.dp)) + .fillMaxSize() + .padding(vertical = 30.dp) + .verticalScroll(rememberScrollState()), + horizontalAlignment = Alignment.CenterHorizontally + ) { + val context = LocalContext.current + val imageResId = context.resources.getIdentifier( + "quiz", + "drawable", + context.packageName + ) + Column( + modifier = Modifier + .size(width = 150.dp, height = 145.dp) + .clickable { navControllerRandomQuiz() }, + ) { + Image( + painter = painterResource(id = imageResId), + contentDescription = "Random Quiz", + modifier = Modifier + .size(width = 150.dp, height = 100.dp) + .clip(shape = RoundedCornerShape(20.dp)), + contentScale = ContentScale.Crop + ) + Spacer(Modifier.height(10.dp)) + Text( + text = "Random Quiz", + style = TextStyle( + fontSize = 17.sp, + fontWeight = FontWeight.Medium, + textAlign = TextAlign.Center, + color = MaterialTheme.colorScheme.primary + ) + ) + } + } + } } + + } } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizRandom.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizRandom.kt new file mode 100644 index 0000000..b038774 --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizRandom.kt @@ -0,0 +1,159 @@ +package com.example.what_the_fantasy.ui.screens + +import android.util.Log +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +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.data.local.QuestionStub +import com.example.what_the_fantasy.ui.components.NavBar + +@Composable +fun QuizRandom( + navFavorite: () -> Unit, + navAccueil: () -> Unit, + navProfil:() -> Unit, + navQuiz: () -> Unit, + navSearch: () -> Unit, + navControllerQuizEnd: (Int, Int) -> Unit, +) { + val questions = QuestionStub.allQuestionsShuffled + var idCurrentQuestion by remember { mutableIntStateOf(0) } + var pts by remember { mutableIntStateOf(0) } + var lifes by remember { mutableIntStateOf(3) } + + val gradient = Brush.linearGradient( + colors = listOf(MaterialTheme.colorScheme.onPrimary, MaterialTheme.colorScheme.onPrimary), + start = Offset(0f, 1000f), + end = Offset(1000f, 0f) + ) + + fun onAnswerSelected(answer: String) { + val currentQuestion = questions[idCurrentQuestion] + val correctAnswer = mapOf( + "A" to currentQuestion.ansA, + "B" to currentQuestion.ansB, + "C" to currentQuestion.ansC, + "D" to currentQuestion.ansD + )[currentQuestion.correctAns] + + if (answer == correctAnswer) pts++ + else { + lifes -= 1 + Log.d("Quiz Debug", "Lifes -1 :, $lifes") + } + if (idCurrentQuestion < questions.size - 1 && lifes > 0) idCurrentQuestion++ + else { + navControllerQuizEnd(-1, pts) + Log.d("Quiz Debug", "Game over lifes : $lifes") + } // Retour menu + } + NavBar( + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = navQuiz, + navControllerSearch = navSearch + ){ + Column ( + modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) + ) { + // Contenu princiapl + Column( + modifier = Modifier + .weight(0.8f) + .fillMaxWidth() + .padding(horizontal = 50.dp, vertical = 20.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + val question = questions[idCurrentQuestion] + + Column( + horizontalAlignment = Alignment.CenterHorizontally, + ) { + if (questions != null) { + Text( + text = "▶ Random Quiz ◀", + color = Color.White, + style = TextStyle( + fontSize = 20.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + } + Spacer(Modifier.height(20.dp)) + Column( + modifier = Modifier + .background(brush = gradient, shape = RoundedCornerShape(20.dp)) + .height(800.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + "Question ${idCurrentQuestion + 1}", + color = Color.White, + fontSize = 18.sp, + modifier = Modifier + .padding(top = 20.dp) + .weight(0.1f), + style = TextStyle( + fontSize = 25.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + Text( + question.question, + color = Color.White, + fontSize = 15.sp, + modifier = Modifier + .padding(horizontal = 25.dp) + .weight(0.1f), + textAlign = TextAlign.Center + ) + Column( + modifier = Modifier + .weight(0.7f) + .fillMaxHeight() + .padding(vertical = 30.dp), + verticalArrangement = Arrangement.SpaceBetween + + ) { + listOf( + question.ansA, + question.ansB, + question.ansC, + question.ansD + ).forEach { answer -> + Box( + modifier = Modifier + .width(220.dp) + .height(50.dp) + .background(Color.White, shape = RoundedCornerShape(16.dp)) + .clickable { onAnswerSelected(answer) } + .padding(horizontal = 8.dp), + contentAlignment = Alignment.Center + ) { + Text(answer, color = Color.Black, fontSize = 18.sp) + } + } + } + } + } + } + } + } +} \ No newline at end of file From aa7505f05daccfb31eae78b71b089d98d23645d6 Mon Sep 17 00:00:00 2001 From: tomivt Date: Fri, 28 Mar 2025 09:37:54 +0100 Subject: [PATCH 9/9] feat: Quick fix on QuizRandom --- .../com/example/what_the_fantasy/data/local/QuestionStub.kt | 4 +--- .../com/example/what_the_fantasy/ui/screens/QuizEndPage.kt | 2 +- .../com/example/what_the_fantasy/ui/screens/QuizRandom.kt | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuestionStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuestionStub.kt index 317518c..b786637 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuestionStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuestionStub.kt @@ -98,7 +98,5 @@ object QuestionStub { question1, question2, question3, question4, question5, question6, question7, question8, question9, question10 ) - val allQuestionsShuffled: List = listOf( - question1, question2, question3, question4, question5, question6, question7, question8, question9, question10 - ).shuffled() + val shuffleRandomQuestions: List = allQuestions.shuffled().take(10) } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt index cbd6c6d..74ffee1 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizEndPage.kt @@ -84,7 +84,7 @@ fun QuizEndPage( textAlign = TextAlign.Center ) ) - val nbQuestions = QuestionStub.allQuestionsShuffled.size + val nbQuestions = 10 Text( text = "Nombres de Questions : $nbQuestions", color = Color.White, diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizRandom.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizRandom.kt index b038774..e13b60b 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizRandom.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizRandom.kt @@ -30,7 +30,7 @@ fun QuizRandom( navSearch: () -> Unit, navControllerQuizEnd: (Int, Int) -> Unit, ) { - val questions = QuestionStub.allQuestionsShuffled + val questions = QuestionStub.shuffleRandomQuestions var idCurrentQuestion by remember { mutableIntStateOf(0) } var pts by remember { mutableIntStateOf(0) } var lifes by remember { mutableIntStateOf(3) }