[ADD] Kahoot fonctionne avec partie (push tres atomique)
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
0032bedb05
commit
8bc7609765
@ -0,0 +1,27 @@
|
|||||||
|
package fr.iut.sciencequest.model.buisness
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.partie.LaunchedPartieDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.partie.PartieKahootDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.partie.NouvellePartieDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.question.QuestionPartieDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.reponse.ReponseInfoDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.reponseValidityDTO
|
||||||
|
import retrofit2.http.Body
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.POST
|
||||||
|
import retrofit2.http.Path
|
||||||
|
import retrofit2.http.Query
|
||||||
|
|
||||||
|
interface KahootPartieRequestService {
|
||||||
|
@POST("partie/kahoot")
|
||||||
|
suspend fun createPartie(@Body gameInfo: NouvellePartieDTO): PartieKahootDTO
|
||||||
|
|
||||||
|
@POST("partie/kahoot/{codePartie}/demarrer")
|
||||||
|
suspend fun launchPartie(@Path("codePartie") code: String): LaunchedPartieDTO
|
||||||
|
|
||||||
|
@GET("partie/kahoot/{codePartie}/question")
|
||||||
|
suspend fun getQuestionFromPartie(@Path("codePartie") code: String): QuestionPartieDTO
|
||||||
|
|
||||||
|
@POST("partie/kahoot/{codeInvitation}/reponse")
|
||||||
|
suspend fun postResponse(@Path("codeInvitation") code:String, @Body reponseInfo: ReponseInfoDTO): reponseValidityDTO
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.extensions
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.JeuDTO
|
||||||
|
import fr.iut.sciencequest.model.metier.Jeu
|
||||||
|
|
||||||
|
fun JeuDTO.toModel(): Jeu {
|
||||||
|
return Jeu(
|
||||||
|
this.id,
|
||||||
|
this.nom,
|
||||||
|
this.nbrParties
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.extensions
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.joueur.JoueurSimpleDTO
|
||||||
|
import fr.iut.sciencequest.model.metier.joueur.JoueurSimple
|
||||||
|
|
||||||
|
fun JoueurSimpleDTO.toModel(): JoueurSimple {
|
||||||
|
return JoueurSimple(
|
||||||
|
this.id,
|
||||||
|
this.pseudo
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun List<JoueurSimpleDTO>.toModel(): List<JoueurSimple> {
|
||||||
|
val liste = mutableListOf<JoueurSimple>()
|
||||||
|
for (joueur in this) {
|
||||||
|
liste.add(joueur.toModel())
|
||||||
|
}
|
||||||
|
return liste
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.extensions
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.partie.PartieDTO
|
||||||
|
import fr.iut.sciencequest.model.metier.partie.Partie
|
||||||
|
|
||||||
|
fun PartieDTO.toModel(): Partie {
|
||||||
|
return Partie(
|
||||||
|
this.id,
|
||||||
|
this.codeInvitation,
|
||||||
|
this.joueurs.toModel(),
|
||||||
|
this.jeu.toModel(),
|
||||||
|
this.thematiques.toModel()
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.extensions
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.partie.PartieKahootDTO
|
||||||
|
import fr.iut.sciencequest.model.metier.partie.PartieKahoot
|
||||||
|
|
||||||
|
fun PartieKahootDTO.toModel(): PartieKahoot {
|
||||||
|
return PartieKahoot(
|
||||||
|
this.id,
|
||||||
|
this.code,
|
||||||
|
this.thematiques.toModel(),
|
||||||
|
this.joueurs.toModel(),
|
||||||
|
this.difficulte.ToModel()
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.extensions
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.question.QuestionPartieDTO
|
||||||
|
import fr.iut.sciencequest.model.metier.question.QuestionPartie
|
||||||
|
import kotlinx.datetime.Instant
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
import kotlinx.datetime.TimeZone
|
||||||
|
import kotlinx.datetime.toInstant
|
||||||
|
|
||||||
|
fun QuestionPartieDTO.toModel(): QuestionPartie {
|
||||||
|
var limite: Instant
|
||||||
|
if (this.limitTime == null) {
|
||||||
|
limite = LocalDateTime(1,1,1,1,1,1,1).toInstant(TimeZone.UTC)
|
||||||
|
} else {
|
||||||
|
limite = Instant.parse(this.limitTime)
|
||||||
|
}
|
||||||
|
return QuestionPartie(
|
||||||
|
this.question?.ToModel(),
|
||||||
|
limite
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.joueur
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.metier.joueur.JoueurSimple
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class JoueurScoreDTO (
|
||||||
|
val joueur: JoueurSimpleDTO,
|
||||||
|
val score: Int
|
||||||
|
)
|
@ -1,5 +1,8 @@
|
|||||||
package fr.iut.sciencequest.model.dto.joueur
|
package fr.iut.sciencequest.model.dto.joueur
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
class JoueurSimpleDTO (
|
class JoueurSimpleDTO (
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val pseudo: String,
|
val pseudo: String,
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.partie
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.joueur.JoueurScoreDTO
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class LaunchedPartieDTO (
|
||||||
|
val status: String,
|
||||||
|
val scores: List<JoueurScoreDTO>
|
||||||
|
)
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.partie
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class NouvellePartieDTO (
|
||||||
|
val idJoueur: Int,
|
||||||
|
val thematiques: List<Int>,
|
||||||
|
val idDifficulte: Int
|
||||||
|
)
|
@ -1,5 +1,7 @@
|
|||||||
package fr.iut.sciencequest.model.dto
|
package fr.iut.sciencequest.model.dto.partie
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.JeuDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.ThematiqueDTO
|
||||||
import fr.iut.sciencequest.model.dto.joueur.JoueurSimpleDTO
|
import fr.iut.sciencequest.model.dto.joueur.JoueurSimpleDTO
|
||||||
|
|
||||||
class PartieDTO (
|
class PartieDTO (
|
@ -0,0 +1,17 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.partie
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.ThematiqueDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.difficulte.DifficulteDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.joueur.JoueurSimpleDTO
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class PartieKahootDTO (
|
||||||
|
val id: Int,
|
||||||
|
@SerialName("codeInvitation")
|
||||||
|
val code: String,
|
||||||
|
val thematiques: List<ThematiqueDTO>,
|
||||||
|
val joueurs: List<JoueurSimpleDTO>,
|
||||||
|
val difficulte: DifficulteDTO
|
||||||
|
)
|
@ -0,0 +1,12 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.question
|
||||||
|
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class QuestionPartieDTO (
|
||||||
|
@SerialName("questionActuel")
|
||||||
|
val question: QuestionWithSimpleResponseDTO?,
|
||||||
|
@SerialName("tempsLimiteReponse")
|
||||||
|
val limitTime: String?
|
||||||
|
)
|
@ -0,0 +1,9 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto.reponse
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class ReponseInfoDTO (
|
||||||
|
val idJoueur: Int,
|
||||||
|
val idReponse: Int
|
||||||
|
)
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.iut.sciencequest.model.dto
|
||||||
|
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class reponseValidityDTO (
|
||||||
|
@SerialName("estValide")
|
||||||
|
val isValid: Boolean
|
||||||
|
)
|
@ -0,0 +1,7 @@
|
|||||||
|
package fr.iut.sciencequest.model.metier
|
||||||
|
|
||||||
|
class Jeu (
|
||||||
|
val id: Int,
|
||||||
|
val nom: String,
|
||||||
|
val nbrParties: UInt
|
||||||
|
)
|
@ -0,0 +1,6 @@
|
|||||||
|
package fr.iut.sciencequest.model.metier.joueur
|
||||||
|
|
||||||
|
class JoueurSimple (
|
||||||
|
val id: Int,
|
||||||
|
val pseudo: String
|
||||||
|
)
|
@ -0,0 +1,13 @@
|
|||||||
|
package fr.iut.sciencequest.model.metier.partie
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.metier.Jeu
|
||||||
|
import fr.iut.sciencequest.model.metier.Thematique
|
||||||
|
import fr.iut.sciencequest.model.metier.joueur.JoueurSimple
|
||||||
|
|
||||||
|
class Partie (
|
||||||
|
val id: Int,
|
||||||
|
val codeInvitation: String,
|
||||||
|
val joueurs: List<JoueurSimple>,
|
||||||
|
val jeu: Jeu,
|
||||||
|
val thematiques: List<Thematique>
|
||||||
|
)
|
@ -0,0 +1,13 @@
|
|||||||
|
package fr.iut.sciencequest.model.metier.partie
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.metier.Difficulte
|
||||||
|
import fr.iut.sciencequest.model.metier.Thematique
|
||||||
|
import fr.iut.sciencequest.model.metier.joueur.JoueurSimple
|
||||||
|
|
||||||
|
class PartieKahoot (
|
||||||
|
val id: Int,
|
||||||
|
val code: String,
|
||||||
|
val thematiques: List<Thematique>,
|
||||||
|
val joueurs: List<JoueurSimple>,
|
||||||
|
val difficulte: Difficulte
|
||||||
|
)
|
@ -0,0 +1,9 @@
|
|||||||
|
package fr.iut.sciencequest.model.metier.question
|
||||||
|
|
||||||
|
import kotlinx.datetime.Instant
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
|
||||||
|
class QuestionPartie (
|
||||||
|
val question: QuestionWithSimpleReponse?,
|
||||||
|
val date: Instant
|
||||||
|
)
|
@ -0,0 +1,18 @@
|
|||||||
|
package fr.iut.sciencequest.model.repositories.kahootPartie
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.dto.partie.NouvellePartieDTO
|
||||||
|
import fr.iut.sciencequest.model.metier.partie.PartieKahoot
|
||||||
|
import fr.iut.sciencequest.model.metier.question.QuestionPartie
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
|
interface IKahootPartieRepository {
|
||||||
|
val partie: StateFlow<PartieKahoot>
|
||||||
|
val question: StateFlow<QuestionPartie>
|
||||||
|
val isStarted: StateFlow<Boolean>
|
||||||
|
val isReponseValid: StateFlow<Boolean>
|
||||||
|
|
||||||
|
suspend fun createPartie(nvPartie: NouvellePartieDTO)
|
||||||
|
suspend fun startPartie(code: String)
|
||||||
|
suspend fun getQuestion(code: String)
|
||||||
|
suspend fun postReponse(code: String, idJoueur: Int, idReponse: Int)
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package fr.iut.sciencequest.model.repositories.kahootPartie
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import fr.iut.sciencequest.model.buisness.KahootPartieRequestService
|
||||||
|
import fr.iut.sciencequest.model.buisness.createRequestService
|
||||||
|
import fr.iut.sciencequest.model.dto.extensions.toModel
|
||||||
|
import fr.iut.sciencequest.model.dto.partie.NouvellePartieDTO
|
||||||
|
import fr.iut.sciencequest.model.dto.reponse.ReponseInfoDTO
|
||||||
|
import fr.iut.sciencequest.model.metier.Difficulte
|
||||||
|
import fr.iut.sciencequest.model.metier.partie.PartieKahoot
|
||||||
|
import fr.iut.sciencequest.model.metier.question.QuestionPartie
|
||||||
|
import fr.iut.sciencequest.model.metier.question.QuestionWithSimpleReponse
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
import kotlinx.datetime.TimeZone
|
||||||
|
import kotlinx.datetime.toInstant
|
||||||
|
import retrofit2.create
|
||||||
|
|
||||||
|
class KahootAPIRepository: IKahootPartieRepository {
|
||||||
|
|
||||||
|
private val _partie = MutableStateFlow(PartieKahoot(0,"", emptyList(),emptyList(), Difficulte(0,"")))
|
||||||
|
override val partie: StateFlow<PartieKahoot>
|
||||||
|
get() = _partie.asStateFlow()
|
||||||
|
|
||||||
|
private val _question = MutableStateFlow(QuestionPartie(QuestionWithSimpleReponse(0,"", emptyList()), LocalDateTime(1,1,1,1,1 ).toInstant(
|
||||||
|
TimeZone.UTC)))
|
||||||
|
override val question: StateFlow<QuestionPartie>
|
||||||
|
get() = _question.asStateFlow()
|
||||||
|
|
||||||
|
private val _isStarted = MutableStateFlow(false)
|
||||||
|
override val isStarted: StateFlow<Boolean>
|
||||||
|
get() = _isStarted.asStateFlow()
|
||||||
|
|
||||||
|
private val _isValidResponse = MutableStateFlow(false)
|
||||||
|
override val isReponseValid: StateFlow<Boolean>
|
||||||
|
get() = _isValidResponse.asStateFlow()
|
||||||
|
|
||||||
|
override suspend fun createPartie(nvPartie: NouvellePartieDTO) {
|
||||||
|
val serviceClient = createRequestService().create<KahootPartieRequestService>()
|
||||||
|
try {
|
||||||
|
_partie.value = serviceClient.createPartie(nvPartie).toModel()
|
||||||
|
Log.d("Req partie crea",_partie.value.code)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Requete API Partie crea", e.message.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun startPartie(code: String) {
|
||||||
|
val serviceClient = createRequestService().create<KahootPartieRequestService>()
|
||||||
|
try {
|
||||||
|
val partieStatus = serviceClient.launchPartie(code)
|
||||||
|
_isStarted.value = partieStatus.status == "Started"
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Requete API Partie star", e.message.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getQuestion(code: String) {
|
||||||
|
val serviceClient = createRequestService().create<KahootPartieRequestService>()
|
||||||
|
try {
|
||||||
|
_question.value = serviceClient.getQuestionFromPartie(code).toModel()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Requete API Partie getq", e.message.toString())
|
||||||
|
_question.value = QuestionPartie(
|
||||||
|
question = _question.value.question,
|
||||||
|
date = LocalDateTime(1,1,1,1,1,1,1).toInstant(TimeZone.UTC)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun postReponse(code: String, idJoueur: Int, idReponse: Int) {
|
||||||
|
val serviceClient = createRequestService().create<KahootPartieRequestService>()
|
||||||
|
try {
|
||||||
|
_isValidResponse.value = serviceClient.postResponse(code, ReponseInfoDTO(idJoueur, idReponse)).isValid
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Requete API Partie post", e.message.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package fr.iut.sciencequest.view.games.kahoot
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import fr.iut.sciencequest.R
|
||||||
|
import fr.iut.sciencequest.view.TopBar
|
||||||
|
import fr.iut.sciencequest.viewModels.KahootJoinViewModel
|
||||||
|
import fr.iut.sciencequest.viewModels.KahootViewModel
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MenuKahoot(kahootViewModel: KahootViewModel = viewModel(factory = KahootViewModel.ApiFactory),
|
||||||
|
kahootJoinVM: KahootJoinViewModel = viewModel(),
|
||||||
|
goToAccount: () -> Unit,
|
||||||
|
goToHome: () -> Unit,
|
||||||
|
goToWaiting: (KahootViewModel) -> Unit) {
|
||||||
|
Column(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
TopBar(goToAccount, goToHome, stringResource(id = R.string.kahoot))
|
||||||
|
RejoindreKahootAvecCodeContainer()
|
||||||
|
Button(onClick = { goToWaiting(kahootViewModel) }) {
|
||||||
|
Text("Creer une partie")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package fr.iut.sciencequest.view.games.kahoot
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextField
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import fr.iut.sciencequest.R
|
||||||
|
import fr.iut.sciencequest.viewModels.KahootJoinViewModel
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun RejoindreKahootAvecCodeContainer(kahootJoinVM: KahootJoinViewModel = viewModel()) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
|
||||||
|
) {
|
||||||
|
Text(stringResource(id = R.string.join_game))
|
||||||
|
KahootCodeInputContainer(kahootJoinVM)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun KahootCodeInputContainer(kahootJoinVM: KahootJoinViewModel = viewModel()) {
|
||||||
|
val state = kahootJoinVM.uiState.collectAsState()
|
||||||
|
Column (
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
){
|
||||||
|
TextField(value = state.value.code,
|
||||||
|
onValueChange = {kahootJoinVM.setCode(it)})
|
||||||
|
Button(onClick = { /*TODO*/ }) {
|
||||||
|
Text(text = stringResource(id = R.string.join))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package fr.iut.sciencequest.view.games.kahoot
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import fr.iut.sciencequest.R
|
||||||
|
import fr.iut.sciencequest.view.TopBar
|
||||||
|
import fr.iut.sciencequest.viewModels.KahootJoinViewModel
|
||||||
|
import fr.iut.sciencequest.viewModels.KahootViewModel
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ResultatKahoot(goToAccount: () -> Unit,
|
||||||
|
goToHome: () -> Unit,
|
||||||
|
kahootViewModel: KahootViewModel) {
|
||||||
|
val state = kahootViewModel.uiState.collectAsState()
|
||||||
|
Column(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
TopBar(goToAccount, goToHome, stringResource(id = R.string.kahoot))
|
||||||
|
Column(modifier = Modifier.fillMaxHeight(),
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
|
Text("Vous avez " + state.value.nbPoints + "points")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package fr.iut.sciencequest.view.games.kahoot
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import fr.iut.sciencequest.R
|
||||||
|
import fr.iut.sciencequest.model.metier.joueur.JoueurSimple
|
||||||
|
import fr.iut.sciencequest.view.TopBar
|
||||||
|
import fr.iut.sciencequest.viewModels.KahootJoinViewModel
|
||||||
|
import fr.iut.sciencequest.viewModels.KahootViewModel
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun WaitingScreen(kahootViewModel: KahootViewModel = viewModel(factory = KahootViewModel.ApiFactory),
|
||||||
|
goToAccount: () -> Unit,
|
||||||
|
goToHome: () -> Unit,
|
||||||
|
goToGame: () -> Unit) {
|
||||||
|
val state = kahootViewModel.uiState.collectAsState()
|
||||||
|
Column(modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
|
TopBar(goToAccount, goToHome, stringResource(id = R.string.kahoot))
|
||||||
|
Column {
|
||||||
|
Text(text = stringResource(id = R.string.user_in_game))
|
||||||
|
ListeJoueurs(state.value.partie.joueurs)
|
||||||
|
Button(onClick = { goToGame() }) {
|
||||||
|
Text(stringResource(id = R.string.start_game))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ListeJoueurs(joueurs: List<JoueurSimple>) {
|
||||||
|
for (joueur in joueurs) {
|
||||||
|
JoueurContainer(joueur)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun JoueurContainer(joueur: JoueurSimple) {
|
||||||
|
Row {
|
||||||
|
Text("Pseudo: " + joueur.pseudo)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package fr.iut.sciencequest.viewModels
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import fr.iut.sciencequest.viewModels.uiStates.KahootJoinUIState
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
|
class KahootJoinViewModel : ViewModel() {
|
||||||
|
private val _uiState = MutableStateFlow(KahootJoinUIState())
|
||||||
|
val uiState = _uiState.asStateFlow()
|
||||||
|
|
||||||
|
fun setCode(code: String) {
|
||||||
|
if (code.length >= 6) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_uiState.value = KahootJoinUIState(code)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package fr.iut.sciencequest.viewModels.uiStates
|
||||||
|
|
||||||
|
data class KahootJoinUIState (
|
||||||
|
val code: String = ""
|
||||||
|
)
|
Loading…
Reference in new issue