From 2f57ac9d826d221058ac5ef2b54b1f5b7b678458 Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Fri, 7 Mar 2025 12:01:15 +0100 Subject: [PATCH 01/11] 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 02/11] 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 03/11] =?UTF-8?q?ajout=20des=20methode(pas=20encore=20impl?= =?UTF-8?q?ementer)=20n=C3=A9c=C3=A9saire=20pour=20la=20fin=20de=20la=20pa?= =?UTF-8?q?ge=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 04/11] 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 05/11] 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 06/11] =?UTF-8?q?fin=20page=20quote=20(l=C3=A9g=C3=A8re=20?= =?UTF-8?q?modif=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 07/11] =?UTF-8?q?modif=20quote=20pour=20coh=C3=A9rence=20a?= =?UTF-8?q?vec=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 08/11] 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 09/11] 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) } From 15af4bf0b5a07f93a3e06b12ac6d87243eb9aae5 Mon Sep 17 00:00:00 2001 From: "maxime.rocher" Date: Fri, 28 Mar 2025 10:16:50 +0100 Subject: [PATCH 10/11] =?UTF-8?q?modifications=20n=C3=A9cessaires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../what_the_fantasy/data/local/QuoteStub.kt | 47 ++++++++++++- .../data/services/IServices.kt | 1 + .../data/services/ServicesStub.kt | 9 +++ .../ui/screens/AccueilPage.kt | 67 ++++++++++++++----- 4 files changed, 105 insertions(+), 19 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt index 36e2909..2282ce9 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/QuoteStub.kt @@ -7,7 +7,7 @@ import com.example.what_the_fantasy.data.model.SrcType object QuoteStub { val quotes: MutableList = mutableListOf( - Quote(1,"All we have to decide is what to do with the time that is given us.",466,SrcLanguage.vo,CharacterStub.gandalf.name,"The Lord of the Rings: The Fellowship of the Ring",CharacterStub.gandalf.imgUrl,SrcType.Movie,2000), + Quote(1, "All we have to decide is what to do with the time that is given us.", 466, SrcLanguage.vo, CharacterStub.gandalf.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), Quote(2, "A wizard is never late, nor is he early, he arrives precisely when he means to.", 467, SrcLanguage.vo, CharacterStub.gandalf.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), Quote(3, "Even the smallest person can change the course of the future.", 466, SrcLanguage.vo, CharacterStub.galadriel.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.galadriel.imgUrl, SrcType.Movie, 2000), Quote(4, "I would rather share one lifetime with you than face all the ages of this world alone.", 120, SrcLanguage.vo, CharacterStub.arwen.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.arwen.imgUrl, SrcType.Movie, 2000), @@ -26,6 +26,47 @@ object QuoteStub { Quote(17, "Le courage n'est pas l'absence de peur, mais la capacité de vaincre ce qui fait peur.", 300, SrcLanguage.vf, CharacterStub.boromir.name, "Nelson Mandela", CharacterStub.boromir.imgUrl, SrcType.Movie, 2000), Quote(18, "La folie, c'est de faire toujours la même chose et de s'attendre à un résultat différent.", 400, SrcLanguage.vf, CharacterStub.eowyn.name, "Albert Einstein", CharacterStub.eowyn.imgUrl, SrcType.Movie, 2000), Quote(19, "Le bonheur n'est pas quelque chose de tout fait. Il vient de vos propres actions.", 500, SrcLanguage.vo, CharacterStub.saruman.name, "Dalaï Lama", CharacterStub.saruman.imgUrl, SrcType.Movie, 2000), - Quote(20, "La vie est un mystère qu'il faut vivre, et non un problème à résoudre.", 600, SrcLanguage.vo, CharacterStub.samwiseGamgee.name, "Gandhi", CharacterStub.samwiseGamgee.imgUrl, SrcType.Movie, 2000) + Quote(20, "La vie est un mystère qu'il faut vivre, et non un problème à résoudre.", 600, SrcLanguage.vo, CharacterStub.samwiseGamgee.name, "Gandhi", CharacterStub.samwiseGamgee.imgUrl, SrcType.Movie, 2000), + Quote(21, "All we have to decide is what to do with the time that is given us.", 466, SrcLanguage.vf, CharacterStub.gandalf.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), + Quote(22, "A wizard is never late, nor is he early, he arrives precisely when he means to.", 467, SrcLanguage.vf, CharacterStub.gandalf.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), + Quote(23, "Even the smallest person can change the course of the future.", 466, SrcLanguage.vf, CharacterStub.galadriel.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.galadriel.imgUrl, SrcType.Movie, 2000), + Quote(24, "I would rather share one lifetime with you than face all the ages of this world alone.", 120, SrcLanguage.vf, CharacterStub.arwen.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.arwen.imgUrl, SrcType.Movie, 2000), + Quote(25, "Faithless is he that says farewell when the road darkens.", 150, SrcLanguage.vf, CharacterStub.gimli.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.gimli.imgUrl, SrcType.Movie, 2000), + Quote(26, "It's a dangerous business, Frodo, going out your door. You step onto the road, and if you don't keep your feet, there's no knowing where you might be swept off to.", 200, SrcLanguage.vf, CharacterStub.frodoBaggins.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.frodoBaggins.imgUrl, SrcType.Movie, 2000), + Quote(27, "I am no man.", 300, SrcLanguage.vf, CharacterStub.eowyn.name, "The Lord of the Rings: The Return of the King", CharacterStub.eowyn.imgUrl, SrcType.Movie, 2000), + Quote(28, "The world is changed. I feel it in the water. I feel it in the earth. I smell it in the air.", 400, SrcLanguage.vf, CharacterStub.treebeard.name, "The Lord of the Rings: The Two Towers", CharacterStub.treebeard.imgUrl, SrcType.Movie, 2000), + Quote(29, "We wants it, we needs it. Must have the precious.", 500, SrcLanguage.vf, CharacterStub.gollum.name, "The Lord of the Rings: The Two Towers", CharacterStub.gollum.imgUrl, SrcType.Movie, 2000), + Quote(30, "The board is set, the pieces are moving. We come to it at last, the great battle of our time.", 600, SrcLanguage.vf, CharacterStub.gandalf.name, "The Lord of the Rings: The Return of the King", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), + Quote(31, "Un grand pouvoir implique de grandes responsabilités.", 466, SrcLanguage.vo, CharacterStub.aragorn.name, "Spider-Man", CharacterStub.aragorn.imgUrl, SrcType.Series, 2000), + Quote(32, "Que la Force soit avec toi.", 467, SrcLanguage.vo, CharacterStub.legolas.name, "Star Wars", CharacterStub.legolas.imgUrl, SrcType.Movie, 2000), + Quote(33, "La magie est partout. Il suffit de savoir où la trouver.", 466, SrcLanguage.vo, CharacterStub.gandalf.name, "Harry Potter", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), + Quote(34, "Le monde est plein de choses magiques, patientant que nos sens s'aiguisent.", 120, SrcLanguage.vo, CharacterStub.frodoBaggins.name, "Le Seigneur des Anneaux", CharacterStub.frodoBaggins.imgUrl, SrcType.Movie, 2000), + Quote(35, "La peur mène à la colère, la colère mène à la haine, la haine mène à la souffrance.", 150, SrcLanguage.vo, CharacterStub.gimli.name, "Star Wars", CharacterStub.gimli.imgUrl, SrcType.Movie, 2000), + Quote(36, "La vie est une aventure audacieuse ou rien du tout.", 200, SrcLanguage.vo, CharacterStub.galadriel.name, "Helen Keller", CharacterStub.galadriel.imgUrl, SrcType.Movie, 2000), + Quote(37, "Le courage n'est pas l'absence de peur, mais la capacité de vaincre ce qui fait peur.", 300, SrcLanguage.vo, CharacterStub.boromir.name, "Nelson Mandela", CharacterStub.boromir.imgUrl, SrcType.Movie, 2000), + Quote(38, "La folie, c'est de faire toujours la même chose et de s'attendre à un résultat différent.", 400, SrcLanguage.vo, CharacterStub.eowyn.name, "Albert Einstein", CharacterStub.eowyn.imgUrl, SrcType.Movie, 2000), + Quote(39, "Le bonheur n'est pas quelque chose de tout fait. Il vient de vos propres actions.", 500, SrcLanguage.vf, CharacterStub.saruman.name, "Dalaï Lama", CharacterStub.saruman.imgUrl, SrcType.Movie, 2000), + Quote(40, "La vie est un mystère qu'il faut vivre, et non un problème à résoudre.", 600, SrcLanguage.vf, CharacterStub.samwiseGamgee.name, "Gandhi", CharacterStub.samwiseGamgee.imgUrl, SrcType.Movie, 2000), + Quote(41, "All we have to decide is what to do with the time that is given us.", 466, SrcLanguage.vo, CharacterStub.gandalf.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), + Quote(42, "A wizard is never late, nor is he early, he arrives precisely when he means to.", 467, SrcLanguage.vo, CharacterStub.gandalf.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), + Quote(43, "Even the smallest person can change the course of the future.", 466, SrcLanguage.vo, CharacterStub.galadriel.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.galadriel.imgUrl, SrcType.Movie, 2000), + Quote(44, "I would rather share one lifetime with you than face all the ages of this world alone.", 120, SrcLanguage.vo, CharacterStub.arwen.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.arwen.imgUrl, SrcType.Movie, 2000), + Quote(45, "Faithless is he that says farewell when the road darkens.", 150, SrcLanguage.vo, CharacterStub.gimli.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.gimli.imgUrl, SrcType.Movie, 2000), + Quote(46, "It's a dangerous business, Frodo, going out your door. You step onto the road, and if you don't keep your feet, there's no knowing where you might be swept off to.", 200, SrcLanguage.vo, CharacterStub.frodoBaggins.name, "The Lord of the Rings: The Fellowship of the Ring", CharacterStub.frodoBaggins.imgUrl, SrcType.Movie, 2000), + Quote(47, "I am no man.", 300, SrcLanguage.vo, CharacterStub.eowyn.name, "The Lord of the Rings: The Return of the King", CharacterStub.eowyn.imgUrl, SrcType.Movie, 2000), + Quote(48, "The world is changed. I feel it in the water. I feel it in the earth. I smell it in the air.", 400, SrcLanguage.vo, CharacterStub.treebeard.name, "The Lord of the Rings: The Two Towers", CharacterStub.treebeard.imgUrl, SrcType.Movie, 2000), + Quote(49, "We wants it, we needs it. Must have the precious.", 500, SrcLanguage.vo, CharacterStub.gollum.name, "The Lord of the Rings: The Two Towers", CharacterStub.gollum.imgUrl, SrcType.Movie, 2000), + Quote(50, "The board is set, the pieces are moving. We come to it at last, the great battle of our time.", 600, SrcLanguage.vo, CharacterStub.gandalf.name, "The Lord of the Rings: The Return of the King", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), + Quote(51, "Un grand pouvoir implique de grandes responsabilités.", 466, SrcLanguage.vf, CharacterStub.aragorn.name, "Spider-Man", CharacterStub.aragorn.imgUrl, SrcType.Series, 2000), + Quote(52, "Que la Force soit avec toi.", 467, SrcLanguage.vf, CharacterStub.legolas.name, "Star Wars", CharacterStub.legolas.imgUrl, SrcType.Movie, 2000), + Quote(53, "La magie est partout. Il suffit de savoir où la trouver.", 466, SrcLanguage.vf, CharacterStub.gandalf.name, "Harry Potter", CharacterStub.gandalf.imgUrl, SrcType.Movie, 2000), + Quote(54, "Le monde est plein de choses magiques, patientant que nos sens s'aiguisent.", 120, SrcLanguage.vf, CharacterStub.frodoBaggins.name, "Le Seigneur des Anneaux", CharacterStub.frodoBaggins.imgUrl, SrcType.Movie, 2000), + Quote(55, "La peur mène à la colère, la colère mène à la haine, la haine mène à la souffrance.", 150, SrcLanguage.vf, CharacterStub.gimli.name, "Star Wars", CharacterStub.gimli.imgUrl, SrcType.Movie, 2000), + Quote(56, "La vie est une aventure audacieuse ou rien du tout.", 200, SrcLanguage.vf, CharacterStub.galadriel.name, "Helen Keller", CharacterStub.galadriel.imgUrl, SrcType.Movie, 2000), + Quote(57, "Le courage n'est pas l'absence de peur, mais la capacité de vaincre ce qui fait peur.", 300, SrcLanguage.vf, CharacterStub.boromir.name, "Nelson Mandela", CharacterStub.boromir.imgUrl, SrcType.Movie, 2000), + Quote(58, "La folie, c'est de faire toujours la même chose et de s'attendre à un résultat différent.", 400, SrcLanguage.vf, CharacterStub.eowyn.name, "Albert Einstein", CharacterStub.eowyn.imgUrl, SrcType.Movie, 2000), + Quote(59, "Le bonheur n'est pas quelque chose de tout fait. Il vient de vos propres actions.", 500, SrcLanguage.vo, CharacterStub.saruman.name, "Dalaï Lama", CharacterStub.saruman.imgUrl, SrcType.Movie, 2000), + Quote(60, "La vie est un mystère qu'il faut vivre, et non un problème à résoudre.", 600, SrcLanguage.vo, CharacterStub.samwiseGamgee.name, "Gandhi", CharacterStub.samwiseGamgee.imgUrl, SrcType.Movie, 2000) ) -} \ 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 afa5cd6..6804fbc 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 @@ -24,4 +24,5 @@ interface IServices { fun isFavorite(id : Int): Boolean fun getAllFavorite(): List fun getAllQuote(): List + fun getSomeQuotes(nb: Int, page: Int) : MutableList } \ 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 7e8eab0..1b5e0b7 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 @@ -103,6 +103,15 @@ class ServicesStub : IServices { return (quotes.find { it.id == id+1 }) } + override fun getSomeQuotes(nb: Int, page: Int): MutableList { + val fromIndex = (page - 1) * nb + val toIndex = minOf(page * nb, quotes.size) + + if (fromIndex >= quotes.size) return mutableListOf() + + return quotes.subList(fromIndex, toIndex).toMutableList() + } + override fun isFavorite(id: Int): Boolean { TODO("Not yet implemented") } 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 6161a81..f2c1d71 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 @@ -5,6 +5,7 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -18,10 +19,12 @@ 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.model.Quote import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.QuoteLittle import com.example.what_the_fantasy.ui.theme.colorBackground +import kotlinx.coroutines.delay @Composable fun AccueilPage( @@ -31,15 +34,41 @@ fun AccueilPage( navProfil: (Int) -> Unit, navQuote: (Int) -> Unit, services: IServices - ) { - var itemCount by remember { mutableStateOf(15) } val dailyQuote = DailyQuoteStub.dailyQuote - val quotes = services.getAllQuote().take(itemCount) val user = services.getUserById(index) ?: return val titleDalyQuote = stringResource(R.string.TitleHomeDailyQuote) val titleSuggestion = stringResource(R.string.TitleHomeSuggestion) + + val page = remember { mutableStateOf(1) } + val quotes = remember { mutableStateListOf() } + val state = rememberLazyListState() + val layoutInfo = state.layoutInfo + val isLoading = remember { mutableStateOf(false) } + val visibleItemsInfo = layoutInfo.visibleItemsInfo + val fullyVisibleItemsInfo = visibleItemsInfo.toMutableList() + val lastItem = if (fullyVisibleItemsInfo.isNotEmpty()) fullyVisibleItemsInfo.last() else null + + + LaunchedEffect(page.value) { + if (!isLoading.value) { + isLoading.value = true + delay(500) + val newQuotes = services.getSomeQuotes(15, page.value) + val uniqueQuotes = newQuotes.filterNot { new -> quotes.any { it.id == new.id } } + + if (uniqueQuotes.isNotEmpty()) { + quotes.addAll(uniqueQuotes) + } else { + println("Aucune nouvelle quote à la page ${page.value}, stop pagination.") + } + isLoading.value = false + } + } + + + NavBar( onAccueil = true, index = index, @@ -53,9 +82,9 @@ fun AccueilPage( .fillMaxSize() .background(MaterialTheme.colorScheme.background) ) { - LazyColumn(modifier = Modifier.weight(1f)) { - item{ - Column { + LazyColumn(modifier = Modifier.weight(1f), state = state) { + item { + Column(Modifier.clickable { navQuote(dailyQuote.id - 1) }) { Text( text = titleDalyQuote, color = MaterialTheme.colorScheme.onBackground, @@ -65,9 +94,9 @@ fun AccueilPage( .padding(16.dp), textAlign = TextAlign.Center ) - QuoteLittle(dailyQuote) } + Text( text = titleSuggestion, color = MaterialTheme.colorScheme.onBackground, @@ -78,21 +107,18 @@ fun AccueilPage( textAlign = TextAlign.Center ) } - items(quotes) { quote -> - Column(Modifier.clickable {navQuote(quote.id)} - ) { - if(quote.language == user.langage){ + items(quotes) { quote -> + if (quote.language == user.langage) { + Column(Modifier.clickable { navQuote(quote.id - 1) }) { QuoteLittle(quote) Spacer(modifier = Modifier.height(16.dp)) } } } - if (itemCount < quotes.size) { - item { - LaunchedEffect(itemCount) { - itemCount += 15 - } + + item { + if (lastItem?.index == quotes.size) { Box( modifier = Modifier .fillMaxWidth() @@ -101,6 +127,15 @@ fun AccueilPage( ) { CircularProgressIndicator() } + } else { + LaunchedEffect(state.firstVisibleItemIndex, state.layoutInfo.totalItemsCount) { + if (!isLoading.value && state.layoutInfo.visibleItemsInfo.isNotEmpty()) { + val lastVisibleItem = state.layoutInfo.visibleItemsInfo.last() + if (lastVisibleItem.index >= state.layoutInfo.totalItemsCount - 1) { + page.value++ + } + } + } } } } From 7b251c8b1b02c9ae0272161e7dc9934732acae9e Mon Sep 17 00:00:00 2001 From: "maxime.rocher" Date: Fri, 28 Mar 2025 11:31:48 +0100 Subject: [PATCH 11/11] =?UTF-8?q?Modification=20style=20commentaires=20+?= =?UTF-8?q?=20pagination=20recherche=20+=20petits=20d=C3=A9tails=20de=20co?= =?UTF-8?q?uleurs=20par=20ci=20par=20la=20=E2=98=9D=F0=9F=A4=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/screens/AccueilPage.kt | 1 - .../what_the_fantasy/ui/screens/LoginPage.kt | 2 - .../what_the_fantasy/ui/screens/QuizMenu.kt | 4 +- .../what_the_fantasy/ui/screens/QuotePage.kt | 91 ++++++++----- .../what_the_fantasy/ui/screens/SearchPage.kt | 125 ++++++++---------- 5 files changed, 115 insertions(+), 108 deletions(-) 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 7053bbd..ad0d1af 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 @@ -37,7 +37,6 @@ fun AccueilPage( services: IServices ) { - var itemCount by remember { mutableStateOf(15) } val dailyQuote = DailyQuoteStub.dailyQuote val user = services.getUserById(index) ?: return 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 c185d7c..a98a4f8 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 @@ -71,8 +71,6 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni } - - @Composable fun IdentifiantTextField(textIdentifiantResId : Int) : String{ val textIdentifiant = stringResource(id = textIdentifiantResId) 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 5fb37bf..d67d8b8 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 @@ -76,7 +76,7 @@ fun QuizMenu( Spacer(Modifier.height(20.dp)) Column( modifier = Modifier - .background(MaterialTheme.colorScheme.onPrimary, shape = RoundedCornerShape(20.dp)) + .background(MaterialTheme.colorScheme.primary, shape = RoundedCornerShape(20.dp)) .fillMaxSize() .padding(vertical = 30.dp) .verticalScroll(rememberScrollState()), @@ -115,7 +115,7 @@ fun QuizMenu( fontSize = 17.sp, fontWeight = FontWeight.Medium, textAlign = TextAlign.Center, - color = MaterialTheme.colorScheme.primary + color = MaterialTheme.colorScheme.onPrimary ) ) } 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 c82842b..a3aa9da 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 @@ -30,11 +30,13 @@ import androidx.compose.material.icons.filled.Favorite import androidx.compose.material.icons.filled.FavoriteBorder import androidx.compose.material.icons.filled.MailOutline import androidx.compose.material.icons.filled.Share +import androidx.compose.material3.ExperimentalMaterial3Api 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.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -297,15 +299,21 @@ fun LikeInfo(likes : Int){ } @Composable -fun AddComment(userId : Int, service: IServices){ +fun AddComment(userId: Int, service: IServices) { var text by remember { mutableStateOf("") } - Row(modifier = Modifier.padding(bottom = 15.dp, top = 15.dp)){ + + Row( + modifier = Modifier + .padding(15.dp) + .fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically + ) { IconButton( - onClick = { isCommentVisible = !isCommentVisible}, - ){ + onClick = { isCommentVisible = !isCommentVisible } + ) { Icon( - Icons.AutoMirrored.Filled.ArrowBack, - contentDescription = stringResource(R.string.send), + imageVector = Icons.AutoMirrored.Filled.ArrowBack, + contentDescription = stringResource(R.string.send), tint = MaterialTheme.colorScheme.onPrimary ) } @@ -314,37 +322,50 @@ fun AddComment(userId : Int, service: IServices){ onValueChange = { text = it }, label = { Text(stringResource(R.string.comment)) }, modifier = Modifier - .width(300.dp) + .weight(1f) + .padding(horizontal = 8.dp), + shape = RoundedCornerShape(20.dp), + colors = TextFieldDefaults.colors( + focusedContainerColor = MaterialTheme.colorScheme.onPrimary, + unfocusedContainerColor = MaterialTheme.colorScheme.onPrimary, + focusedIndicatorColor = Color.Transparent, + unfocusedIndicatorColor = Color.Transparent, + focusedLabelColor = MaterialTheme.colorScheme.primary, + unfocusedLabelColor = MaterialTheme.colorScheme.primary + ), + trailingIcon = { + IconButton( + onClick = { isCommentVisible = !isCommentVisible } + ) { + Icon( + imageVector = Icons.AutoMirrored.Filled.Send, + contentDescription = "Retour", + tint = MaterialTheme.colorScheme.primary + ) + } + } ) - IconButton( - onClick = { service.AddComment(text)}, //send comment - ){ - Icon( - Icons.AutoMirrored.Filled.Send, - contentDescription = stringResource(R.string.send), - tint = MaterialTheme.colorScheme.onPrimary - ) - } } } + @Composable -fun LstComment(lst : List){ +fun LstComment(lst: List) { LazyColumn( - verticalArrangement = Arrangement.spacedBy(4.dp), - ) { - items( - items = lst, - ) { + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = Modifier.padding(10.dp) + ) { + items(lst) { Column( - modifier = Modifier.padding(5.dp) - .fillMaxSize() + modifier = Modifier + .fillMaxWidth() .background( color = MaterialTheme.colorScheme.onPrimary, shape = RoundedCornerShape(15.dp) ) + .padding(12.dp) ) { - Row { + Row(verticalAlignment = Alignment.CenterVertically) { AsyncImage( model = it.img, contentDescription = stringResource(R.string.profilePict), @@ -353,18 +374,22 @@ fun LstComment(lst : List){ .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), + text = "${it.user} • ${it.date}", + color = MaterialTheme.colorScheme.onBackground, + modifier = Modifier.padding(start = 12.dp), + fontWeight = FontWeight.Bold, + fontSize = 14.sp ) } + Text( + text = it.content, + color = MaterialTheme.colorScheme.onBackground, + modifier = Modifier.padding(top = 10.dp, start = 8.dp, end = 8.dp), + fontSize = 14.sp + ) } } } } + 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 4dbc806..8c5f996 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,84 +2,67 @@ 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.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState 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 -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.material3.* +import androidx.compose.runtime.* 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.model.Quote 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 +import kotlinx.coroutines.delay @Composable fun SearchPage( navFavorite: () -> Unit, navAccueil: () -> Unit, - navProfil:() -> Unit, + navProfil: () -> Unit, navQuiz: () -> Unit, navQuote: (Int) -> Unit, - navSearch: (String,String) -> Unit, + navSearch: (String, String) -> Unit, services: IServices, + type: String, + search: String +) { + var newSearch by remember { mutableStateOf(search) } + val filtre = listOf("contenue", "personnage", "titre") + val (newFiltre, onFiltreSelected) = remember { mutableStateOf(type) } - type : String, - search:String - ) { - var itemCount by remember { mutableStateOf(15) } - val quotes = services.search(type,search,itemCount) + val page = remember { mutableStateOf(1) } + val quotes = remember { mutableStateListOf() } + val isLoading = remember { mutableStateOf(false) } + val state = rememberLazyListState() - var newSearch by remember { mutableStateOf(search) } - val filtre = listOf("contenue","personnage","titre") - val (newFiltre, onFiltreSelected) = remember { mutableStateOf(type) } + LaunchedEffect(page.value, type, search) { + if (!isLoading.value) { + isLoading.value = true + delay(500) + val newQuotes = services.search(type, search, page.value * 15) + val uniqueQuotes = newQuotes.filterNot { new -> quotes.any { it.id == new.id } } + if (uniqueQuotes.isNotEmpty()) { + quotes.addAll(uniqueQuotes) + } + isLoading.value = false + } + } NavBar( onAccueil = true, @@ -87,16 +70,15 @@ fun SearchPage( navControllerAccueil = navAccueil, navControllerProfil = navProfil, navControllerQuiz = navQuiz, - navControllerSearch = {navSearch("contenue","")} + navControllerSearch = { navSearch("contenue", "") } ) { Column( modifier = Modifier .fillMaxSize() .background(MaterialTheme.colorScheme.background) ) { - Text( - text = "▶ "+stringResource(R.string.TitleSearch)+" ◀", + text = "▶ " + stringResource(R.string.TitleSearch) + " ◀", color = MaterialTheme.colorScheme.onBackground, fontSize = 24.sp, modifier = Modifier @@ -104,8 +86,7 @@ fun SearchPage( .padding(16.dp), textAlign = TextAlign.Center ) - Column (horizontalAlignment = Alignment.CenterHorizontally - ){ + Column(horizontalAlignment = Alignment.CenterHorizontally) { OutlinedTextField( value = newSearch, onValueChange = { newSearch = it }, @@ -116,41 +97,43 @@ fun SearchPage( .height(50.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), maxLines = 1, - shape = CircleShape, // Bords arrondis + shape = CircleShape, trailingIcon = { - IconButton(onClick = { navSearch(newFiltre, newSearch) } , + IconButton( + onClick = { navSearch(newFiltre, newSearch) }, modifier = Modifier .size(50.dp) .clip(CircleShape) ) { - Icon(Icons.Rounded.Search, + Icon( + Icons.Rounded.Search, contentDescription = stringResource(R.string.TitleSearch), Modifier .fillMaxSize() - .background(MaterialTheme.colorScheme.primary,CircleShape) + .background(MaterialTheme.colorScheme.primary, CircleShape) ) } } ) Row(horizontalArrangement = Arrangement.SpaceAround) { - filtre.forEach{ type -> + filtre.forEach { typeItem -> Row( Modifier .height(56.dp) .selectable( - selected = (type == newFiltre), - onClick = { onFiltreSelected(type) }, + selected = (typeItem == newFiltre), + onClick = { onFiltreSelected(typeItem) }, role = Role.RadioButton ) .padding(horizontal = 16.dp), verticalAlignment = Alignment.CenterVertically ) { RadioButton( - selected = (type == newFiltre), - onClick = null // null recommended for accessibility with screen readers + selected = (typeItem == newFiltre), + onClick = null ) Text( - text = type, + text = typeItem, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.padding(start = 16.dp), color = MaterialTheme.colorScheme.onBackground @@ -159,17 +142,19 @@ fun SearchPage( } } } - LazyColumn(modifier = Modifier.weight(1f)) { + LazyColumn( + modifier = Modifier.weight(1f), + state = state + ) { items(quotes) { quote -> - Column(Modifier.clickable {navQuote(quote.id)} - ) { + Column(Modifier.clickable { navQuote(quote.id) }) { QuoteLittle(quote) } } - if (itemCount < quotes.size) { - item { - LaunchedEffect(itemCount) { - itemCount += 15 + item { + if (state.layoutInfo.visibleItemsInfo.lastOrNull()?.index == quotes.size - 1 && !isLoading.value) { + LaunchedEffect(Unit) { + page.value++ } Box( modifier = Modifier @@ -184,4 +169,4 @@ fun SearchPage( } } } -} \ No newline at end of file +}