Modification style commentaires + pagination recherche + petits détails de couleurs par ci par la ☝🤓

nettoyage
Maxime ROCHER 3 weeks ago
parent 49a1c367ca
commit 7b251c8b1b

@ -37,7 +37,6 @@ fun AccueilPage(
services: IServices services: IServices
) { ) {
var itemCount by remember { mutableStateOf(15) }
val dailyQuote = DailyQuoteStub.dailyQuote val dailyQuote = DailyQuoteStub.dailyQuote
val user = services.getUserById(index) ?: return val user = services.getUserById(index) ?: return

@ -71,8 +71,6 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni
} }
@Composable @Composable
fun IdentifiantTextField(textIdentifiantResId : Int) : String{ fun IdentifiantTextField(textIdentifiantResId : Int) : String{
val textIdentifiant = stringResource(id = textIdentifiantResId) val textIdentifiant = stringResource(id = textIdentifiantResId)

@ -76,7 +76,7 @@ fun QuizMenu(
Spacer(Modifier.height(20.dp)) Spacer(Modifier.height(20.dp))
Column( Column(
modifier = Modifier modifier = Modifier
.background(MaterialTheme.colorScheme.onPrimary, shape = RoundedCornerShape(20.dp)) .background(MaterialTheme.colorScheme.primary, shape = RoundedCornerShape(20.dp))
.fillMaxSize() .fillMaxSize()
.padding(vertical = 30.dp) .padding(vertical = 30.dp)
.verticalScroll(rememberScrollState()), .verticalScroll(rememberScrollState()),
@ -115,7 +115,7 @@ fun QuizMenu(
fontSize = 17.sp, fontSize = 17.sp,
fontWeight = FontWeight.Medium, fontWeight = FontWeight.Medium,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.primary color = MaterialTheme.colorScheme.onPrimary
) )
) )
} }

@ -30,11 +30,13 @@ import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.FavoriteBorder import androidx.compose.material.icons.filled.FavoriteBorder
import androidx.compose.material.icons.filled.MailOutline import androidx.compose.material.icons.filled.MailOutline
import androidx.compose.material.icons.filled.Share import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -297,14 +299,20 @@ fun LikeInfo(likes : Int){
} }
@Composable @Composable
fun AddComment(userId : Int, service: IServices){ fun AddComment(userId: Int, service: IServices) {
var text by remember { mutableStateOf("") } 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( IconButton(
onClick = { isCommentVisible = !isCommentVisible}, onClick = { isCommentVisible = !isCommentVisible }
){ ) {
Icon( Icon(
Icons.AutoMirrored.Filled.ArrowBack, imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = stringResource(R.string.send), contentDescription = stringResource(R.string.send),
tint = MaterialTheme.colorScheme.onPrimary tint = MaterialTheme.colorScheme.onPrimary
) )
@ -314,37 +322,50 @@ fun AddComment(userId : Int, service: IServices){
onValueChange = { text = it }, onValueChange = { text = it },
label = { Text(stringResource(R.string.comment)) }, label = { Text(stringResource(R.string.comment)) },
modifier = Modifier 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( IconButton(
onClick = { service.AddComment(text)}, //send comment onClick = { isCommentVisible = !isCommentVisible }
){ ) {
Icon( Icon(
Icons.AutoMirrored.Filled.Send, imageVector = Icons.AutoMirrored.Filled.Send,
contentDescription = stringResource(R.string.send), contentDescription = "Retour",
tint = MaterialTheme.colorScheme.onPrimary tint = MaterialTheme.colorScheme.primary
) )
} }
} }
)
}
} }
@Composable @Composable
fun LstComment(lst : List<Comment>){ fun LstComment(lst: List<Comment>) {
LazyColumn( LazyColumn(
verticalArrangement = Arrangement.spacedBy(4.dp), verticalArrangement = Arrangement.spacedBy(8.dp),
) { modifier = Modifier.padding(10.dp)
items(
items = lst,
) { ) {
items(lst) {
Column( Column(
modifier = Modifier.padding(5.dp) modifier = Modifier
.fillMaxSize() .fillMaxWidth()
.background( .background(
color = MaterialTheme.colorScheme.onPrimary, color = MaterialTheme.colorScheme.onPrimary,
shape = RoundedCornerShape(15.dp) shape = RoundedCornerShape(15.dp)
) )
.padding(12.dp)
) { ) {
Row { Row(verticalAlignment = Alignment.CenterVertically) {
AsyncImage( AsyncImage(
model = it.img, model = it.img,
contentDescription = stringResource(R.string.profilePict), contentDescription = stringResource(R.string.profilePict),
@ -353,18 +374,22 @@ fun LstComment(lst : List<Comment>){
.clip(RoundedCornerShape(50)) .clip(RoundedCornerShape(50))
) )
Text( Text(
text = it.user + " " + it.date, text = "${it.user}${it.date}",
modifier = Modifier.padding(start = 15.dp) color = MaterialTheme.colorScheme.onBackground,
modifier = Modifier.padding(start = 12.dp),
fontWeight = FontWeight.Bold,
fontSize = 14.sp
) )
} }
Row {
Text( Text(
text = it.content, text = it.content,
modifier = Modifier.padding(15.dp), color = MaterialTheme.colorScheme.onBackground,
modifier = Modifier.padding(top = 10.dp, start = 8.dp, end = 8.dp),
fontSize = 14.sp
) )
} }
} }
} }
}
} }

@ -2,101 +2,83 @@ package com.example.what_the_fantasy.ui.screens
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.*
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.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.selection.selectable import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Search import androidx.compose.material.icons.rounded.Search
import androidx.compose.material3.Button import androidx.compose.material3.*
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.*
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.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.motionEventSpy
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardType 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.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.R import com.example.what_the_fantasy.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.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.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.NavBar
import com.example.what_the_fantasy.ui.components.QuoteLittle import com.example.what_the_fantasy.ui.components.QuoteLittle
import com.example.what_the_fantasy.ui.theme.colorBackground import kotlinx.coroutines.delay
import com.example.what_the_fantasy.ui.theme.colorNavBar
@Composable @Composable
fun SearchPage( fun SearchPage(
navFavorite: () -> Unit, navFavorite: () -> Unit,
navAccueil: () -> Unit, navAccueil: () -> Unit,
navProfil:() -> Unit, navProfil: () -> Unit,
navQuiz: () -> Unit, navQuiz: () -> Unit,
navQuote: (Int) -> Unit, navQuote: (Int) -> Unit,
navSearch: (String,String) -> Unit, navSearch: (String, String) -> Unit,
services: IServices, services: IServices,
type: String,
type : String, search: String
search:String ) {
) {
var itemCount by remember { mutableStateOf(15) }
val quotes = services.search(type,search,itemCount)
var newSearch by remember { mutableStateOf(search) } var newSearch by remember { mutableStateOf(search) }
val filtre = listOf("contenue","personnage","titre") val filtre = listOf("contenue", "personnage", "titre")
val (newFiltre, onFiltreSelected) = remember { mutableStateOf(type) } val (newFiltre, onFiltreSelected) = remember { mutableStateOf(type) }
val page = remember { mutableStateOf(1) }
val quotes = remember { mutableStateListOf<Quote>() }
val isLoading = remember { mutableStateOf(false) }
val state = rememberLazyListState()
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( NavBar(
onAccueil = true, onAccueil = true,
navControllerFavorite = navFavorite, navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil, navControllerAccueil = navAccueil,
navControllerProfil = navProfil, navControllerProfil = navProfil,
navControllerQuiz = navQuiz, navControllerQuiz = navQuiz,
navControllerSearch = {navSearch("contenue","")} navControllerSearch = { navSearch("contenue", "") }
) { ) {
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(MaterialTheme.colorScheme.background) .background(MaterialTheme.colorScheme.background)
) { ) {
Text( Text(
text = ""+stringResource(R.string.TitleSearch)+"", text = "" + stringResource(R.string.TitleSearch) + "",
color = MaterialTheme.colorScheme.onBackground, color = MaterialTheme.colorScheme.onBackground,
fontSize = 24.sp, fontSize = 24.sp,
modifier = Modifier modifier = Modifier
@ -104,8 +86,7 @@ fun SearchPage(
.padding(16.dp), .padding(16.dp),
textAlign = TextAlign.Center textAlign = TextAlign.Center
) )
Column (horizontalAlignment = Alignment.CenterHorizontally Column(horizontalAlignment = Alignment.CenterHorizontally) {
){
OutlinedTextField( OutlinedTextField(
value = newSearch, value = newSearch,
onValueChange = { newSearch = it }, onValueChange = { newSearch = it },
@ -116,41 +97,43 @@ fun SearchPage(
.height(50.dp), .height(50.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
maxLines = 1, maxLines = 1,
shape = CircleShape, // Bords arrondis shape = CircleShape,
trailingIcon = { trailingIcon = {
IconButton(onClick = { navSearch(newFiltre, newSearch) } , IconButton(
onClick = { navSearch(newFiltre, newSearch) },
modifier = Modifier modifier = Modifier
.size(50.dp) .size(50.dp)
.clip(CircleShape) .clip(CircleShape)
) { ) {
Icon(Icons.Rounded.Search, Icon(
Icons.Rounded.Search,
contentDescription = stringResource(R.string.TitleSearch), contentDescription = stringResource(R.string.TitleSearch),
Modifier Modifier
.fillMaxSize() .fillMaxSize()
.background(MaterialTheme.colorScheme.primary,CircleShape) .background(MaterialTheme.colorScheme.primary, CircleShape)
) )
} }
} }
) )
Row(horizontalArrangement = Arrangement.SpaceAround) { Row(horizontalArrangement = Arrangement.SpaceAround) {
filtre.forEach{ type -> filtre.forEach { typeItem ->
Row( Row(
Modifier Modifier
.height(56.dp) .height(56.dp)
.selectable( .selectable(
selected = (type == newFiltre), selected = (typeItem == newFiltre),
onClick = { onFiltreSelected(type) }, onClick = { onFiltreSelected(typeItem) },
role = Role.RadioButton role = Role.RadioButton
) )
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
RadioButton( RadioButton(
selected = (type == newFiltre), selected = (typeItem == newFiltre),
onClick = null // null recommended for accessibility with screen readers onClick = null
) )
Text( Text(
text = type, text = typeItem,
style = MaterialTheme.typography.bodyLarge, style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(start = 16.dp), modifier = Modifier.padding(start = 16.dp),
color = MaterialTheme.colorScheme.onBackground color = MaterialTheme.colorScheme.onBackground
@ -159,17 +142,19 @@ fun SearchPage(
} }
} }
} }
LazyColumn(modifier = Modifier.weight(1f)) { LazyColumn(
items(quotes) { quote -> modifier = Modifier.weight(1f),
Column(Modifier.clickable {navQuote(quote.id)} state = state
) { ) {
items(quotes) { quote ->
Column(Modifier.clickable { navQuote(quote.id) }) {
QuoteLittle(quote) QuoteLittle(quote)
} }
} }
if (itemCount < quotes.size) {
item { item {
LaunchedEffect(itemCount) { if (state.layoutInfo.visibleItemsInfo.lastOrNull()?.index == quotes.size - 1 && !isLoading.value) {
itemCount += 15 LaunchedEffect(Unit) {
page.value++
} }
Box( Box(
modifier = Modifier modifier = Modifier

Loading…
Cancel
Save