|
|
|
@ -7,7 +7,6 @@ import android.widget.Toast
|
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
|
import androidx.activity.OnBackPressedCallback
|
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
@ -28,7 +27,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.draw.clip
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
|
@ -47,14 +45,17 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
private val handler = Handler(Looper.getMainLooper())
|
|
|
|
|
private val refreshInterval: Long = 2000
|
|
|
|
|
|
|
|
|
|
private val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
|
|
|
|
|
override fun handleOnBackPressed() {
|
|
|
|
|
myBackPressed()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
|
|
|
|
val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
|
|
|
|
|
override fun handleOnBackPressed() {
|
|
|
|
|
myBackPressed()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
|
|
|
|
|
|
|
|
|
setContent {
|
|
|
|
|
ServerDetailPage()
|
|
|
|
|
}
|
|
|
|
@ -134,8 +135,8 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
|
|
|
|
|
val lobbyName = intent.getStringExtra("serverName")
|
|
|
|
|
val lobbyId = intent.getIntExtra("lobbyId",-1)
|
|
|
|
|
var isCreator = false
|
|
|
|
|
|
|
|
|
|
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) }
|
|
|
|
@ -145,7 +146,7 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
val refreshRunnable = object : Runnable {
|
|
|
|
|
override fun run() {
|
|
|
|
|
playerList = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString())!!
|
|
|
|
|
handler.postDelayed(this, 2000)
|
|
|
|
|
handler.post(this)
|
|
|
|
|
|
|
|
|
|
if (playerList != null) {
|
|
|
|
|
playerListInfos = playerList.mapNotNull { playerId ->
|
|
|
|
@ -154,12 +155,13 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId!!.toInt())
|
|
|
|
|
Toast.makeText(context, "TOTO", Toast.LENGTH_SHORT).show()
|
|
|
|
|
|
|
|
|
|
if(ControllerLobby.lobbyIsLaunched(lobbyId!!.toInt())){
|
|
|
|
|
//val intent = Intent(this@ServerDetailsActivity, QuizMultiActivity::class.java)
|
|
|
|
|
//intent.putExtra("lobbyId", lobbyId)
|
|
|
|
|
//startActivity(intent)
|
|
|
|
|
Toast.makeText(context, "TOTOGOGO", Toast.LENGTH_SHORT).show()
|
|
|
|
|
Toast.makeText(context, isCreator.toString(), Toast.LENGTH_SHORT).show()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -200,21 +202,24 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
Toast.makeText(context, "TOTOGOGOCREATOR", Toast.LENGTH_SHORT).show()
|
|
|
|
|
},
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Green),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp)
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = "LAUNCH",
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
)
|
|
|
|
|
if (isCreator) {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
Toast.makeText(context, "TOTOGOGOCREATOR", Toast.LENGTH_SHORT).show()
|
|
|
|
|
},
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
enabled = isCreator,
|
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Green),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp)
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = "LAUNCH",
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|