From 7b251c8b1b02c9ae0272161e7dc9934732acae9e Mon Sep 17 00:00:00 2001 From: "maxime.rocher" Date: Fri, 28 Mar 2025 11:31:48 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20style=20commentaires=20+=20pagin?= =?UTF-8?q?ation=20recherche=20+=20petits=20d=C3=A9tails=20de=20couleurs?= =?UTF-8?q?=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 +}