Add isNotBlank fields to SubmitQuote

submitQuote
tomivt 1 month ago
parent 5c2a195b95
commit 3d130b2504

@ -20,3 +20,14 @@ fun ErrorMessageProfileComponent(titleResId : Int) {
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()
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<QuizMenu> {
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.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,

@ -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

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