|
|
@ -1,6 +1,7 @@
|
|
|
|
package com.example.mathseduc
|
|
|
|
package com.example.mathseduc
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Context
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
@ -8,16 +9,28 @@ import android.view.ViewGroup
|
|
|
|
import android.widget.ArrayAdapter
|
|
|
|
import android.widget.ArrayAdapter
|
|
|
|
import android.widget.ListView
|
|
|
|
import android.widget.ListView
|
|
|
|
import android.widget.TextView
|
|
|
|
import android.widget.TextView
|
|
|
|
|
|
|
|
import androidx.activity.OnBackPressedCallback
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import com.example.mathseduc.controllers.ControllerLobby
|
|
|
|
import com.example.mathseduc.controllers.ControllerLobby
|
|
|
|
import com.example.mathseduc.controllers.ControllerPlayer
|
|
|
|
import com.example.mathseduc.controllers.ControllerPlayer
|
|
|
|
import com.example.mathseduc.controllers.ControllerUtiliser
|
|
|
|
import com.example.mathseduc.controllers.ControllerUtiliser
|
|
|
|
import com.example.mathseduc.models.Player
|
|
|
|
import com.example.mathseduc.models.Player
|
|
|
|
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
import okhttp3.MultipartBody
|
|
|
|
import okhttp3.MultipartBody
|
|
|
|
|
|
|
|
|
|
|
|
class ServerDetailsActivity : AppCompatActivity() {
|
|
|
|
class ServerDetailsActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var playerList: List<Player> = emptyList()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
|
|
|
|
|
|
|
|
override fun handleOnBackPressed() {
|
|
|
|
|
|
|
|
MyBackPressed()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
|
|
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
|
|
|
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_server_details)
|
|
|
|
setContentView(R.layout.activity_server_details)
|
|
|
|
|
|
|
|
|
|
|
|
val serverName = intent.getStringExtra("serverName")
|
|
|
|
val serverName = intent.getStringExtra("serverName")
|
|
|
@ -27,38 +40,51 @@ class ServerDetailsActivity : AppCompatActivity() {
|
|
|
|
serverNameTextView.text = serverName
|
|
|
|
serverNameTextView.text = serverName
|
|
|
|
|
|
|
|
|
|
|
|
val lobbyId = intent.getIntExtra("lobbyId", -1)
|
|
|
|
val lobbyId = intent.getIntExtra("lobbyId", -1)
|
|
|
|
val playerIds = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId)
|
|
|
|
|
|
|
|
if (playerIds != null) {
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
val playerList = playerIds.mapNotNull { playerId ->
|
|
|
|
playerList = savedInstanceState?.getParcelableArrayList("playerList") ?: emptyList() //TODO deprecated c'est pas normal !!!
|
|
|
|
ControllerPlayer.getPlayerInfoById(playerId.toString())
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Si l'état d'instance est nul, récupérez la liste des joueurs normalement
|
|
|
|
|
|
|
|
val playerId = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId)
|
|
|
|
|
|
|
|
if (playerId != null) {
|
|
|
|
|
|
|
|
playerList = playerId.mapNotNull { playerId ->
|
|
|
|
|
|
|
|
ControllerPlayer.getPlayerInfoById(playerId.toString())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val listViewPlayers = findViewById<ListView>(R.id.listViewPlayers)
|
|
|
|
|
|
|
|
val playerAdapter = PlayerAdapter(this, playerList)
|
|
|
|
|
|
|
|
listViewPlayers.adapter = playerAdapter
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val listViewPlayers = findViewById<ListView>(R.id.listViewPlayers)
|
|
|
|
|
|
|
|
val playerAdapter = PlayerAdapter(this, playerList)
|
|
|
|
|
|
|
|
listViewPlayers.adapter = playerAdapter
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
|
|
|
|
|
|
|
super.onSaveInstanceState(outState)
|
|
|
|
|
|
|
|
// Save the player list to the instance state
|
|
|
|
|
|
|
|
outState.putParcelableArrayList("playerList", ArrayList(playerList))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onStop() {
|
|
|
|
private fun MyBackPressed() {
|
|
|
|
super.onStop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val lobbyId = intent.getIntExtra("lobbyId", -1)
|
|
|
|
val lobbyId = intent.getIntExtra("lobbyId", -1)
|
|
|
|
|
|
|
|
|
|
|
|
ControllerUtiliser.DeleteUtiliserForLobby(MainActivity.idPlayerConnected,lobbyId)
|
|
|
|
ControllerUtiliser.DeleteUtiliserForLobby(MainActivity.idPlayerConnected, lobbyId)
|
|
|
|
|
|
|
|
|
|
|
|
if(ControllerLobby.PlayerCreatorIdPresentInLobby(MainActivity.idPlayerConnected,lobbyId)){
|
|
|
|
if (ControllerLobby.PlayerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId)) {
|
|
|
|
|
|
|
|
|
|
|
|
val idNextPlayerCreator = ControllerUtiliser.getIdNextPlayerInLobby(lobbyId)
|
|
|
|
val idNextPlayerCreator = ControllerUtiliser.getIdNextPlayerInLobby(lobbyId)
|
|
|
|
|
|
|
|
|
|
|
|
if (idNextPlayerCreator == -1){
|
|
|
|
if (idNextPlayerCreator == -1) {
|
|
|
|
ControllerLobby.deleteLobby(lobbyId)
|
|
|
|
ControllerLobby.deleteLobby(lobbyId)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
|
|
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
|
|
|
|
|
|
|
|
|
|
formDataBuilder.addFormDataPart("idplayercreator", idNextPlayerCreator.toString())
|
|
|
|
formDataBuilder.addFormDataPart("idplayercreator", idNextPlayerCreator.toString())
|
|
|
|
|
|
|
|
|
|
|
|
ControllerLobby.updateLobbyIdCreatorLobby(lobbyId,formDataBuilder)
|
|
|
|
ControllerLobby.updateLobbyIdCreatorLobby(lobbyId, formDataBuilder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PlayerAdapter(context: Context, players: List<Player>) :
|
|
|
|
class PlayerAdapter(context: Context, players: List<Player>) :
|
|
|
|