Merge QuizUIUX into master

pull/37/head
tomivt 2 months ago
commit 62f6f6d5c3

@ -0,0 +1,126 @@
package com.example.what_the_fantasy.data.local
import com.example.what_the_fantasy.data.model.Quiz
object QuizStub {
val quiz1 = Quiz(
id = 1,
name = "Quiz Seigneur des Anneaux",
questions = listOf(
QuestionStub.question1,
QuestionStub.question4,
QuestionStub.question8,
QuestionStub.question9
),
img = "lotr"
)
val quiz2 = Quiz(
id = 2,
name = "Quiz Harry Potter",
questions = listOf(
QuestionStub.question2,
QuestionStub.question7,
QuestionStub.question10
),
img = "hp"
)
val quiz3 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val quiz4 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val quiz5 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val quiz6 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val quiz7 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val quiz8 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val quiz9 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val quiz10 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val quiz11 = Quiz(
id = 3,
name = "Quiz Divers Fantasy",
questions = listOf(
QuestionStub.question3,
QuestionStub.question5,
QuestionStub.question6
),
img = "quiz"
)
val allQuizzes: List<Quiz> = listOf(quiz1, quiz2, quiz3, quiz4, quiz5, quiz6, quiz7, quiz8, quiz9, quiz10, quiz11)
fun getQuizById(id: Int): Quiz? {
return allQuizzes.find { it.id == id }
}
}

@ -0,0 +1,8 @@
package com.example.what_the_fantasy.data.model
class Quiz (
val id : Int,
val name : String,
val questions : List<Question>,
val img : String
)

@ -18,6 +18,7 @@ import com.example.what_the_fantasy.ui.screens.SignUpPage
import com.example.what_the_fantasy.ui.screens.SubmitQuotePage
sealed class Destination(val route: String) {
data object Login : Destination("Login")
data object Accueil : Destination("Accueil/{userIndex}") { // Ajout du paramètre userIndex
@ -29,20 +30,21 @@ 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 Quote : Destination("Quote")
data object Search : Destination("Search")
data object SignUp : Destination("SignUp")
data object SubmitQuote : Destination("SubmitQuote")
data object QuizMenu : Destination("QuizMenu/{userIndex}") { // Ajout du paramètre userIndex
fun createRoute(userIndex: Int) = "QuizMenu/$userIndex" // Fonction pour créer la route avec l'index
}
data object Quiz : Destination("Quiz")
data object Quiz : Destination("Quiz/{idQuiz}") {
// Ajout paramètre idQuiz
fun createId(idQuiz : Int) = "Quiz/$idQuiz"
}
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")
data object SubmitQuote : Destination("SubmitQuote")
}
@Composable
@ -136,18 +138,23 @@ fun AppNavigator() {
navFavorite = { userIndex ->
navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil
},
navControllerQuiz = { navController.navigate(Destination.Quiz.route) },
navControllerQuiz = { id ->
navController.navigate(Destination.Quiz.createId(id))
},
navProfil = { userIndex ->
navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil
}
)
}
composable(Destination.Quiz.route) {
composable(Destination.Quiz.route) { backStackEntry ->
val idQuiz = backStackEntry.arguments?.getString("idQuiz")?.toInt() ?: 0
QuizPage(
navControllerQuizEnd = { idQuiz, pts ->
navController.navigate(Destination.QuizEnd.createIdAndPts(idQuiz, pts))
},
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) }
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) },
navControllerMenu = { navController.navigate(Destination.Accueil.route) },
idQuiz
)
}
composable(Destination.QuizEnd.route) { backStackEntry ->
@ -156,7 +163,8 @@ fun AppNavigator() {
QuizEndPage(
idQuiz,
pts,
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) }
navControllerQuizMenu = { navController.navigate(Destination.QuizMenu.route) },
navControllerMenu = { navController.navigate(Destination.Accueil.route) }
)
}
}

@ -33,29 +33,34 @@ val gradient = Brush.linearGradient(
)
@Composable
fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
fun QuizEndPage(
idQuiz: Int,
points: Int,
navControllerQuizMenu: () -> Unit,
navControllerMenu: () -> Unit
) {
Column(
modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B))
) {
// // Bandeau supérieur
// Row(
// modifier = Modifier
// .fillMaxWidth()
// .weight(0.1f)
// .padding(20.dp),
// horizontalArrangement = Arrangement.SpaceBetween,
// verticalAlignment = Alignment.CenterVertically
// ) {
// Image(
// painter = painterResource(id = R.drawable.profile_icon),
// contentDescription = "Profil",
// modifier = Modifier.size(50.dp)
// )
// Image(
// painter = painterResource(id = R.drawable.toggle),
// contentDescription = "Profil"
// )
// }
// Bandeau supérieur
Row(
modifier = Modifier
.fillMaxWidth()
.weight(0.1f)
.padding(20.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Image(
painter = painterResource(id = R.drawable.profile_icon),
contentDescription = "Profil",
modifier = Modifier.size(50.dp)
)
Image(
painter = painterResource(id = R.drawable.toggle),
contentDescription = "Profil"
)
}
// Contenu principal
Column(
@ -76,16 +81,16 @@ fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
.background(brush = gradient, shape = RoundedCornerShape(20.dp))
.padding(30.dp)
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceEvenly
) {
val quiz = QuizStub.getQuizById(idQuiz)
val nbQuestions = quiz?.questions?.size
Text (
text = "Quiz N°$idQuiz",
text = "${quiz?.name}",
color = Color.White,
style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
)
val nbQuestions = QuestionStub.allQuestions.size
Text (
text = "Nombres de Questions : $nbQuestions",
color = Color.White,
@ -96,37 +101,67 @@ fun QuizEndPage(idQuiz: Int, points: Int, navControllerQuizMenu: () -> Unit) {
color = Color.White,
style = TextStyle(fontSize = 15.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
)
val pourcentage = (points.toDouble() / nbQuestions!!) * 100
val note = when {
pourcentage == 100.0 -> "S"
pourcentage >= 70.0 -> "A"
pourcentage >= 40.0 -> "B"
else -> "C"
}
println("Note obtenue : $note")
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(100.dp)
.background(Color.White, shape = RoundedCornerShape(50.dp))
) {
Text(
text = note,
color = Color.Red,
style = TextStyle(
fontSize = 40.sp,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center
)
)
}
}
}
// // 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",
// modifier = Modifier.size(50.dp)
// )
// // 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",
// modifier = Modifier.size(50.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",
modifier = Modifier.size(50.dp)
)
// Bouton WhatTheFantasy
Image(
painter = painterResource(R.drawable.wf_logo),
contentDescription = "Menu Button",
Modifier.clickable { navControllerMenu() }
)
// Bouton Menu Quiz
Image(
painter = painterResource(id = R.drawable.quiz_icon),
contentDescription = "Bouton",
modifier = Modifier
.size(50.dp)
.clickable { navControllerQuizMenu() }
)
}
}
}
}

@ -2,132 +2,162 @@ package com.example.what_the_fantasy.ui.screens
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
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 com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.local.QuizStub
import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.ui.components.NavBar
@Composable
fun QuizMenu(
index: Int,
navFavorite: (Int) -> Unit,
navAccueil: (Int) -> Unit,
navProfil:(Int) -> Unit,
navControllerQuiz: () -> Unit
) {
NavBar(onQuiz = true,
index = index,
navControllerFavorite = navFavorite,
navControllerAccueil = navAccueil,
navControllerProfil = navProfil,
navControllerQuiz = { }
fun QuizMenu(navControllerQuiz: (Int) -> Unit) {
Column (
modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B))
) {
// Bandeau supérieur
Row(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFF100C1B))
.padding(top = 100.dp)
.fillMaxWidth()
.weight(0.1f)
//background(Color(0xFF300052))
.padding(20.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Spacer(modifier = Modifier.weight(0.1f))
Image(
painter = painterResource(id = R.drawable.profile_icon),
contentDescription = "Profil"
)
Image(
painter = painterResource(id = R.drawable.toggle),
contentDescription = "Profil"
)
}
// Contenu princiapl
Column(
modifier = Modifier
.weight(0.9f)
.fillMaxHeight(),
.fillMaxSize()
.padding(20.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
modifier = Modifier
.size(width = 150.dp, height = 100.dp)
.padding(8.dp)
.clickable {
navControllerQuiz()
}
) {
Image(
painter = painterResource(id = R.drawable.quiz),
contentDescription = "Quiz 1",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop
)
}
Box(
modifier = Modifier
.size(width = 150.dp, height = 100.dp)
.padding(8.dp)
.clickable {
navControllerQuiz()
}
) {
Image(
painter = painterResource(id = R.drawable.quiz),
contentDescription = "Quiz 2",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop
)
}
}
Spacer(modifier = Modifier.width(10.dp))
Column(
Text(
text = "▶ Menu des Quiz ◀",
color = Color.White,
style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
)
Spacer(Modifier.height(20.dp))
Column (
modifier = Modifier
.weight(0.9f)
.fillMaxHeight(),
.background(brush = gradient, shape = RoundedCornerShape(20.dp))
.fillMaxSize()
.padding(vertical = 30.dp)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
modifier = Modifier
.size(width = 150.dp, height = 100.dp)
.padding(8.dp)
.clickable {
navControllerQuiz()
}
) {
Image(
painter = painterResource(id = R.drawable.quiz),
contentDescription = "Quiz 3",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop
)
}
Box(
modifier = Modifier
.size(width = 150.dp, height = 100.dp)
.padding(8.dp)
.clickable {
navControllerQuiz()
val quizzes = QuizStub.allQuizzes.chunked(2)
val context = LocalContext.current
for (rowQuizzes in quizzes) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) {
for (quiz in rowQuizzes) {
val imageResId = context.resources.getIdentifier(
quiz.img,
"drawable",
context.packageName
)
Column (
modifier = Modifier
.size(width = 150.dp, height = 145.dp)
.clickable { navControllerQuiz(quiz.id) },
) {
Image(
painter = painterResource(id = imageResId),
contentDescription = quiz.name,
modifier = Modifier
.size(width = 150.dp, height = 100.dp)
.clip(shape = RoundedCornerShape(20.dp)),
contentScale = ContentScale.Crop
)
Spacer(Modifier.height(10.dp))
Text(
text = quiz.name,
style = TextStyle(
fontSize = 17.sp,
fontWeight = FontWeight.Medium,
textAlign = TextAlign.Center,
color = Color.White
)
)
}
}
) {
Image(
painter = painterResource(id = R.drawable.quiz),
contentDescription = "Quiz 4",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop
)
}
Spacer(Modifier.height(30.dp))
}
}
}
Spacer(modifier = Modifier.weight(0.1f))
// 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 { }
)
// Bouton Quiz
Image(
painter = painterResource(id = R.drawable.quiz_icon),
contentDescription = "Bouton"
)
}
}
}
}

@ -21,13 +21,17 @@ 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.QuestionStub
import com.example.what_the_fantasy.data.local.QuizStub
@Composable
fun QuizPage(
navControllerQuizEnd: (Int, Int) -> Unit,
navControllerQuizMenu: () -> Unit
) {
val questions = QuestionStub.allQuestions
navControllerQuizMenu: () -> Unit,
navControllerMenu: () -> Unit,
idQuiz: Int
) {
val quiz = QuizStub.getQuizById(idQuiz)
val questions = quiz?.questions ?: emptyList()
var idCurrentQuestion by remember { mutableIntStateOf(0) }
var pts by remember { mutableIntStateOf(0) }
@ -48,31 +52,31 @@ fun QuizPage(
if (answer == correctAnswer) pts++
if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++
else navControllerQuizEnd(0, pts) // Retour menu
else navControllerQuizEnd(idQuiz, pts) // Retour menu
}
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"
// )
// }
// 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(
@ -87,18 +91,21 @@ fun QuizPage(
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = "▶ Quiz ◀",
color = Color.White,
style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
)
if (quiz != null) {
Text(
text = "${quiz.name}",
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)),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
"Question ${question.id}",
"Question ${idCurrentQuestion+1}",
color = Color.White,
fontSize = 18.sp,
modifier = Modifier.padding(top = 20.dp),
@ -142,33 +149,33 @@ fun QuizPage(
}
}
// // 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"
// )
// }
// 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 { navControllerMenu() }
)
// Bouton Menu Quiz
Image(
painter = painterResource(id = R.drawable.quiz_icon),
contentDescription = "Bouton",
Modifier.clickable { navControllerQuizMenu() }
)
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 284 KiB

Loading…
Cancel
Save