feat : ajout de l'utilisation du bouton retour avec fonctionnalités + fix lag sur l'application
continuous-integration/drone/push Build is passing Details

androidCompose
Jeremy DUCOURTHIAL 1 year ago
parent a628d77a11
commit 3c7f0a02c4

@ -1,6 +1,7 @@
package com.example.mathseduc package com.example.mathseduc
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable

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

@ -57,15 +57,21 @@ fun MultiPage() {
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
val refreshRunnable = object : Runnable { val refreshRunnable = object : Runnable {
override fun run() { override fun run() {
lobbyList = emptyList()
lobbyList = ControllerLobby.getLobbies()!! lobbyList = ControllerLobby.getLobbies()!!
selectedItem = null selectedItem = null
handler.postDelayed(this, 3000) if (refreshState){
handler.postDelayed(this,3000)
Log.e("MainActivity", "Refresh Multi")
}
} }
} }
handler.post(refreshRunnable) handler.postDelayed(refreshRunnable, 3000)
onDispose { onDispose {
Toast.makeText(context, "TOTO", Toast.LENGTH_SHORT).show()
refreshState = false
handler.removeCallbacks(refreshRunnable) handler.removeCallbacks(refreshRunnable)
} }
} }
@ -108,9 +114,10 @@ fun MultiPage() {
.weight(1f) .weight(1f)
.padding(start = 20.dp) .padding(start = 20.dp)
) )
Button( Button(
onClick = { onClick = {
refreshState = false
val intent = Intent(context, CreateLobbyActivity::class.java) val intent = Intent(context, CreateLobbyActivity::class.java)
context.startActivity(intent) context.startActivity(intent)
}, },
@ -157,6 +164,8 @@ fun MultiPage() {
@Composable @Composable
fun LobbyItem(lobby: Lobby, isSelected: Boolean, onItemClick: (Lobby) -> Unit) { fun LobbyItem(lobby: Lobby, isSelected: Boolean, onItemClick: (Lobby) -> Unit) {
val nbCurrentPlayer = ControllerLobby.getNbPlayerInLobby(lobby.id)
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()

Loading…
Cancel
Save