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.compose.setContent
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.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() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -24,9 +13,7 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()
setContent {
What_The_FantasyTheme {
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.LoginPage
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.QuotePage
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
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 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 Search : Destination("Search")
data object SignUp : Destination("SignUp")
@ -47,12 +54,33 @@ fun AppNavigator() {
}
composable(Destination.Accueil.route) { AccueilPage() }
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) {
// Récupère l'index passé dans la route
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
ProfilPage(index = userIndex, navController = navController, services)
}
composable(Destination.Quiz.route) { QuizPage(navController) }
composable(Destination.Quote.route) { QuotePage() }
composable(Destination.Search.route) { SearchPage() }
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.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
@ -31,10 +32,8 @@ val gradient = Brush.linearGradient(
end = Offset(1000f, 0f)
)
@Composable
fun QuizEndPage(points: Int, idQuiz: Int) {
fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
Column(
modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B))
) {
@ -48,9 +47,6 @@ fun QuizEndPage(points: Int, idQuiz: Int) {
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
IconButton(onClick = { }) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White)
}
Image(
painter = painterResource(id = R.drawable.quiz),
contentDescription = "Profil",
@ -58,8 +54,7 @@ fun QuizEndPage(points: Int, idQuiz: Int) {
)
Image(
painter = painterResource(id = R.drawable.quiz),
contentDescription = "Profil",
modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape)
contentDescription = "Profil"
)
}
@ -122,8 +117,7 @@ fun QuizEndPage(points: Int, idQuiz: Int) {
// Bouton Quiz Suivant
Image(
painter = painterResource(id = R.drawable.quiz),
contentDescription = "Profil",
modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape)
contentDescription = "Profil"
)
}
@ -148,9 +142,9 @@ fun QuizEndPage(points: Int, idQuiz: Int) {
)
// Bouton WhatTheFantasy
Image(
painter = painterResource(id = R.drawable.quiz),
contentDescription = "Bouton",
modifier = Modifier.size(50.dp).background(Color.Yellow, CircleShape)
painter = painterResource(R.drawable.wf_logo),
contentDescription = "Menu Button",
Modifier.clickable { navControllerQuizMenu() }
)
// Bouton Quiz
Image(

@ -19,15 +19,11 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
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
@Composable
fun QuizAccueil(navController: NavController) {
fun QuizMenu(navControllerQuiz: () -> Unit) {
Row(
modifier = Modifier
.fillMaxSize()
@ -47,7 +43,7 @@ fun QuizAccueil(navController: NavController) {
.size(width = 150.dp, height = 100.dp)
.padding(8.dp)
.clickable {
navController.navigate("quizPage")
navControllerQuiz()
}
) {
Image(
@ -63,8 +59,7 @@ fun QuizAccueil(navController: NavController) {
.size(width = 150.dp, height = 100.dp)
.padding(8.dp)
.clickable {
navController.navigate("quizPage")
navControllerQuiz()
}
) {
Image(
@ -89,7 +84,7 @@ fun QuizAccueil(navController: NavController) {
.size(width = 150.dp, height = 100.dp)
.padding(8.dp)
.clickable {
navController.navigate("quizPage")
navControllerQuiz()
}
) {
Image(
@ -105,7 +100,7 @@ fun QuizAccueil(navController: NavController) {
.size(width = 150.dp, height = 100.dp)
.padding(8.dp)
.clickable {
navController.navigate("quizPage")
navControllerQuiz()
}
) {
Image(
@ -120,20 +115,3 @@ fun QuizAccueil(navController: NavController) {
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
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
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.runtime.*
import androidx.compose.ui.Alignment
@ -16,13 +13,20 @@ 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.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.sp
import androidx.navigation.NavController
import com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.local.QuestionStub
@Composable
fun QuizPage(navController: NavController) {
fun QuizPage(
navControllerQuizEnd: (Int, Int) -> Unit,
navControllerQuizMenu: () -> Unit
) {
val questions = QuestionStub.allQuestions
var idCurrentQuestion by remember { mutableIntStateOf(0) }
var pts by remember { mutableIntStateOf(0) }
@ -44,59 +48,126 @@ fun QuizPage(navController: NavController) {
if (answer == correctAnswer) pts++
if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++
else navController.popBackStack() // Retour menu
else navControllerQuizEnd(0, pts) // Retour menu
}
Box(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFF100C1B))
.padding(16.dp)
Column (
modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B))
) {
// Bandeau supérieur
Row(
modifier = Modifier
.fillMaxWidth()
.weight(0.1f)
//.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(
modifier = Modifier
.fillMaxSize(),
.weight(0.8f)
.fillMaxWidth()
.padding(horizontal = 50.dp, vertical = 20.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
val question = questions[idCurrentQuestion]
Column (
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Box(
modifier = Modifier.fillMaxWidth()
Text(
text = "▶ Quiz ◀",
color = Color.White,
style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
)
Column (
modifier = Modifier
.background(brush = gradient, shape = RoundedCornerShape(20.dp)),
horizontalAlignment = Alignment.CenterHorizontally
) {
IconButton(
onClick = { navController.popBackStack() },
modifier = Modifier.align(Alignment.TopStart)
) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White)
}
}
Text("Question ${question.id}", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 20.dp))
Text("Points : $pts", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 40.dp))
Text(question.question, color = Color.White, fontSize = 22.sp, modifier = Modifier.padding(40.dp))
}
Column (
modifier = Modifier
.padding(top = 30.dp)
) {
listOf(question.ansA, question.ansB, question.ansC, question.ansD).forEach { answer ->
Box(
Text(
"Question ${question.id}",
color = Color.White,
fontSize = 18.sp,
modifier = Modifier.padding(top = 20.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(
modifier = Modifier
.width(220.dp)
.height(50.dp)
.background(brush = gradient, shape = RoundedCornerShape(16.dp))
.clickable { onAnswerSelected(answer) }
.padding(horizontal = 8.dp),
contentAlignment = Alignment.Center
.padding(top = 30.dp)
) {
Text(answer, color = Color.White, fontSize = 18.sp)
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)
}
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