diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/ErrorMessageComponent.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/ErrorMessageComponent.kt index 6498a73..e78f7f2 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/ErrorMessageComponent.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/ErrorMessageComponent.kt @@ -19,4 +19,15 @@ fun ErrorMessageProfileComponent(titleResId : Int) { fontSize = 12.sp, modifier = Modifier.padding(top = 4.dp) ) +} + +@Composable +fun ErrorMessageSubmitQuoteComponent(titleResId: Int) { + val textError = stringResource(id = titleResId) + Text( + text = textError, + color = Color.Red, + fontSize = 12.sp, + modifier = Modifier.padding(top = 4.dp) + ) } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt index 57b8e47..3603478 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt @@ -49,7 +49,14 @@ data object Search data object SignUp @Serializable -data object SubmitQuote +data class SubmitQuote(val userIndex: Int) + +@Serializable +data class RecapSubmit(val userIndex: Int, + val quoteContent : String, + val character : String, + val source : String) + @Composable fun AppNavigator() { @@ -80,7 +87,14 @@ fun AppNavigator() { navFavorite = { navController.navigate(Favorite(accueil.userIndex)) }, navQuiz = { navController.navigate(QuizMenu(accueil.userIndex)) }, navProfil = { navController.navigate(Profil(accueil.userIndex)) }, - navQuote = { quoteId -> navController.navigate(OneQuote(quoteId,accueil.userIndex)) }, + navQuote = { quoteId -> + navController.navigate( + OneQuote( + quoteId, + accueil.userIndex + ) + ) + }, services = services ) } @@ -91,7 +105,14 @@ fun AppNavigator() { navAccueil = { navController.navigate(Accueil(favorite.userIndex)) }, navQuiz = { navController.navigate(QuizMenu(favorite.userIndex)) }, navProfil = { navController.navigate(Profil(favorite.userIndex)) }, - navQuote = { quoteId -> navController.navigate(OneQuote(quoteId,favorite.userIndex)) }, + navQuote = { quoteId -> + navController.navigate( + OneQuote( + quoteId, + favorite.userIndex + ) + ) + }, services = services ) } @@ -133,7 +154,41 @@ fun AppNavigator() { services = services ) } - composable { SubmitQuotePage() } + composable { + val submitQuote: SubmitQuote = it.toRoute() + SubmitQuotePage( + index = submitQuote.userIndex, + navAccueil = { navController.navigate(Accueil(submitQuote.userIndex)) }, + navFavorite = { navController.navigate(Favorite(submitQuote.userIndex)) }, + navProfil = { navController.navigate(Profil(submitQuote.userIndex)) }, + navControllerQuiz = { idQuiz -> + navController.navigate(Quiz(submitQuote.userIndex, idQuiz)) + }, + navRecap = { quoteContent, character, source -> + navController.navigate( + RecapSubmit( + submitQuote.userIndex, + quoteContent, + character, + source + ) + ) + } + ) + } + composable { + val recapSubmit: RecapSubmit = it.toRoute() + RecapSubmitPage( + index = recapSubmit.userIndex, + quoteContent = recapSubmit.quoteContent, + character = recapSubmit.character, + source = recapSubmit.source, + navAccueil = { navController.navigate(Accueil(recapSubmit.userIndex)) }, + navFavorite = { navController.navigate(Favorite(recapSubmit.userIndex)) }, + navProfil = { navController.navigate(Profil(recapSubmit.userIndex)) } + ) + } + composable { val quizMenu: QuizMenu = it.toRoute() QuizMenu( @@ -176,3 +231,4 @@ fun AppNavigator() { } } } + diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt index 5764deb..5776311 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/QuizMenu.kt @@ -32,13 +32,13 @@ import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.data.local.QuizStub import com.example.what_the_fantasy.ui.components.NavBar - @Composable -fun QuizMenu( index: Int, - navFavorite: (Int) -> Unit, - navAccueil: (Int) -> Unit, - navProfil:(Int) -> Unit, - navControllerQuiz: (Int) -> Unit +fun QuizMenu( + index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navProfil:(Int) -> Unit, + navControllerQuiz: (Int) -> Unit ) { NavBar(onQuiz = true, index = index, diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/RecapSubmitPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/RecapSubmitPage.kt new file mode 100644 index 0000000..4d906c4 --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/RecapSubmitPage.kt @@ -0,0 +1,169 @@ +package com.example.what_the_fantasy.ui.screens +import android.content.Context +import android.content.Intent +import androidx.compose.foundation.background +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.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Favorite +import androidx.compose.material.icons.filled.FavoriteBorder +import androidx.compose.material.icons.filled.MailOutline +import androidx.compose.material.icons.filled.Share +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Text +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.CornerRadius +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.example.what_the_fantasy.R +import coil.compose.AsyncImage +import com.example.what_the_fantasy.ui.components.NavBar +import com.example.what_the_fantasy.ui.theme.gradienBox +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +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 com.example.what_the_fantasy.data.model.Character + + +@Composable +fun RecapSubmitPage( + index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navProfil:(Int) -> Unit, + quoteContent : String, + character: String, + source: String +) { + NavBar(onQuiz = true, + index = index, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = { } + ) { + + Column( + modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B)) + ) { + // Contenu princiapl + Column( + modifier = Modifier + .weight(0.9f) + .fillMaxSize() + .padding(20.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = "▶ Recap de la citation ◀", + color = Color.White, + style = TextStyle( + fontSize = 25.sp, + fontWeight = FontWeight.Bold, + textAlign = TextAlign.Center + ) + ) + Spacer(Modifier.height(20.dp)) + Column( + modifier = Modifier + .background(brush = gradient, shape = RoundedCornerShape(20.dp)) + .fillMaxSize() + .padding(vertical = 30.dp) + .verticalScroll(rememberScrollState()), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Column(modifier = Modifier + .padding(15.dp) + .drawBehind { + drawRoundRect( + gradienBox, + cornerRadius = CornerRadius(15.dp.toPx()), + ) + } + ) { + Row(modifier = Modifier.padding(15.dp)) { + ImageQuote( + imageUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-fantaisie_1045-185.jpg?size=338&ext=jpg" + ) + Column { + QuoteText( + text = '"' + quoteContent + '"' + ) + } + } + Column(modifier = Modifier + .padding(15.dp) + .fillMaxWidth() + ) { + InfoQuoteText( + nameId = R.string.source, + text = source + ) + Text( + text = "Character : $character" + ) + } + } + } + } + } + } +} + +@Composable +fun QuoteText(text: String ){ + Text( + text = text, + modifier = Modifier.padding(start = 10.dp, top = 15.dp), + fontWeight = FontWeight(1000), + fontSize = 20.sp, + color = Color.White + ) +} + +@Composable +fun ImageQuote(imageUrl : String){ + AsyncImage( + model = imageUrl, + contentDescription = "exemple", + modifier = Modifier + .size(150.dp) + .clip(RoundedCornerShape(15.dp)) + ) +} + +@Composable +fun InfoQuoteText(nameId : Int, text : String){ + Column(modifier = Modifier.padding(bottom = 20.dp)){ + + Text( + text = text, + fontSize = 16.sp, + fontWeight = FontWeight(400), + modifier = Modifier + .drawBehind { + drawRoundRect( + Color(255,255,255), + cornerRadius = CornerRadius(15.dp.toPx()) + ) + } + .padding(5.dp), + ) + } +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt index dd6dce6..35edd2f 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt @@ -1,8 +1,253 @@ 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.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text import androidx.compose.runtime.Composable +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.res.stringResource +import androidx.compose.ui.text.input.KeyboardType +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.ui.components.ErrorMessageSubmitQuoteComponent import com.example.what_the_fantasy.ui.components.NavBar +import com.example.what_the_fantasy.ui.components.SpaceHeightComponent +import com.example.what_the_fantasy.ui.components.TitlePageComponent +import com.example.what_the_fantasy.ui.theme.colorBackground +import com.example.what_the_fantasy.ui.theme.gradienBox @Composable -fun SubmitQuotePage() { -} \ No newline at end of file +fun SubmitQuotePage( + index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navProfil:(Int) -> Unit, + navControllerQuiz: (Int) -> Unit, + navRecap: (String, String, String) -> Unit +) { + NavBar( + index = index, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = navControllerQuiz + ) { + Box( + modifier = Modifier + .fillMaxSize() + .background(colorBackground), + contentAlignment = Alignment.Center + ){ + Column( + modifier = Modifier + .fillMaxWidth(0.9f) + .padding(20.dp) + .clip(RoundedCornerShape(16.dp)) + .background(gradienBox) + .padding(20.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + TitlePageComponent(R.string.titleSubmitQuote, Color.White) + SpaceHeightComponent(20) + SubmitQuoteButton( + quoteTextField(R.string.quote), + characterTextField(R.string.character), + sourceTextField(R.string.source), + timeCodeTextField(R.string.timeCode), + yearTextField(R.string.year), + R.string.titleButtonSubmit, + 18, + Color.White, + Color.Black, + navRecap + ) + SpaceHeightComponent(20) + BackButton(R.string.titleButtonBack, 12, Color.White,navProfil, index) + } + } + } + +} + +@Composable +fun quoteTextField(textQuoteResId : Int) : String{ + val textQuote = stringResource(id = textQuoteResId) + var quote by remember { mutableStateOf("") } + Column(modifier = Modifier.padding(top = 16.dp)) { + OutlinedTextField( + value = quote, + onValueChange = { quote = it }, + label = { Text(textQuote, color = Color.White) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) + ) + } + return quote; +} + +@Composable +fun characterTextField(textCharacterResId : Int) : String{ + val textCharacter = stringResource(id = textCharacterResId) + var character by remember { mutableStateOf("") } + + Column(modifier = Modifier.padding(top = 16.dp)) { + OutlinedTextField( + value = character, + onValueChange = { character = it }, + label = { Text(textCharacter, color = Color.White) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) + ) + } + return character; +} + +@Composable +fun sourceTextField(textSourceResId : Int) : String{ + val textSource = stringResource(id = textSourceResId) + var source by remember { mutableStateOf("") } + Column(modifier = Modifier.padding(top = 16.dp)) { + OutlinedTextField( + value = source, + onValueChange = { source = it }, + label = { Text(textSource, color = Color.White) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) + ) + } + return source; +} + + +@Composable +fun timeCodeTextField(textTimeCodeResId : Int) : String{ + val textTimeCode = stringResource(id = textTimeCodeResId) + var timeCode by remember { mutableStateOf("") } + Column(modifier = Modifier.padding(top = 16.dp)) { + OutlinedTextField( + value = timeCode, + onValueChange = { timeCode = it }, + label = { Text(textTimeCode, color = Color.White) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) + ) + } + return timeCode; +} + + +@Composable +fun yearTextField(textYearResId : Int) : String{ + val textYear = stringResource(id = textYearResId) + var year by remember { mutableStateOf("") } + Column(modifier = Modifier.padding(top = 16.dp, bottom = 30.dp)) { + OutlinedTextField( + value = year, + onValueChange = { year = it }, + label = { Text(textYear, color = Color.White) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) + ) + } + return year; +} + + +@Composable +fun SubmitQuoteButton( + quote: String, + character: String, + source: String, + timeCode: String, + year: String, + titleResId: Int, + size: Int, + colorButton: Color, + colorText: Color, + navRecap : (String, String, String) -> Unit +) { + val title = stringResource(id = titleResId) + var showError by remember { mutableStateOf(false) } + + Button( + onClick = { showError = !goToRecap(quote, character, source, timeCode, year, navRecap) }, + colors = ButtonDefaults.buttonColors(containerColor = colorButton), + modifier = Modifier.fillMaxWidth(), + ) { + Text(title, fontSize = size.sp, color = colorText) + } + + if (showError) { + ErrorMessageSubmitQuoteComponent(R.string.ErrorSubmitQuote) + } +} + +fun goToRecap(quote: String, + character: String, + source: String, + timeCode: String, + year: String, + navRecap : (String, String, String) -> Unit): Boolean { + if (validSubmitQuote(quote, character, source, timeCode, year)) { + navRecap(quote, character, source) + return true + } + return false +} + +fun validSubmitQuote(quote : String, character : String, source: String, timeCode: String, year: String): Boolean{ + val isNotBlank = quote.isNotBlank() && + character.isNotBlank() && + source.isNotBlank() && + timeCode.isNotBlank() && + year.isNotBlank() && + year.all { it.isDigit() } + return isNotBlank +} + +@Composable +fun BackButton(titleResId : Int, size : Int, color : Color, navController: (Int) -> Unit, user: Int) { + val title = stringResource(id = titleResId) + Text( + text = title, + fontSize = size.sp, + color = color, + modifier = Modifier.clickable { + navController(user) + } + ) +} + diff --git a/What_The_Fantasy/app/src/main/res/values/strings.xml b/What_The_Fantasy/app/src/main/res/values/strings.xml index 028b28a..191ee6f 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -54,4 +54,14 @@ ▶ Quote of the day ◀ ▶ Suggestions ◀ + //Page SubmitQuote + Submit Quote + Submit + Profil + Quote + Character + Source + Time Code + Year + Invalid Fields \ No newline at end of file