commit
49a1c367ca
@ -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<Comment> = 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"),
|
||||||
|
)
|
||||||
|
}
|
@ -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
|
||||||
|
)
|
@ -1,7 +1,10 @@
|
|||||||
package com.example.what_the_fantasy.data.model
|
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) {
|
enum class SrcType (val value: String) {
|
||||||
Movie("@string/movie"),
|
Movie("movie" ),
|
||||||
VideoGame("@string/videoGame"),
|
VideoGame("videoGame"),
|
||||||
Series("@string/series"),
|
Series("series"),
|
||||||
}
|
}
|
@ -1,64 +1,89 @@
|
|||||||
package com.example.what_the_fantasy.data.services
|
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.Favorite
|
import com.example.what_the_fantasy.data.model.Favorite
|
||||||
import com.example.what_the_fantasy.data.model.Quote
|
import com.example.what_the_fantasy.data.model.Quote
|
||||||
import com.example.what_the_fantasy.data.model.User
|
import com.example.what_the_fantasy.data.model.User
|
||||||
|
//import com.example.what_the_fantasy.ui.navigations.Destination
|
||||||
|
|
||||||
//class ServicesAPI : IServices {
|
class ServicesAPI : IServices {
|
||||||
// override fun EditUsername(username: String, index : Int) : Boolean {
|
override fun EditUsername(username: String, index : Int): Boolean {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun EditEmail(email: String, index : Int) : Boolean {
|
override fun EditEmail(email: String, index : Int): Boolean {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun EditPasswd(passwd: String, index : Int) {
|
override fun EditPasswd(passwd: String, index : Int) {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun EditImage(imageURL: String, index : Int) {
|
override fun EditImage(imageURL: String, index : Int) {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun ChangeLangage(user: User) {
|
override fun ChangeLangage(user: User) {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean {
|
override fun AddFav(userId: Int, QuoteId: Int) {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun SearchQuote(quote: String) {
|
override fun SupFav(userId: Int, QuoteId: Int) {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun getQuote(id: Int): Quote? {
|
override fun AddComment(content: String) {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun isFavorite(id: Int): Boolean {
|
override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun getAllFavorite(): List<Favorite> {
|
override fun getFavorite(user: User): List<Quote> {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
|
|
||||||
// override fun getAllQuote(): List<Quote> {
|
override fun SearchQuote(quote: String) {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun getFavorite(user: User): Favorite {
|
override fun getQuote(id: Int): Quote? {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun getAllUsers(): List<User> {
|
override fun isFavorite(id: Int, user: User): Boolean {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun getUserById(id: Int): User? {
|
override fun getAllFavorite(): List<Favorite> {
|
||||||
// TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//}
|
override fun getAllQuote(): List<Quote> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllUsers(): List<User> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getComment(quoteId: Int): List<Comment> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getUserById(id: Int): User? {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun search(type : String ,search:String ,indexCount: Int): List<Quote>{
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
@ -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.shuffleRandomQuestions
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,187 @@
|
|||||||
package com.example.what_the_fantasy.ui.screens
|
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.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.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.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
|
@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) }
|
||||||
|
val filtre = listOf("contenue","personnage","titre")
|
||||||
|
val (newFiltre, onFiltreSelected) = remember { mutableStateOf(type) }
|
||||||
|
|
||||||
|
NavBar(
|
||||||
|
onAccueil = true,
|
||||||
|
navControllerFavorite = navFavorite,
|
||||||
|
navControllerAccueil = navAccueil,
|
||||||
|
navControllerProfil = navProfil,
|
||||||
|
navControllerQuiz = navQuiz,
|
||||||
|
navControllerSearch = {navSearch("contenue","")}
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.background)
|
||||||
|
) {
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "▶ "+stringResource(R.string.TitleSearch)+" ◀",
|
||||||
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
|
fontSize = 24.sp,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
Column (horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
){
|
||||||
|
OutlinedTextField(
|
||||||
|
value = newSearch,
|
||||||
|
onValueChange = { newSearch = it },
|
||||||
|
textStyle = TextStyle(color = MaterialTheme.colorScheme.onBackground),
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(top = 2.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(50.dp),
|
||||||
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
|
||||||
|
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(MaterialTheme.colorScheme.primary,CircleShape)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
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 = MaterialTheme.colorScheme.onBackground
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LazyColumn(modifier = Modifier.weight(1f)) {
|
||||||
|
items(quotes) { quote ->
|
||||||
|
Column(Modifier.clickable {navQuote(quote.id)}
|
||||||
|
) {
|
||||||
|
QuoteLittle(quote)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (itemCount < quotes.size) {
|
||||||
|
item {
|
||||||
|
LaunchedEffect(itemCount) {
|
||||||
|
itemCount += 15
|
||||||
|
}
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue