ajout toast au clic d'une reponse

pull/24/head
Victor SOULIER 1 year ago
parent 13f09af49a
commit 9955393b50

@ -1,14 +1,22 @@
package fr.iut.sciencequest.view.games package fr.iut.sciencequest.view.games
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material3.Button
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import fr.iut.sciencequest.R import fr.iut.sciencequest.R
import fr.iut.sciencequest.model.dto.question.QuestionWithSimpleResponseDTO import fr.iut.sciencequest.model.dto.question.QuestionWithSimpleResponseDTO
import fr.iut.sciencequest.model.dto.reponse.ReponseSimpleDTO import fr.iut.sciencequest.model.dto.reponse.ReponseSimpleDTO
@ -39,19 +47,25 @@ fun KahootPlayerPreview(){
@Composable @Composable
fun KahootPlayer(question: QuestionWithSimpleResponseDTO){ fun KahootPlayer(question: QuestionWithSimpleResponseDTO){
Column { val context = LocalContext.current;
Column (horizontalAlignment = Alignment.CenterHorizontally){
KahootQuestion(question = question.question) KahootQuestion(question = question.question)
KahootReponses(reponses = question.reponses) KahootReponses(reponses = question.reponses) {Toast.makeText(context, it.reponse, Toast.LENGTH_SHORT).show()}
} }
} }
@Composable @Composable
fun KahootReponses(reponses : List<ReponseSimpleDTO>) { fun KahootReponses(reponses : List<ReponseSimpleDTO>, action: (ReponseSimpleDTO)->Unit) {
LazyVerticalGrid(columns = GridCells.Fixed(2)) { LazyVerticalGrid(columns = GridCells.Fixed(2),
contentPadding = PaddingValues(12.dp),
verticalArrangement = Arrangement.spacedBy(10.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp)) {
reponses.forEach { reponses.forEach {
item() { item() {
Text(it.reponse) Button(onClick = {action(it)}){
Text(it.reponse)
}
} }
} }
} }
@ -59,5 +73,5 @@ fun KahootReponses(reponses : List<ReponseSimpleDTO>) {
@Composable @Composable
fun KahootQuestion(question: String){ fun KahootQuestion(question: String){
Text(question) Text(question, textAlign = TextAlign.Center)
} }
Loading…
Cancel
Save