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
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable

@ -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 onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
myBackPressed()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
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,11 +202,13 @@ class ServerDetailsActivity : ComponentActivity() {
)
}
}
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()
@ -219,3 +223,4 @@ class ServerDetailsActivity : ComponentActivity() {
}
}
}
}

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

Loading…
Cancel
Save