feat : ajout MultiPageViewModel utilisable
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
5382e21c65
commit
a1665f119c
@ -0,0 +1,37 @@
|
|||||||
|
package com.example.mathseduc.viewModel
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import com.example.mathseduc.controllers.ControllerLobby
|
||||||
|
import com.example.mathseduc.controllers.ControllerPlayer
|
||||||
|
import com.example.mathseduc.models.Lobby
|
||||||
|
import com.example.mathseduc.models.Player
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
class MultiPageViewModel : ViewModel() {
|
||||||
|
|
||||||
|
private var lobbyListState = MutableStateFlow<List<Lobby>>(emptyList())
|
||||||
|
val lobbyList : StateFlow<List<Lobby>> = lobbyListState
|
||||||
|
|
||||||
|
/*
|
||||||
|
var isCreator by rememberSaveable { mutableStateOf(false) }
|
||||||
|
var playerListInfos: List<Player> by rememberSaveable { mutableStateOf(emptyList()) }
|
||||||
|
var playerList by rememberSaveable { mutableStateOf(ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString()) ?: emptyList()) }
|
||||||
|
var refreshState by rememberSaveable { mutableStateOf(true) }
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
fun updateLobbyList() {
|
||||||
|
this.lobbyListState.update {
|
||||||
|
ControllerLobby.getLobbies() ?: emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getNbPlayerInLobby(selectedItem : Lobby) : Int {
|
||||||
|
return ControllerLobby.getNbPlayerInLobby(selectedItem!!.id)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.example.mathseduc.viewModel
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import com.example.mathseduc.controllers.ControllerLobby
|
||||||
|
import com.example.mathseduc.models.Lobby
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
class ServerDetailsViewModel : ViewModel() {
|
||||||
|
|
||||||
|
private var lobbyListState = MutableStateFlow<List<Lobby>>(emptyList())
|
||||||
|
val lobbyList : StateFlow<List<Lobby>> = lobbyListState
|
||||||
|
|
||||||
|
fun updateLobbyList() {
|
||||||
|
this.lobbyListState.update {
|
||||||
|
ControllerLobby.getLobbies() ?: emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getNbPlayerInLobby(selectedItem : Lobby) : Int {
|
||||||
|
return ControllerLobby.getNbPlayerInLobby(selectedItem!!.id)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue