From 5c2a195b9547c99e16fc6a9702c1e217cd654be7 Mon Sep 17 00:00:00 2001 From: "louis.guichard-montguers" Date: Fri, 7 Mar 2025 11:54:59 +0100 Subject: [PATCH 1/4] page submitQuote manque juste la verification --- .../ui/navigations/AppNavigator.kt | 19 +- .../what_the_fantasy/ui/screens/ProfilPage.kt | 7 +- .../ui/screens/SubmitQuotePage.kt | 208 +++++++++++++++++- .../app/src/main/res/values-fr/strings.xml | 10 + .../app/src/main/res/values/strings.xml | 9 + 5 files changed, 244 insertions(+), 9 deletions(-) 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 169f329..80a3f4c 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 @@ -17,6 +17,7 @@ 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.SignUpPage import com.example.what_the_fantasy.ui.screens.SubmitQuotePage +import com.example.what_the_fantasy.ui.screens.validLogin import kotlinx.serialization.Serializable @Serializable @@ -40,7 +41,7 @@ data object Search @Serializable data object SignUp @Serializable -data object SubmitQuote +data class SubmitQuote(val userIndex: Int) @Composable @@ -90,7 +91,8 @@ fun AppNavigator() { popUpTo(profil) { inclusive = true } } }, - services = services + services = services, + navSubmitQuote = { navController.navigate( SubmitQuote(profil.userIndex))} ) } composable { QuotePage() } @@ -102,8 +104,17 @@ fun AppNavigator() { popUpTo(Login) { inclusive = true } } },services) } - composable { SubmitQuotePage() } - + composable { + val submitQuote:SubmitQuote=it.toRoute() + SubmitQuotePage( + index = submitQuote.userIndex, + navControllerProfil = { userIndex -> + navController.navigate(Profil(userIndex)) { + // Vider pile de navigation pour empêcher le retour à la page Login + popUpTo(Login) { inclusive = true } + } + }) + } composable { val quizMenu:QuizMenu=it.toRoute() QuizMenu( diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt index b122258..4242829 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt @@ -79,7 +79,8 @@ fun ProfilPage(index: Int, navAccueil: (Int) -> Unit, navQuiz: (Int) -> Unit, navUnLog: () -> Unit, - services: IServices + services: IServices, + navSubmitQuote: () -> Unit ) { val user = services.getUserById(index) ?: return @@ -125,8 +126,8 @@ fun ProfilPage(index: Int, SpaceHeightComponent(16) // Bouton - //ButtonProfile(R.string.ButtonAddQuoteprofile, 18, Color.Black, Color.White,navUnLog) // Pas encore de navigation definie - //SpaceHeightComponent(16) + ButtonProfile(R.string.ButtonAddQuoteprofile, 18, Color.Black, Color.White,navSubmitQuote) // Pas encore de navigation definie + SpaceHeightComponent(16) ButtonProfile(R.string.ButtonLanguageprofile, 18, Color.Black, Color.White,navUnLog) // Pas encore de navigation definie SpaceHeightComponent(16) ButtonProfile(R.string.ButtonUnlogprofile, 18, Color.Black, Color.White, navUnLog) 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..bb17128 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,212 @@ 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.IconButton +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.text.input.PasswordVisualTransformation +import androidx.compose.ui.text.input.VisualTransformation +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.model.Character +import com.example.what_the_fantasy.data.model.User +import com.example.what_the_fantasy.data.services.IServices +import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent 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.components.hashPassword +import com.example.what_the_fantasy.ui.navigations.Profil +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, + navControllerProfil: (Int) -> Unit +) { + + + + 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) + SpaceHeightComponent(20) + BackButton(R.string.titleButtonBack, 12, Color.White,navControllerProfil, index) + } + } + +} + +@Composable +fun QuoteTextField(textQuoteResId : Int) : String{ + val textQuote = stringResource(id = textQuoteResId) + var quote by remember { mutableStateOf("") } // Stocke la valeur du champ + Column(modifier = Modifier.padding(top = 16.dp)) { + OutlinedTextField( + value = quote, + onValueChange = { quote = it }, + label = { Text(textQuote) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) // Bords arrondis + ) + } + return quote; +} + +@Composable +fun CharacterTextField(textCharacterResId : Int) : String{ + val textCharacter = stringResource(id = textCharacterResId) + var character by remember { mutableStateOf("") } // Stocke la valeur du champ + + Column(modifier = Modifier.padding(top = 16.dp)) { + OutlinedTextField( + value = character, + onValueChange = { character = it }, + label = { Text(textCharacter) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) // Bords arrondis + ) + } + return character; +} + +@Composable +fun SourceTextField(textSourceResId : Int) : String{ + val textSource = stringResource(id = textSourceResId) + var source by remember { mutableStateOf("") } // Stocke la valeur du champ + Column(modifier = Modifier.padding(top = 16.dp)) { + OutlinedTextField( + value = source, + onValueChange = { source = it }, + label = { Text(textSource) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) // Bords arrondis + ) + } + return source; +} + + +@Composable +fun TimeCodeTextField(textTimeCodeResId : Int) : String{ + val textTimeCode = stringResource(id = textTimeCodeResId) + var timeCode by remember { mutableStateOf("") } // Stocke la valeur du champ + Column(modifier = Modifier.padding(top = 16.dp)) { + OutlinedTextField( + value = timeCode, + onValueChange = { timeCode = it }, + label = { Text(textTimeCode) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) // Bords arrondis + ) + } + return timeCode; +} + + +@Composable +fun YearTextField(textYearResId : Int) : String{ + val textYear = stringResource(id = textYearResId) + var year by remember { mutableStateOf("") } // Stocke la valeur du champ + Column(modifier = Modifier.padding(top = 16.dp, bottom = 30.dp)) { + OutlinedTextField( + value = year, + onValueChange = { year = it }, + label = { Text(textYear) }, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), + shape = RoundedCornerShape(16.dp) // Bords arrondis + ) + } + return year; +} + + +@Composable +fun SubmitQuoteButton( quote : String, character : String, source: String, timeCode: String, year: String , titleResId : Int, size : Int, colorButton : Color, colorText : Color){ + val title = stringResource(id = titleResId) + var showError by remember { mutableStateOf(false) } + Button( + onClick = { showError = validSubmitQuote() + }, + colors = ButtonDefaults.buttonColors(containerColor = colorButton), + modifier = Modifier + .fillMaxWidth(), + ) { + Text(title, fontSize = size.sp, color = colorText) + } + + if(showError){ + ErrorMessageProfileComponent(R.string.ErrorLogin) + } +} + +fun validSubmitQuote(): Boolean{ + return true +} + +@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-fr/strings.xml b/What_The_Fantasy/app/src/main/res/values-fr/strings.xml index 84332fa..19d5e87 100644 --- a/What_The_Fantasy/app/src/main/res/values-fr/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values-fr/strings.xml @@ -43,4 +43,14 @@ //Page Favori Favoris + + //Page Submit Quote + Proposez Une Citation + Proposez + Profile + citation + personnage + source + code temporel + année de sortie \ No newline at end of file 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 2fcce63..63bf200 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -41,4 +41,13 @@ //Page Favori Favorites + //Page SubmitQuote + Submit Quote + Submit + Profil + quote + character + source + time code + year \ No newline at end of file From 3d130b25043085117b4a14de3c62154e5deb6f7b Mon Sep 17 00:00:00 2001 From: tomivt Date: Fri, 14 Mar 2025 08:53:17 +0100 Subject: [PATCH 2/4] Add isNotBlank fields to SubmitQuote --- .../ui/components/ErrorMessageComponent.kt | 11 ++ .../ui/navigations/AppNavigator.kt | 13 +- .../what_the_fantasy/ui/screens/QuizMenu.kt | 19 +-- .../ui/screens/SubmitQuotePage.kt | 144 +++++++++++------- .../app/src/main/res/values/strings.xml | 11 +- 5 files changed, 120 insertions(+), 78 deletions(-) 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 80a3f4c..d1e46e1 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 @@ -108,12 +108,13 @@ fun AppNavigator() { val submitQuote:SubmitQuote=it.toRoute() SubmitQuotePage( index = submitQuote.userIndex, - navControllerProfil = { userIndex -> - navController.navigate(Profil(userIndex)) { - // Vider pile de navigation pour empêcher le retour à la page Login - popUpTo(Login) { inclusive = true } - } - }) + 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)) + } + ) } composable { val quizMenu:QuizMenu=it.toRoute() 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 99c50af..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 @@ -2,16 +2,11 @@ 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 @@ -34,18 +29,16 @@ 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: (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/SubmitQuotePage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SubmitQuotePage.kt index bb17128..8270ae1 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 @@ -14,6 +14,8 @@ import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.IconButton import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text +import androidx.compose.material3.TextFieldColors +import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -34,6 +36,7 @@ import com.example.what_the_fantasy.data.model.Character import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent +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 @@ -44,90 +47,108 @@ import com.example.what_the_fantasy.ui.theme.gradienBox @Composable fun SubmitQuotePage( - index : Int, - navControllerProfil: (Int) -> Unit + index: Int, + navFavorite: (Int) -> Unit, + navAccueil: (Int) -> Unit, + navProfil:(Int) -> Unit, + navControllerQuiz: (Int) -> Unit ) { - - - - Box( - modifier = Modifier - .fillMaxSize() - .background(colorBackground), - contentAlignment = Alignment.Center - ){ - Column( + NavBar( + index = index, + navControllerFavorite = navFavorite, + navControllerAccueil = navAccueil, + navControllerProfil = navProfil, + navControllerQuiz = navControllerQuiz + ) { + Box( 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) - SpaceHeightComponent(20) - BackButton(R.string.titleButtonBack, 12, Color.White,navControllerProfil, index) + .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 + ) + SpaceHeightComponent(20) + BackButton(R.string.titleButtonBack, 12, Color.White,navProfil, index) + } } } - + } @Composable -fun QuoteTextField(textQuoteResId : Int) : String{ +fun quoteTextField(textQuoteResId : Int) : String{ val textQuote = stringResource(id = textQuoteResId) - var quote by remember { mutableStateOf("") } // Stocke la valeur du champ + var quote by remember { mutableStateOf("") } Column(modifier = Modifier.padding(top = 16.dp)) { OutlinedTextField( value = quote, onValueChange = { quote = it }, - label = { Text(textQuote) }, + label = { Text(textQuote, color = Color.White) }, modifier = Modifier .fillMaxWidth() .padding(top = 8.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), - shape = RoundedCornerShape(16.dp) // Bords arrondis + shape = RoundedCornerShape(16.dp) ) } return quote; } @Composable -fun CharacterTextField(textCharacterResId : Int) : String{ +fun characterTextField(textCharacterResId : Int) : String{ val textCharacter = stringResource(id = textCharacterResId) - var character by remember { mutableStateOf("") } // Stocke la valeur du champ + var character by remember { mutableStateOf("") } Column(modifier = Modifier.padding(top = 16.dp)) { OutlinedTextField( value = character, onValueChange = { character = it }, - label = { Text(textCharacter) }, + label = { Text(textCharacter, color = Color.White) }, modifier = Modifier .fillMaxWidth() .padding(top = 8.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), - shape = RoundedCornerShape(16.dp) // Bords arrondis + shape = RoundedCornerShape(16.dp) ) } return character; } @Composable -fun SourceTextField(textSourceResId : Int) : String{ +fun sourceTextField(textSourceResId : Int) : String{ val textSource = stringResource(id = textSourceResId) - var source by remember { mutableStateOf("") } // Stocke la valeur du champ + var source by remember { mutableStateOf("") } Column(modifier = Modifier.padding(top = 16.dp)) { OutlinedTextField( value = source, onValueChange = { source = it }, - label = { Text(textSource) }, + label = { Text(textSource, color = Color.White) }, modifier = Modifier .fillMaxWidth() .padding(top = 8.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), - shape = RoundedCornerShape(16.dp) // Bords arrondis + shape = RoundedCornerShape(16.dp) ) } return source; @@ -135,19 +156,19 @@ fun SourceTextField(textSourceResId : Int) : String{ @Composable -fun TimeCodeTextField(textTimeCodeResId : Int) : String{ +fun timeCodeTextField(textTimeCodeResId : Int) : String{ val textTimeCode = stringResource(id = textTimeCodeResId) - var timeCode by remember { mutableStateOf("") } // Stocke la valeur du champ + var timeCode by remember { mutableStateOf("") } Column(modifier = Modifier.padding(top = 16.dp)) { OutlinedTextField( value = timeCode, onValueChange = { timeCode = it }, - label = { Text(textTimeCode) }, + label = { Text(textTimeCode, color = Color.White) }, modifier = Modifier .fillMaxWidth() .padding(top = 8.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), - shape = RoundedCornerShape(16.dp) // Bords arrondis + shape = RoundedCornerShape(16.dp) ) } return timeCode; @@ -155,19 +176,19 @@ fun TimeCodeTextField(textTimeCodeResId : Int) : String{ @Composable -fun YearTextField(textYearResId : Int) : String{ +fun yearTextField(textYearResId : Int) : String{ val textYear = stringResource(id = textYearResId) - var year by remember { mutableStateOf("") } // Stocke la valeur du champ + var year by remember { mutableStateOf("") } Column(modifier = Modifier.padding(top = 16.dp, bottom = 30.dp)) { OutlinedTextField( value = year, onValueChange = { year = it }, - label = { Text(textYear) }, + label = { Text(textYear, color = Color.White) }, modifier = Modifier .fillMaxWidth() .padding(top = 8.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), - shape = RoundedCornerShape(16.dp) // Bords arrondis + shape = RoundedCornerShape(16.dp) ) } return year; @@ -175,26 +196,41 @@ fun YearTextField(textYearResId : Int) : String{ @Composable -fun SubmitQuoteButton( quote : String, character : String, source: String, timeCode: String, year: String , titleResId : Int, size : Int, colorButton : Color, colorText : Color){ +fun SubmitQuoteButton( + quote: String, + character: String, + source: String, + timeCode: String, + year: String, + titleResId: Int, + size: Int, + colorButton: Color, + colorText: Color +) { val title = stringResource(id = titleResId) var showError by remember { mutableStateOf(false) } + Button( - onClick = { showError = validSubmitQuote() - }, + onClick = { showError = !validSubmitQuote(quote, character, source, timeCode, year) }, colors = ButtonDefaults.buttonColors(containerColor = colorButton), - modifier = Modifier - .fillMaxWidth(), + modifier = Modifier.fillMaxWidth(), ) { Text(title, fontSize = size.sp, color = colorText) } - if(showError){ - ErrorMessageProfileComponent(R.string.ErrorLogin) + if (showError) { + ErrorMessageSubmitQuoteComponent(R.string.ErrorSubmitQuote) } } -fun validSubmitQuote(): Boolean{ - return true +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 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 63bf200..4e8e5a8 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -45,9 +45,10 @@ Submit Quote Submit Profil - quote - character - source - time code - year + Quote + Character + Source + Time Code + Year + Invalid Fields \ No newline at end of file From fdc03b62cf8a221f346b62e0296195a3902cdae6 Mon Sep 17 00:00:00 2001 From: tomivt Date: Fri, 14 Mar 2025 09:36:33 +0100 Subject: [PATCH 3/4] Add RecapSubmit --- .../ui/navigations/AppNavigator.kt | 22 +++ .../ui/screens/RecapSubmitPage.kt | 168 ++++++++++++++++++ .../ui/screens/SubmitQuotePage.kt | 35 ++-- 3 files changed, 210 insertions(+), 15 deletions(-) create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/RecapSubmitPage.kt 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 d1e46e1..cd1e808 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 @@ -14,6 +14,7 @@ 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.RecapSubmitPage import com.example.what_the_fantasy.ui.screens.SearchPage import com.example.what_the_fantasy.ui.screens.SignUpPage import com.example.what_the_fantasy.ui.screens.SubmitQuotePage @@ -43,6 +44,12 @@ data object SignUp @Serializable 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() { @@ -113,6 +120,9 @@ fun AppNavigator() { 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)) } ) } @@ -154,5 +164,17 @@ fun AppNavigator() { navQuiz = { navController.navigate(QuizMenu(quizEnd.userIndex)) } ) } + 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)) } + ) + } } } 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..65c74a3 --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/RecapSubmitPage.kt @@ -0,0 +1,168 @@ +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 + ) + } + } + } + } + } + } +} + +@Composable +fun QuoteText(text: String ){ + Text( + text = text, + modifier = Modifier.padding(start = 10.dp, top = 15.dp), + fontWeight = FontWeight(1000), + fontSize = 20.sp + ) +} + +@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 8270ae1..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 @@ -11,11 +11,8 @@ 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.IconButton import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text -import androidx.compose.material3.TextFieldColors -import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -27,21 +24,13 @@ 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.text.input.PasswordVisualTransformation -import androidx.compose.ui.text.input.VisualTransformation 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.model.Character -import com.example.what_the_fantasy.data.model.User -import com.example.what_the_fantasy.data.services.IServices -import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent 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.components.hashPassword -import com.example.what_the_fantasy.ui.navigations.Profil import com.example.what_the_fantasy.ui.theme.colorBackground import com.example.what_the_fantasy.ui.theme.gradienBox @@ -51,7 +40,8 @@ fun SubmitQuotePage( navFavorite: (Int) -> Unit, navAccueil: (Int) -> Unit, navProfil:(Int) -> Unit, - navControllerQuiz: (Int) -> Unit + navControllerQuiz: (Int) -> Unit, + navRecap: (String, String, String) -> Unit ) { NavBar( index = index, @@ -86,7 +76,8 @@ fun SubmitQuotePage( R.string.titleButtonSubmit, 18, Color.White, - Color.Black + Color.Black, + navRecap ) SpaceHeightComponent(20) BackButton(R.string.titleButtonBack, 12, Color.White,navProfil, index) @@ -205,13 +196,14 @@ fun SubmitQuoteButton( titleResId: Int, size: Int, colorButton: Color, - colorText: Color + colorText: Color, + navRecap : (String, String, String) -> Unit ) { val title = stringResource(id = titleResId) var showError by remember { mutableStateOf(false) } Button( - onClick = { showError = !validSubmitQuote(quote, character, source, timeCode, year) }, + onClick = { showError = !goToRecap(quote, character, source, timeCode, year, navRecap) }, colors = ButtonDefaults.buttonColors(containerColor = colorButton), modifier = Modifier.fillMaxWidth(), ) { @@ -223,6 +215,19 @@ fun SubmitQuoteButton( } } +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() && From f08a28f4a7d89d26b9b1b92077ea282fca937254 Mon Sep 17 00:00:00 2001 From: tomivt Date: Fri, 14 Mar 2025 09:45:00 +0100 Subject: [PATCH 4/4] Ready to merge --- .../example/what_the_fantasy/ui/screens/RecapSubmitPage.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 index 65c74a3..4d906c4 100644 --- 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 @@ -116,7 +116,7 @@ fun RecapSubmitPage( text = source ) Text( - text = character + text = "Character : $character" ) } } @@ -132,7 +132,8 @@ fun QuoteText(text: String ){ text = text, modifier = Modifier.padding(start = 10.dp, top = 15.dp), fontWeight = FontWeight(1000), - fontSize = 20.sp + fontSize = 20.sp, + color = Color.White ) }