parent
54f2e1741e
commit
a4e874b8fc
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue