|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
package com.example.mathseduc
|
|
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.os.Handler
|
|
|
|
|
import android.os.Looper
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
|
import androidx.activity.OnBackPressedCallback
|
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
@ -146,30 +147,31 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
val refreshRunnable = object : Runnable {
|
|
|
|
|
override fun run() {
|
|
|
|
|
playerList = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString())!!
|
|
|
|
|
handler.post(this)
|
|
|
|
|
|
|
|
|
|
if (playerList != null) {
|
|
|
|
|
playerListInfos = playerList.mapNotNull { playerId ->
|
|
|
|
|
ControllerPlayer.getPlayerInfoById(playerId.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId!!.toInt())
|
|
|
|
|
Toast.makeText(context, "TOTO", Toast.LENGTH_SHORT).show()
|
|
|
|
|
isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId)
|
|
|
|
|
|
|
|
|
|
if(ControllerLobby.lobbyIsLaunched(lobbyId)){
|
|
|
|
|
val intent = Intent(context, QuizMultiActivity::class.java)
|
|
|
|
|
intent.putExtra("lobbyId", lobbyId)
|
|
|
|
|
context.startActivity(intent)
|
|
|
|
|
refreshState = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ControllerLobby.lobbyIsLaunched(lobbyId!!.toInt())){
|
|
|
|
|
//val intent = Intent(this@ServerDetailsActivity, QuizMultiActivity::class.java)
|
|
|
|
|
//intent.putExtra("lobbyId", lobbyId)
|
|
|
|
|
//startActivity(intent)
|
|
|
|
|
Toast.makeText(context, isCreator.toString(), Toast.LENGTH_SHORT).show()
|
|
|
|
|
return
|
|
|
|
|
if (refreshState){
|
|
|
|
|
handler.postDelayed(this,3000)
|
|
|
|
|
Log.e("MainActivity", "Refresh ServerDetails")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handler.postDelayed(refreshRunnable, 2000)
|
|
|
|
|
handler.post(refreshRunnable)
|
|
|
|
|
|
|
|
|
|
onDispose {
|
|
|
|
|
refreshState = false
|
|
|
|
|
handler.removeCallbacks(refreshRunnable)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -203,9 +205,11 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isCreator) {
|
|
|
|
|
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
|
|
|
formDataBuilder.addFormDataPart("launched", "1")
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
Toast.makeText(context, "TOTOGOGOCREATOR", Toast.LENGTH_SHORT).show()
|
|
|
|
|
ControllerLobby.updateLobbyLauched(lobbyId,formDataBuilder)
|
|
|
|
|
},
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
enabled = isCreator,
|
|
|
|
|