commit
9d8738e398
@ -0,0 +1,39 @@
|
|||||||
|
package com.example.what_the_fantasy.data.local
|
||||||
|
|
||||||
|
import com.example.what_the_fantasy.data.model.Comment
|
||||||
|
import com.example.what_the_fantasy.data.model.User
|
||||||
|
|
||||||
|
object CommentStub {
|
||||||
|
val comments: MutableList<Comment> = mutableListOf(
|
||||||
|
Comment("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Trop bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("encore un Test","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Je suis la ","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("J'en ai rien a foutre de la citation","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Android c'est bien","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("je sais plus quoi mettre donc ca va être le bordel","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("Et un test de plus","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("La bombe à été activer","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
Comment("J'aime pas les *****","Dev","21-12-2005", "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"),
|
||||||
|
)
|
||||||
|
}
|
@ -1,27 +1,21 @@
|
|||||||
package com.example.what_the_fantasy.data.local
|
package com.example.what_the_fantasy.data.local
|
||||||
|
|
||||||
|
import com.example.what_the_fantasy.data.local.QuoteStub.quotes
|
||||||
|
import com.example.what_the_fantasy.data.local.UserStub.users
|
||||||
import com.example.what_the_fantasy.data.model.Favorite
|
import com.example.what_the_fantasy.data.model.Favorite
|
||||||
import com.example.what_the_fantasy.data.model.Quote
|
|
||||||
|
|
||||||
object FavoriteStub {
|
object FavoriteStub {
|
||||||
val favorites: MutableList<Favorite> = mutableListOf(
|
val favorites: MutableList<Favorite> = mutableListOf(
|
||||||
Favorite(UserStub.users[0], QuoteStub.quote1),
|
Favorite(users[0], mutableListOf(quotes[0], quotes[1], quotes[12])), // Aragorn123 aime ces citations
|
||||||
Favorite(UserStub.users[1], QuoteStub.quote12),
|
Favorite(users[1], mutableListOf(quotes[5], quotes[6], quotes[7])), // Legolas456 aime ces citations
|
||||||
Favorite(UserStub.users[2], QuoteStub.quote13),
|
Favorite(users[2], mutableListOf(quotes[8], quotes[9], quotes[10])), // Gandalf789 aime ces citations
|
||||||
Favorite(UserStub.users[3], QuoteStub.quote6),
|
Favorite(users[3], mutableListOf(quotes[11], quotes[12], quotes[13])), // FrodoBaggins aime ces citations
|
||||||
Favorite(UserStub.users[4], QuoteStub.quote5),
|
Favorite(users[4], mutableListOf(quotes[14], quotes[15], quotes[16])), // Gimli999 aime ces citations
|
||||||
Favorite(UserStub.users[5], QuoteStub.quote3),
|
Favorite(users[5], mutableListOf(quotes[17], quotes[18], quotes[19])), // Galadriel321 aime ces citations
|
||||||
Favorite(UserStub.users[6], QuoteStub.quote17),
|
Favorite(users[6], mutableListOf(quotes[17], quotes[2], quotes[7])), // Boromir654 aime ces citations
|
||||||
Favorite(UserStub.users[7], QuoteStub.quote7),
|
Favorite(users[7], mutableListOf(quotes[3], quotes[4], quotes[10])), // Eowyn777 aime ces citations
|
||||||
Favorite(UserStub.users[8], QuoteStub.quote19),
|
Favorite(users[8], mutableListOf(quotes[6], quotes[8], quotes[9])), // Saruman888 aime ces citations
|
||||||
Favorite(UserStub.users[9], QuoteStub.quote20),
|
Favorite(users[9], mutableListOf(quotes[5], quotes[13], quotes[15])), // Faramir222 aime ces citations
|
||||||
Favorite(UserStub.users[10], QuoteStub.quote11)
|
Favorite(users[10], mutableListOf(quotes[12], quotes[17], quotes[16])) // dev aime ces citations
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getFavoritesByUser(userId: Int): List<Quote> {
|
|
||||||
return favorites
|
|
||||||
.filter { it.user.id == userId }
|
|
||||||
.map { it.quote }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.example.what_the_fantasy.data.model
|
||||||
|
|
||||||
|
data class Comment(
|
||||||
|
val content : String,
|
||||||
|
val user : String,
|
||||||
|
val date : String,
|
||||||
|
val img : String
|
||||||
|
)
|
@ -1,6 +1,6 @@
|
|||||||
package com.example.what_the_fantasy.data.model
|
package com.example.what_the_fantasy.data.model
|
||||||
|
|
||||||
enum class SrcLanguage {
|
enum class SrcLanguage {
|
||||||
fr,
|
vf,
|
||||||
vo
|
vo
|
||||||
}
|
}
|
@ -1,27 +1,33 @@
|
|||||||
package com.example.what_the_fantasy.data.services
|
package com.example.what_the_fantasy.data.services
|
||||||
|
|
||||||
|
import com.example.what_the_fantasy.data.model.Favorite
|
||||||
|
import com.example.what_the_fantasy.data.model.Comment
|
||||||
import com.example.what_the_fantasy.data.model.Quote
|
import com.example.what_the_fantasy.data.model.Quote
|
||||||
import com.example.what_the_fantasy.data.model.User
|
import com.example.what_the_fantasy.data.model.User
|
||||||
|
|
||||||
interface IServices {
|
interface IServices {
|
||||||
fun EditUsername(username : String, index : Int)
|
fun EditUsername(username : String, index : Int) : Boolean
|
||||||
fun EditEmail(email : String, index : Int)
|
fun EditEmail(email : String, index : Int) : Boolean
|
||||||
fun EditPasswd(passwd : String, index : Int)
|
fun EditPasswd(passwd : String, index : Int)
|
||||||
fun EditImage(imageURL : String, index : Int)
|
fun EditImage(imageURL : String, index : Int)
|
||||||
|
fun ChangeLangage(user: User)
|
||||||
|
|
||||||
|
fun AddFav(userId: Int, QuoteId : Int)
|
||||||
|
fun SupFav(userId: Int, QuoteId : Int)
|
||||||
|
fun AddComment(content : String)
|
||||||
fun CreateUser(username : String, email : String, passwd : String, services : IServices) : Boolean
|
fun CreateUser(username : String, email : String, passwd : String, services : IServices) : Boolean
|
||||||
fun getFavorite(username: String)
|
fun getFavorite(user: User): List<Quote>
|
||||||
fun getAllUsers(): List<User>
|
fun getAllUsers(): List<User>
|
||||||
|
fun getComment(quoteId : Int) : List<Comment>
|
||||||
fun getUserById(id: Int): User?
|
fun getUserById(id: Int): User?
|
||||||
|
|
||||||
fun SearchQuote(quote : String)
|
fun SearchQuote(quote : String)
|
||||||
|
|
||||||
fun getQuote( id : Int): Quote?
|
fun getQuote( id : Int): Quote?
|
||||||
|
|
||||||
fun isFavorite(id : Int): Boolean
|
fun isFavorite(id : Int, user: User): Boolean
|
||||||
|
fun getAllFavorite(): List<Favorite>
|
||||||
|
fun getAllQuote(): List<Quote>
|
||||||
|
|
||||||
fun search(type : String ,search:String ,indexCount: Int): List<Quote>
|
fun search(type : String ,search:String ,indexCount: Int): List<Quote>
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,174 @@
|
|||||||
|
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.material3.MaterialTheme
|
||||||
|
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: () -> Unit,
|
||||||
|
navAccueil: () -> Unit,
|
||||||
|
navProfil:() -> Unit,
|
||||||
|
navQuiz: () -> Unit,
|
||||||
|
navSearch: () -> Unit,
|
||||||
|
quoteContent : String,
|
||||||
|
character: String,
|
||||||
|
source: String
|
||||||
|
) {
|
||||||
|
NavBar(
|
||||||
|
navControllerFavorite = navFavorite,
|
||||||
|
navControllerAccueil = navAccueil,
|
||||||
|
navControllerProfil = navProfil,
|
||||||
|
navControllerQuiz = navQuiz,
|
||||||
|
navControllerSearch = navSearch
|
||||||
|
) {
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.background)
|
||||||
|
) {
|
||||||
|
// Contenu princiapl
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(0.9f)
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(20.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "▶ Recap de la citation ◀",
|
||||||
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
|
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 QuoteText2(text: String ){
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
modifier = Modifier.padding(start = 10.dp, top = 15.dp),
|
||||||
|
fontWeight = FontWeight(1000),
|
||||||
|
fontSize = 20.sp,
|
||||||
|
color = MaterialTheme.colorScheme.background
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ImageQuote2(imageUrl : String){
|
||||||
|
AsyncImage(
|
||||||
|
model = imageUrl,
|
||||||
|
contentDescription = "exemple",
|
||||||
|
modifier = Modifier
|
||||||
|
.size(150.dp)
|
||||||
|
.clip(RoundedCornerShape(15.dp))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun InfoQuoteText2(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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,262 @@
|
|||||||
package com.example.what_the_fantasy.ui.screens
|
package com.example.what_the_fantasy.ui.screens
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.gestures.scrollable
|
||||||
|
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.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
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.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
|
@Composable
|
||||||
fun SubmitQuotePage() {
|
fun SubmitQuotePage(
|
||||||
}
|
navFavorite: () -> Unit,
|
||||||
|
navAccueil: () -> Unit,
|
||||||
|
navProfil:() -> Unit,
|
||||||
|
navQuiz: () -> Unit,
|
||||||
|
navRecap: (String, String, String) -> Unit
|
||||||
|
) {
|
||||||
|
NavBar(
|
||||||
|
navControllerFavorite = navFavorite,
|
||||||
|
navControllerAccueil = navAccueil,
|
||||||
|
navControllerProfil = navProfil,
|
||||||
|
navControllerQuiz = navQuiz
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.background)
|
||||||
|
.verticalScroll(rememberScrollState()),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
){
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(0.9f)
|
||||||
|
.padding(20.dp)
|
||||||
|
.clip(RoundedCornerShape(16.dp))
|
||||||
|
.background(MaterialTheme.colorScheme.onPrimary)
|
||||||
|
.padding(20.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
TitlePageComponent(R.string.titleSubmitQuote, MaterialTheme.colorScheme.onBackground)
|
||||||
|
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,
|
||||||
|
MaterialTheme.colorScheme.background,
|
||||||
|
MaterialTheme.colorScheme.onBackground,
|
||||||
|
navRecap
|
||||||
|
)
|
||||||
|
SpaceHeightComponent(20)
|
||||||
|
BackButton(R.string.titleButtonBack, 12, Color.White,navProfil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 = MaterialTheme.colorScheme.onBackground) },
|
||||||
|
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 = MaterialTheme.colorScheme.onBackground) },
|
||||||
|
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 = MaterialTheme.colorScheme.onBackground) },
|
||||||
|
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 = MaterialTheme.colorScheme.onBackground) },
|
||||||
|
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 = MaterialTheme.colorScheme.onBackground) },
|
||||||
|
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 quoteRegex = """^[A-Za-zÀ-ÿ0-9\s\-\.,!?'"()]+$""".toRegex()
|
||||||
|
val timeCodeRegex = """^\d{1}:\d{2}:\d{2}$""".toRegex()
|
||||||
|
val movieTitleRegex = """^[A-Za-z0-9\s\-\(\):]+$""".toRegex()
|
||||||
|
val characterRegex = """^[A-Za-zÀ-ÿ\s\-']+$""".toRegex()
|
||||||
|
val invalidRegex = """^[a-zA-Z0-9]*$""".toRegex()
|
||||||
|
|
||||||
|
val isNotBlank = quote.isNotBlank() && quote.matches(quoteRegex) && !quote.matches(invalidRegex) && quote.length in 3..100 &&
|
||||||
|
character.isNotBlank() && character.matches(characterRegex) && character.length in 3..50 && /*!character.matches(invalidRegex) &&*/
|
||||||
|
source.isNotBlank() && source.matches(movieTitleRegex) && source.length in 3..50 && /*!source.matches(invalidRegex) &&*/
|
||||||
|
timeCode.isNotBlank() && timeCode.matches(timeCodeRegex) &&
|
||||||
|
year.isNotBlank() && year.all { it.isDigit() } && year.length == 4 && year.toInt() in 1900..2025
|
||||||
|
return isNotBlank
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun BackButton(titleResId : Int, size : Int, color : Color, navController: () -> Unit) {
|
||||||
|
val title = stringResource(id = titleResId)
|
||||||
|
Text(
|
||||||
|
text = title,
|
||||||
|
fontSize = size.sp,
|
||||||
|
color = color,
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
navController()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in new issue