Add isNotBlank fields to SubmitQuote

submitQuote
tomivt 1 month ago
parent 5c2a195b95
commit 3d130b2504

@ -19,4 +19,15 @@ fun ErrorMessageProfileComponent(titleResId : Int) {
fontSize = 12.sp, fontSize = 12.sp,
modifier = Modifier.padding(top = 4.dp) 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)
)
} }

@ -108,12 +108,13 @@ fun AppNavigator() {
val submitQuote:SubmitQuote=it.toRoute() val submitQuote:SubmitQuote=it.toRoute()
SubmitQuotePage( SubmitQuotePage(
index = submitQuote.userIndex, index = submitQuote.userIndex,
navControllerProfil = { userIndex -> navAccueil = { navController.navigate( Accueil(submitQuote.userIndex) ) },
navController.navigate(Profil(userIndex)) { navFavorite = { navController.navigate(Favorite(submitQuote.userIndex)) },
// Vider pile de navigation pour empêcher le retour à la page Login navProfil = { navController.navigate(Profil(submitQuote.userIndex)) },
popUpTo(Login) { inclusive = true } navControllerQuiz = { idQuiz ->
} navController.navigate(Quiz(submitQuote.userIndex,idQuiz))
}) }
)
} }
composable<QuizMenu> { composable<QuizMenu> {
val quizMenu:QuizMenu=it.toRoute() val quizMenu:QuizMenu=it.toRoute()

@ -2,16 +2,11 @@ package com.example.what_the_fantasy.ui.screens
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable 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.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height 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.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp 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.local.QuizStub
import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.NavBar
@Composable @Composable
fun QuizMenu( index: Int, fun QuizMenu(
navFavorite: (Int) -> Unit, index: Int,
navAccueil: (Int) -> Unit, navFavorite: (Int) -> Unit,
navProfil:(Int) -> Unit, navAccueil: (Int) -> Unit,
navControllerQuiz: (Int) -> Unit navProfil:(Int) -> Unit,
navControllerQuiz: (Int) -> Unit
) { ) {
NavBar(onQuiz = true, NavBar(onQuiz = true,
index = index, index = index,

@ -14,6 +14,8 @@ import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldColors
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf 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.model.User
import com.example.what_the_fantasy.data.services.IServices 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.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.NavBar
import com.example.what_the_fantasy.ui.components.SpaceHeightComponent 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.TitlePageComponent
@ -44,90 +47,108 @@ import com.example.what_the_fantasy.ui.theme.gradienBox
@Composable @Composable
fun SubmitQuotePage( fun SubmitQuotePage(
index : Int, index: Int,
navControllerProfil: (Int) -> Unit navFavorite: (Int) -> Unit,
navAccueil: (Int) -> Unit,
navProfil:(Int) -> Unit,
navControllerQuiz: (Int) -> Unit
) { ) {
NavBar(
index = index,
navControllerFavorite = navFavorite,
Box( navControllerAccueil = navAccueil,
modifier = Modifier navControllerProfil = navProfil,
.fillMaxSize() navControllerQuiz = navControllerQuiz
.background(colorBackground), ) {
contentAlignment = Alignment.Center Box(
){
Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth(0.9f) .fillMaxSize()
.padding(20.dp) .background(colorBackground),
.clip(RoundedCornerShape(16.dp)) contentAlignment = Alignment.Center
.background(gradienBox) ){
.padding(20.dp), Column(
horizontalAlignment = Alignment.CenterHorizontally modifier = Modifier
) { .fillMaxWidth(0.9f)
TitlePageComponent(R.string.titleSubmitQuote, Color.White) .padding(20.dp)
SpaceHeightComponent(20) .clip(RoundedCornerShape(16.dp))
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) .background(gradienBox)
SpaceHeightComponent(20) .padding(20.dp),
BackButton(R.string.titleButtonBack, 12, Color.White,navControllerProfil, index) 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 @Composable
fun QuoteTextField(textQuoteResId : Int) : String{ fun quoteTextField(textQuoteResId : Int) : String{
val textQuote = stringResource(id = textQuoteResId) 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)) { Column(modifier = Modifier.padding(top = 16.dp)) {
OutlinedTextField( OutlinedTextField(
value = quote, value = quote,
onValueChange = { quote = it }, onValueChange = { quote = it },
label = { Text(textQuote) }, label = { Text(textQuote, color = Color.White) },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 8.dp), .padding(top = 8.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
shape = RoundedCornerShape(16.dp) // Bords arrondis shape = RoundedCornerShape(16.dp)
) )
} }
return quote; return quote;
} }
@Composable @Composable
fun CharacterTextField(textCharacterResId : Int) : String{ fun characterTextField(textCharacterResId : Int) : String{
val textCharacter = stringResource(id = textCharacterResId) 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)) { Column(modifier = Modifier.padding(top = 16.dp)) {
OutlinedTextField( OutlinedTextField(
value = character, value = character,
onValueChange = { character = it }, onValueChange = { character = it },
label = { Text(textCharacter) }, label = { Text(textCharacter, color = Color.White) },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 8.dp), .padding(top = 8.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
shape = RoundedCornerShape(16.dp) // Bords arrondis shape = RoundedCornerShape(16.dp)
) )
} }
return character; return character;
} }
@Composable @Composable
fun SourceTextField(textSourceResId : Int) : String{ fun sourceTextField(textSourceResId : Int) : String{
val textSource = stringResource(id = textSourceResId) 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)) { Column(modifier = Modifier.padding(top = 16.dp)) {
OutlinedTextField( OutlinedTextField(
value = source, value = source,
onValueChange = { source = it }, onValueChange = { source = it },
label = { Text(textSource) }, label = { Text(textSource, color = Color.White) },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 8.dp), .padding(top = 8.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
shape = RoundedCornerShape(16.dp) // Bords arrondis shape = RoundedCornerShape(16.dp)
) )
} }
return source; return source;
@ -135,19 +156,19 @@ fun SourceTextField(textSourceResId : Int) : String{
@Composable @Composable
fun TimeCodeTextField(textTimeCodeResId : Int) : String{ fun timeCodeTextField(textTimeCodeResId : Int) : String{
val textTimeCode = stringResource(id = textTimeCodeResId) 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)) { Column(modifier = Modifier.padding(top = 16.dp)) {
OutlinedTextField( OutlinedTextField(
value = timeCode, value = timeCode,
onValueChange = { timeCode = it }, onValueChange = { timeCode = it },
label = { Text(textTimeCode) }, label = { Text(textTimeCode, color = Color.White) },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 8.dp), .padding(top = 8.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
shape = RoundedCornerShape(16.dp) // Bords arrondis shape = RoundedCornerShape(16.dp)
) )
} }
return timeCode; return timeCode;
@ -155,19 +176,19 @@ fun TimeCodeTextField(textTimeCodeResId : Int) : String{
@Composable @Composable
fun YearTextField(textYearResId : Int) : String{ fun yearTextField(textYearResId : Int) : String{
val textYear = stringResource(id = textYearResId) 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)) { Column(modifier = Modifier.padding(top = 16.dp, bottom = 30.dp)) {
OutlinedTextField( OutlinedTextField(
value = year, value = year,
onValueChange = { year = it }, onValueChange = { year = it },
label = { Text(textYear) }, label = { Text(textYear, color = Color.White) },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 8.dp), .padding(top = 8.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
shape = RoundedCornerShape(16.dp) // Bords arrondis shape = RoundedCornerShape(16.dp)
) )
} }
return year; return year;
@ -175,26 +196,41 @@ fun YearTextField(textYearResId : Int) : String{
@Composable @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) val title = stringResource(id = titleResId)
var showError by remember { mutableStateOf(false) } var showError by remember { mutableStateOf(false) }
Button( Button(
onClick = { showError = validSubmitQuote() onClick = { showError = !validSubmitQuote(quote, character, source, timeCode, year) },
},
colors = ButtonDefaults.buttonColors(containerColor = colorButton), colors = ButtonDefaults.buttonColors(containerColor = colorButton),
modifier = Modifier modifier = Modifier.fillMaxWidth(),
.fillMaxWidth(),
) { ) {
Text(title, fontSize = size.sp, color = colorText) Text(title, fontSize = size.sp, color = colorText)
} }
if(showError){ if (showError) {
ErrorMessageProfileComponent(R.string.ErrorLogin) ErrorMessageSubmitQuoteComponent(R.string.ErrorSubmitQuote)
} }
} }
fun validSubmitQuote(): Boolean{ fun validSubmitQuote(quote : String, character : String, source: String, timeCode: String, year: String): Boolean{
return true val isNotBlank = quote.isNotBlank() &&
character.isNotBlank() &&
source.isNotBlank() &&
timeCode.isNotBlank() &&
year.isNotBlank() &&
year.all { it.isDigit() }
return isNotBlank
} }
@Composable @Composable

@ -45,9 +45,10 @@
<string name="titleSubmitQuote">Submit Quote</string> <string name="titleSubmitQuote">Submit Quote</string>
<string name="titleButtonSubmit">Submit</string> <string name="titleButtonSubmit">Submit</string>
<string name="titleButtonBack">Profil</string> <string name="titleButtonBack">Profil</string>
<string name="quote">quote</string> <string name="quote">Quote</string>
<string name="character">character</string> <string name="character">Character</string>
<string name="source">source</string> <string name="source">Source</string>
<string name="timeCode">time code</string> <string name="timeCode">Time Code</string>
<string name="year">year</string> <string name="year">Year</string>
<string name="ErrorSubmitQuote"> Invalid Fields </string>
</resources> </resources>
Loading…
Cancel
Save