Merge QuizPage2 into master

pull/24/head^2
tomivt 2 months ago
commit e8c720977d

@ -4,19 +4,8 @@ import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import com.example.what_the_fantasy.ui.navigations.AppNavigator import com.example.what_the_fantasy.ui.navigations.AppNavigator
import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme
import com.example.what_the_fantasy.ui.screens.LoginPage
import com.example.what_the_fantasy.ui.screens.ProfilPage
import com.example.what_the_fantasy.ui.screens.QuizPage
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -24,9 +13,7 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge() enableEdgeToEdge()
setContent { setContent {
What_The_FantasyTheme { What_The_FantasyTheme {
AppNavigator() AppNavigator()
//QuizPage()
} }
} }
} }

@ -9,6 +9,8 @@ import com.example.what_the_fantasy.ui.screens.AccueilPage
import com.example.what_the_fantasy.ui.screens.FavoritePage import com.example.what_the_fantasy.ui.screens.FavoritePage
import com.example.what_the_fantasy.ui.screens.LoginPage import com.example.what_the_fantasy.ui.screens.LoginPage
import com.example.what_the_fantasy.ui.screens.ProfilPage import com.example.what_the_fantasy.ui.screens.ProfilPage
import com.example.what_the_fantasy.ui.screens.QuizEndPage
import com.example.what_the_fantasy.ui.screens.QuizMenu
import com.example.what_the_fantasy.ui.screens.QuizPage import com.example.what_the_fantasy.ui.screens.QuizPage
import com.example.what_the_fantasy.ui.screens.QuotePage import com.example.what_the_fantasy.ui.screens.QuotePage
import com.example.what_the_fantasy.ui.screens.SearchPage import com.example.what_the_fantasy.ui.screens.SearchPage
@ -24,7 +26,12 @@ sealed class Destination(val route: String) {
data object Profil : Destination("Profil/{userIndex}") { // Ajout du paramètre userIndex data object Profil : Destination("Profil/{userIndex}") { // Ajout du paramètre userIndex
fun createRoute(userIndex: Int) = "Profil/$userIndex" // Fonction pour créer la route avec l'index fun createRoute(userIndex: Int) = "Profil/$userIndex" // Fonction pour créer la route avec l'index
} }
data object QuizMenu : Destination("QuizMenu")
data object Quiz : Destination("Quiz") data object Quiz : Destination("Quiz")
data object QuizEnd : Destination("QuizEnd/{idQuiz}/{pts}") {
// Ajout paramètres idQuiz et pts
fun createIdAndPts(idQuiz : Int, pts : Int) = "QuizEnd/$idQuiz/$pts"
}
data object Quote : Destination("Quote") data object Quote : Destination("Quote")
data object Search : Destination("Search") data object Search : Destination("Search")
data object SignUp : Destination("SignUp") data object SignUp : Destination("SignUp")
@ -47,12 +54,33 @@ fun AppNavigator() {
} }
composable(Destination.Accueil.route) { AccueilPage() } composable(Destination.Accueil.route) { AccueilPage() }
composable(Destination.Favorite.route) { FavoritePage() } composable(Destination.Favorite.route) { FavoritePage() }
composable(Destination.QuizMenu.route) {
QuizMenu(
navControllerQuiz = { navController.navigate(Destination.Quiz.route) }
)
}
composable(Destination.Quiz.route) {
QuizPage(
navControllerQuizEnd = { idQuiz, pts ->
navController.navigate(Destination.QuizEnd.createIdAndPts(idQuiz, pts))
},
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) }
)
}
composable(Destination.QuizEnd.route) { backStackEntry ->
val idQuiz = backStackEntry.arguments?.getString("idQuiz")?.toInt() ?: 0
val pts = backStackEntry.arguments?.getString("pts")?.toInt() ?: 0
QuizEndPage(
idQuiz,
pts,
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) }
)
}
composable(Destination.Profil.route) { composable(Destination.Profil.route) {
// Récupère l'index passé dans la route // Récupère l'index passé dans la route
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
ProfilPage(index = userIndex, navController = navController, services) ProfilPage(index = userIndex, navController = navController, services)
} }
composable(Destination.Quiz.route) { QuizPage(navController) }
composable(Destination.Quote.route) { QuotePage() } composable(Destination.Quote.route) { QuotePage() }
composable(Destination.Search.route) { SearchPage() } composable(Destination.Search.route) { SearchPage() }
composable(Destination.SignUp.route) { SignUpPage(navController, services) } composable(Destination.SignUp.route) { SignUpPage(navController, services) }

@ -2,6 +2,7 @@ package com.example.what_the_fantasy.ui.screens
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
@ -31,10 +32,8 @@ val gradient = Brush.linearGradient(
end = Offset(1000f, 0f) end = Offset(1000f, 0f)
) )
@Composable @Composable
fun QuizEndPage(points: Int, idQuiz: Int) { fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
Column( Column(
modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B))
) { ) {
@ -48,9 +47,6 @@ fun QuizEndPage(points: Int, idQuiz: Int) {
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
IconButton(onClick = { }) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White)
}
Image( Image(
painter = painterResource(id = R.drawable.quiz), painter = painterResource(id = R.drawable.quiz),
contentDescription = "Profil", contentDescription = "Profil",
@ -58,8 +54,7 @@ fun QuizEndPage(points: Int, idQuiz: Int) {
) )
Image( Image(
painter = painterResource(id = R.drawable.quiz), painter = painterResource(id = R.drawable.quiz),
contentDescription = "Profil", contentDescription = "Profil"
modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape)
) )
} }
@ -122,8 +117,7 @@ fun QuizEndPage(points: Int, idQuiz: Int) {
// Bouton Quiz Suivant // Bouton Quiz Suivant
Image( Image(
painter = painterResource(id = R.drawable.quiz), painter = painterResource(id = R.drawable.quiz),
contentDescription = "Profil", contentDescription = "Profil"
modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape)
) )
} }
@ -148,9 +142,9 @@ fun QuizEndPage(points: Int, idQuiz: Int) {
) )
// Bouton WhatTheFantasy // Bouton WhatTheFantasy
Image( Image(
painter = painterResource(id = R.drawable.quiz), painter = painterResource(R.drawable.wf_logo),
contentDescription = "Bouton", contentDescription = "Menu Button",
modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape) Modifier.clickable { navControllerQuizMenu() }
) )
// Bouton Quiz // Bouton Quiz
Image( Image(

@ -19,15 +19,11 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.what_the_fantasy.R import com.example.what_the_fantasy.R
@Composable @Composable
fun QuizAccueil(navController: NavController) { fun QuizMenu(navControllerQuiz: () -> Unit) {
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -47,7 +43,7 @@ fun QuizAccueil(navController: NavController) {
.size(width = 150.dp, height = 100.dp) .size(width = 150.dp, height = 100.dp)
.padding(8.dp) .padding(8.dp)
.clickable { .clickable {
navController.navigate("quizPage") navControllerQuiz()
} }
) { ) {
Image( Image(
@ -63,8 +59,7 @@ fun QuizAccueil(navController: NavController) {
.size(width = 150.dp, height = 100.dp) .size(width = 150.dp, height = 100.dp)
.padding(8.dp) .padding(8.dp)
.clickable { .clickable {
navControllerQuiz()
navController.navigate("quizPage")
} }
) { ) {
Image( Image(
@ -89,7 +84,7 @@ fun QuizAccueil(navController: NavController) {
.size(width = 150.dp, height = 100.dp) .size(width = 150.dp, height = 100.dp)
.padding(8.dp) .padding(8.dp)
.clickable { .clickable {
navController.navigate("quizPage") navControllerQuiz()
} }
) { ) {
Image( Image(
@ -105,7 +100,7 @@ fun QuizAccueil(navController: NavController) {
.size(width = 150.dp, height = 100.dp) .size(width = 150.dp, height = 100.dp)
.padding(8.dp) .padding(8.dp)
.clickable { .clickable {
navController.navigate("quizPage") navControllerQuiz()
} }
) { ) {
Image( Image(
@ -120,20 +115,3 @@ fun QuizAccueil(navController: NavController) {
Spacer(modifier = Modifier.weight(0.1f)) Spacer(modifier = Modifier.weight(0.1f))
} }
} }
@Composable
fun QuizApp() {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "quizEndPage") {
composable("quizAccueil") {
QuizAccueil(navController = navController)
}
composable("quizPage") {
QuizPage(navController = navController)
}
composable("quizEndPage") {
QuizEndPage(5, 1)
}
}
}

@ -1,14 +1,11 @@
package com.example.what_the_fantasy.ui.screens package com.example.what_the_fantasy.ui.screens
import androidx.compose.foundation.Image
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.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -16,13 +13,20 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.navigation.NavController import com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.local.QuestionStub
@Composable @Composable
fun QuizPage(navController: NavController) { fun QuizPage(
navControllerQuizEnd: (Int, Int) -> Unit,
navControllerQuizMenu: () -> Unit
) {
val questions = QuestionStub.allQuestions val questions = QuestionStub.allQuestions
var idCurrentQuestion by remember { mutableIntStateOf(0) } var idCurrentQuestion by remember { mutableIntStateOf(0) }
var pts by remember { mutableIntStateOf(0) } var pts by remember { mutableIntStateOf(0) }
@ -44,18 +48,38 @@ fun QuizPage(navController: NavController) {
if (answer == correctAnswer) pts++ if (answer == correctAnswer) pts++
if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++ if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++
else navController.popBackStack() // Retour menu else navControllerQuizEnd(0, pts) // Retour menu
} }
Box( Column (
modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B))
) {
// Bandeau supérieur
Row(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxWidth()
.background(Color(0xFF100C1B)) .weight(0.1f)
.padding(16.dp) //.background(Color(0xFF300052))
.padding(20.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) { ) {
Image(
painter = painterResource(id = R.drawable.profile_icon),
contentDescription = "Profil"
)
Image(
painter = painterResource(id = R.drawable.toggle),
contentDescription = "Profil"
)
}
// Contenu princiapl
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize(), .weight(0.8f)
.fillMaxWidth()
.padding(horizontal = 50.dp, vertical = 20.dp),
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
val question = questions[idCurrentQuestion] val question = questions[idCurrentQuestion]
@ -63,40 +87,87 @@ fun QuizPage(navController: NavController) {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
Box( Text(
modifier = Modifier.fillMaxWidth() text = "▶ Quiz ◀",
) { color = Color.White,
IconButton( style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
onClick = { navController.popBackStack() }, )
modifier = Modifier.align(Alignment.TopStart) Column (
modifier = Modifier
.background(brush = gradient, shape = RoundedCornerShape(20.dp)),
horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White) Text(
} "Question ${question.id}",
} color = Color.White,
Text("Question ${question.id}", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 20.dp)) fontSize = 18.sp,
Text("Points : $pts", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 40.dp)) modifier = Modifier.padding(top = 20.dp),
Text(question.question, color = Color.White, fontSize = 22.sp, modifier = Modifier.padding(40.dp)) style = TextStyle(
} fontSize = 25.sp,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center
)
)
Text(
question.question,
color = Color.White,
fontSize = 22.sp,
modifier = Modifier.padding(40.dp)
)
Column( Column(
modifier = Modifier modifier = Modifier
.padding(top = 30.dp) .padding(top = 30.dp)
) { ) {
listOf(question.ansA, question.ansB, question.ansC, question.ansD).forEach { answer -> listOf(
question.ansA,
question.ansB,
question.ansC,
question.ansD
).forEach { answer ->
Box( Box(
modifier = Modifier modifier = Modifier
.width(220.dp) .width(220.dp)
.height(50.dp) .height(50.dp)
.background(brush = gradient, shape = RoundedCornerShape(16.dp)) .background(Color.White, shape = RoundedCornerShape(16.dp))
.clickable { onAnswerSelected(answer) } .clickable { onAnswerSelected(answer) }
.padding(horizontal = 8.dp), .padding(horizontal = 8.dp),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
Text(answer, color = Color.White, fontSize = 18.sp) Text(answer, color = Color.Black, fontSize = 18.sp)
} }
Spacer(modifier = Modifier.height(60.dp)) Spacer(modifier = Modifier.height(60.dp))
} }
} }
}
}
}
// Bandeau inférieur
Row(
modifier = Modifier
.fillMaxWidth()
.weight(0.1f)
.background(Color(0xFF300052))
.padding(20.dp),
horizontalArrangement = Arrangement.SpaceAround,
verticalAlignment = Alignment.CenterVertically
) {
// Bouton Likes
Image(
painter = painterResource(id = R.drawable.like_icon),
contentDescription = "Bouton"
)
// Bouton WhatTheFantasy
Image(
painter = painterResource(R.drawable.wf_logo),
contentDescription = "Menu Button",
Modifier.clickable { navControllerQuizMenu() }
)
// Bouton Quiz
Image(
painter = painterResource(id = R.drawable.quiz_icon),
contentDescription = "Bouton"
)
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Loading…
Cancel
Save