From 3d130b25043085117b4a14de3c62154e5deb6f7b Mon Sep 17 00:00:00 2001 From: tomivt Date: Fri, 14 Mar 2025 08:53:17 +0100 Subject: [PATCH] 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