|
|
|
@ -84,7 +84,7 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
|
|
|
|
|
setContent {
|
|
|
|
|
val navController = rememberNavController()
|
|
|
|
|
ServerDetailPage(navController = navController)
|
|
|
|
|
//ServerDetailPage(navController = navController)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -106,221 +106,215 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
|
}
|
|
|
|
|
finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
|
|
@Composable
|
|
|
|
|
fun ServerDetailPage(navController: NavController, serverName: String?, lobbyId: Int?, chapterId: Int?, nbPlayers: Int?, lobbyDifficulty: Int?) {
|
|
|
|
|
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
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) }
|
|
|
|
|
var showDialog by rememberSaveable { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
val isPortrait = LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT
|
|
|
|
|
val activity = LocalView.current.context as Activity
|
|
|
|
|
val windowInsetsController = remember {
|
|
|
|
|
WindowCompat.getInsetsController(activity.window, activity.window.decorView)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
|
|
@Composable
|
|
|
|
|
fun ServerDetailPage(navController: NavController) {
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
val serverName = intent.getStringExtra("serverName")
|
|
|
|
|
val lobbyId = intent.getIntExtra("lobbyId",-1)
|
|
|
|
|
val chapterId = intent.getIntExtra("chapterId",-1)
|
|
|
|
|
val nbPlayers = intent.getIntExtra("nbPlayers",-1)
|
|
|
|
|
val lobbyDifficulty = intent.getIntExtra("lobbyDifficulty",-1)
|
|
|
|
|
|
|
|
|
|
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) }
|
|
|
|
|
var showDialog by rememberSaveable { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
val isPortrait = LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT
|
|
|
|
|
val activity = LocalView.current.context as Activity
|
|
|
|
|
val windowInsetsController = remember {
|
|
|
|
|
WindowCompat.getInsetsController(activity.window, activity.window.decorView)
|
|
|
|
|
}
|
|
|
|
|
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
|
|
|
|
|
|
|
|
|
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
|
|
|
|
|
|
|
|
|
DisposableEffect(refreshState) {
|
|
|
|
|
val handler = Handler(Looper.getMainLooper())
|
|
|
|
|
val refreshRunnable = object : Runnable {
|
|
|
|
|
override fun run() {
|
|
|
|
|
playerList = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString())!!
|
|
|
|
|
|
|
|
|
|
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
|
|
|
|
|
|
|
|
|
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
|
|
|
|
|
|
|
|
|
DisposableEffect(refreshState) {
|
|
|
|
|
val handler = Handler(Looper.getMainLooper())
|
|
|
|
|
val refreshRunnable = object : Runnable {
|
|
|
|
|
override fun run() {
|
|
|
|
|
playerList = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString())!!
|
|
|
|
|
|
|
|
|
|
playerListInfos = playerList.mapNotNull { playerId ->
|
|
|
|
|
ControllerPlayer.getPlayerInfoById(playerId.toString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId)
|
|
|
|
|
|
|
|
|
|
if(ControllerLobby.lobbyIsLaunched(lobbyId)){
|
|
|
|
|
val intent = Intent(context, QuizMultiActivity::class.java)
|
|
|
|
|
intent.putExtra("serverName", serverName)
|
|
|
|
|
intent.putExtra("lobbyId", lobbyId)
|
|
|
|
|
intent.putExtra("chapterId", chapterId)
|
|
|
|
|
intent.putExtra("nbPlayers", nbPlayers)
|
|
|
|
|
intent.putExtra("lobbyDifficulty", lobbyDifficulty)
|
|
|
|
|
context.startActivity(intent)
|
|
|
|
|
refreshState = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (refreshState){
|
|
|
|
|
handler.postDelayed(this,3000)
|
|
|
|
|
Log.e("MainActivity", "Refresh ServerDetails")
|
|
|
|
|
}
|
|
|
|
|
playerListInfos = playerList.mapNotNull { playerId ->
|
|
|
|
|
ControllerPlayer.getPlayerInfoById(playerId.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handler.post(refreshRunnable)
|
|
|
|
|
isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId!!)
|
|
|
|
|
|
|
|
|
|
if(ControllerLobby.lobbyIsLaunched(lobbyId)){
|
|
|
|
|
val intent = Intent(context, QuizMultiActivity::class.java)
|
|
|
|
|
intent.putExtra("serverName", serverName)
|
|
|
|
|
intent.putExtra("lobbyId", lobbyId)
|
|
|
|
|
intent.putExtra("chapterId", chapterId)
|
|
|
|
|
intent.putExtra("nbPlayers", nbPlayers)
|
|
|
|
|
intent.putExtra("lobbyDifficulty", lobbyDifficulty)
|
|
|
|
|
context.startActivity(intent)
|
|
|
|
|
refreshState = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDispose {
|
|
|
|
|
refreshState = false
|
|
|
|
|
handler.removeCallbacks(refreshRunnable)
|
|
|
|
|
if (refreshState){
|
|
|
|
|
handler.postDelayed(this,3000)
|
|
|
|
|
Log.e("MainActivity", "Refresh ServerDetails")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TopAppBar(
|
|
|
|
|
colors = TopAppBarDefaults.topAppBarColors(
|
|
|
|
|
containerColor = Color.Transparent,
|
|
|
|
|
),
|
|
|
|
|
title = {},
|
|
|
|
|
navigationIcon = {
|
|
|
|
|
IconButton(
|
|
|
|
|
onClick = { showDialog = true },
|
|
|
|
|
modifier = Modifier.size(60.dp)
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Filled.ArrowBack,
|
|
|
|
|
contentDescription = "Retour",
|
|
|
|
|
modifier = Modifier.size(36.dp),
|
|
|
|
|
tint = Color.White
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handler.post(refreshRunnable)
|
|
|
|
|
|
|
|
|
|
onDispose {
|
|
|
|
|
refreshState = false
|
|
|
|
|
handler.removeCallbacks(refreshRunnable)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TopAppBar(
|
|
|
|
|
colors = TopAppBarDefaults.topAppBarColors(
|
|
|
|
|
containerColor = Color.Transparent,
|
|
|
|
|
),
|
|
|
|
|
title = {},
|
|
|
|
|
navigationIcon = {
|
|
|
|
|
IconButton(
|
|
|
|
|
onClick = { showDialog = true },
|
|
|
|
|
modifier = Modifier.size(60.dp)
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Filled.ArrowBack,
|
|
|
|
|
contentDescription = "Retour",
|
|
|
|
|
modifier = Modifier.size(36.dp),
|
|
|
|
|
tint = Color.White
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp, top = 8.dp)
|
|
|
|
|
|
|
|
|
|
Column(
|
|
|
|
|
modifier = modifier,
|
|
|
|
|
verticalArrangement = Arrangement.Center,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = serverName!!,
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontSize = 30.sp,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp, top = 8.dp)
|
|
|
|
|
Spacer(modifier = Modifier.height(if(isPortrait)25.dp else 10.dp))
|
|
|
|
|
|
|
|
|
|
Column(
|
|
|
|
|
modifier = modifier,
|
|
|
|
|
verticalArrangement = Arrangement.Center,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = serverName!!,
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontSize = 30.sp,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
text = "Lobby Settings",
|
|
|
|
|
fontSize = 23.sp,
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
)
|
|
|
|
|
Text(
|
|
|
|
|
text = "Chapter : ${ControllerChapter.getChapterNameById(chapterId!!).toString()}",
|
|
|
|
|
fontSize = 19.sp,
|
|
|
|
|
color = Color.White
|
|
|
|
|
)
|
|
|
|
|
Row {
|
|
|
|
|
Text(
|
|
|
|
|
text = "Players : ${ControllerLobby.getNbPlayerInLobby(lobbyId!!)}/${nbPlayers}",
|
|
|
|
|
fontSize = 19.sp,
|
|
|
|
|
color = (if(ControllerLobby.getNbPlayerInLobby(lobbyId)==nbPlayers) Color.Red else Color.White)
|
|
|
|
|
)
|
|
|
|
|
Spacer(modifier = Modifier.width(40.dp))
|
|
|
|
|
Text(
|
|
|
|
|
text = "Difficulty : $lobbyDifficulty",
|
|
|
|
|
fontSize = 19.sp,
|
|
|
|
|
color = Colors.White,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(if(isPortrait)25.dp else 10.dp))
|
|
|
|
|
Spacer(modifier = Modifier.height(if(isPortrait)30.dp else 10.dp))
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
text = "Player Name",
|
|
|
|
|
fontSize = 19.sp,
|
|
|
|
|
modifier = Modifier.background(Color.Black),
|
|
|
|
|
color = Colors.White,
|
|
|
|
|
)
|
|
|
|
|
Divider(
|
|
|
|
|
color = Color.Gray,
|
|
|
|
|
thickness = 2.dp,
|
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
|
|
)
|
|
|
|
|
LazyColumn(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.weight(0.75f)
|
|
|
|
|
.padding(top = 1.dp),
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
items(playerListInfos) { player ->
|
|
|
|
|
Text(
|
|
|
|
|
text = "Lobby Settings",
|
|
|
|
|
fontSize = 23.sp,
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
)
|
|
|
|
|
Text(
|
|
|
|
|
text = "Chapter : ${ControllerChapter.getChapterNameById(chapterId).toString()}",
|
|
|
|
|
fontSize = 19.sp,
|
|
|
|
|
color = Color.White
|
|
|
|
|
)
|
|
|
|
|
Row {
|
|
|
|
|
Text(
|
|
|
|
|
text = "Players : ${ControllerLobby.getNbPlayerInLobby(lobbyId)}/${nbPlayers}",
|
|
|
|
|
fontSize = 19.sp,
|
|
|
|
|
color = (if(ControllerLobby.getNbPlayerInLobby(lobbyId)==nbPlayers) Color.Red else Color.White)
|
|
|
|
|
)
|
|
|
|
|
Spacer(modifier = Modifier.width(40.dp))
|
|
|
|
|
Text(
|
|
|
|
|
text = "Difficulty : $lobbyDifficulty",
|
|
|
|
|
fontSize = 19.sp,
|
|
|
|
|
color = Colors.White,
|
|
|
|
|
text = player.nickname,
|
|
|
|
|
fontSize = 18.sp,
|
|
|
|
|
color = Colors.White,
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.weight(1f)
|
|
|
|
|
.padding(top = if (isPortrait) 5.dp else 1.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(if(isPortrait)30.dp else 10.dp))
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
text = "Player Name",
|
|
|
|
|
fontSize = 19.sp,
|
|
|
|
|
modifier = Modifier.background(Color.Black),
|
|
|
|
|
color = Colors.White,
|
|
|
|
|
)
|
|
|
|
|
Divider(
|
|
|
|
|
color = Color.Gray,
|
|
|
|
|
thickness = 2.dp,
|
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
|
|
)
|
|
|
|
|
LazyColumn(
|
|
|
|
|
}
|
|
|
|
|
if (isCreator) {
|
|
|
|
|
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
|
|
|
formDataBuilder.addFormDataPart("launched", "1")
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
ControllerLobby.updateLobbyLauched(lobbyId!!,formDataBuilder)
|
|
|
|
|
},
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
enabled = isCreator,
|
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Green),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.weight(0.75f)
|
|
|
|
|
.padding(top = 1.dp),
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp)
|
|
|
|
|
) {
|
|
|
|
|
items(playerListInfos) { player ->
|
|
|
|
|
Text(
|
|
|
|
|
text = player.nickname,
|
|
|
|
|
fontSize = 18.sp,
|
|
|
|
|
color = Colors.White,
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.weight(1f)
|
|
|
|
|
.padding(top = if (isPortrait) 5.dp else 1.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
Text(
|
|
|
|
|
text = "LAUNCH",
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
if (isCreator) {
|
|
|
|
|
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
|
|
|
|
|
formDataBuilder.addFormDataPart("launched", "1")
|
|
|
|
|
}
|
|
|
|
|
if (showDialog) {
|
|
|
|
|
LeaveLobbyDialog(serverName, onConfirmLeave = {navController.navigate("multiplayer")},onCancelLeave = { showDialog = false })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Composable
|
|
|
|
|
fun LeaveLobbyDialog(namelobby: String, onConfirmLeave: () -> Unit, onCancelLeave: () -> Unit) {
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
onDismissRequest = onCancelLeave,
|
|
|
|
|
title = { Text("Confirm leaving lobby") },
|
|
|
|
|
confirmButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
ControllerLobby.updateLobbyLauched(lobbyId,formDataBuilder)
|
|
|
|
|
},
|
|
|
|
|
shape = RoundedCornerShape(15),
|
|
|
|
|
enabled = isCreator,
|
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Green),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp)
|
|
|
|
|
onClick = {
|
|
|
|
|
onConfirmLeave()
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = "LAUNCH",
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
)
|
|
|
|
|
Text("Leave")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (showDialog) {
|
|
|
|
|
LeaveLobbyDialog(serverName, onConfirmLeave = {navController.navigate("multiplayer")},onCancelLeave = { showDialog = false })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Composable
|
|
|
|
|
fun LeaveLobbyDialog(namelobby: String, onConfirmLeave: () -> Unit, onCancelLeave: () -> Unit) {
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
onDismissRequest = onCancelLeave,
|
|
|
|
|
title = { Text("Confirm leaving lobby") },
|
|
|
|
|
confirmButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
onConfirmLeave()
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Text("Leave")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
dismissButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
onCancelLeave()
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Text("Cancel")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
text = {
|
|
|
|
|
Text("Are you sure you want to leave the lobby $namelobby?")
|
|
|
|
|
},
|
|
|
|
|
dismissButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
onCancelLeave()
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Text("Cancel")
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
text = {
|
|
|
|
|
Text("Are you sure you want to leave the lobby $namelobby?")
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|