From a4e874b8fc0349f9f6fd5f702c6443314fe9c7ff Mon Sep 17 00:00:00 2001 From: brongniart Date: Wed, 19 Mar 2025 14:47:55 +0100 Subject: [PATCH 1/2] 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 2/2] 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)) {