feat : ServerDetail Navigation
continuous-integration/drone/push Build is passing Details

androidCompose
Yvan CALATAYUD 1 year ago
parent 820ec2b59b
commit fa91413a98

@ -1,9 +1,11 @@
package com.example.mathseduc package com.example.mathseduc
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.example.mathseduc.ui.CreateLobbyPage import com.example.mathseduc.ui.CreateLobbyPage
import com.example.mathseduc.ui.HomePage import com.example.mathseduc.ui.HomePage
import com.example.mathseduc.ui.MultiPage import com.example.mathseduc.ui.MultiPage
@ -17,6 +19,23 @@ fun AppNavigation() {
composable("connexion") { ConnexionPlayerContent(navController) } composable("connexion") { ConnexionPlayerContent(navController) }
composable("multiplayer") { MultiPage(navController) } composable("multiplayer") { MultiPage(navController) }
composable("createLobby") { CreateLobbyPage(navController) } composable("createLobby") { CreateLobbyPage(navController) }
//composable("serverDetails/{serverName}/{lobbyId}") { ServerDetailPage(navController) } composable(
route = "serverDetails/{lobbyName}/{lobbyId}/{lobbyChapter}/{lobbyNbPlayers}/{lobbyDifficulty}",
arguments = listOf(
navArgument("lobbyName") { type = NavType.StringType },
navArgument("lobbyId") { type = NavType.IntType },
navArgument("lobbyChapter") { type = NavType.IntType },
navArgument("lobbyNbPlayers") { type = NavType.IntType },
navArgument("lobbyDifficulty") { type = NavType.IntType }
)
) { backStackEntry ->
val lobbyName = backStackEntry.arguments?.getString("lobbyName")
val lobbyId = backStackEntry.arguments?.getInt("lobbyId")
val lobbyChapter = backStackEntry.arguments?.getInt("lobbyChapter")
val lobbyNbPlayers = backStackEntry.arguments?.getInt("lobbyNbPlayers")
val lobbyDifficulty = backStackEntry.arguments?.getInt("lobbyDifficulty")
ServerDetailPage(navController, lobbyName,lobbyId, lobbyChapter, lobbyNbPlayers, lobbyDifficulty)
}
} }
} }

@ -84,7 +84,7 @@ class ServerDetailsActivity : ComponentActivity() {
setContent { setContent {
val navController = rememberNavController() val navController = rememberNavController()
ServerDetailPage(navController = navController) //ServerDetailPage(navController = navController)
} }
} }
@ -106,17 +106,12 @@ class ServerDetailsActivity : ComponentActivity() {
} }
finish() finish()
} }
}
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun ServerDetailPage(navController: NavController) { fun ServerDetailPage(navController: NavController, serverName: String?, lobbyId: Int?, chapterId: Int?, nbPlayers: Int?, lobbyDifficulty: Int?) {
val context = LocalContext.current
val serverName = intent.getStringExtra("serverName") val context = LocalContext.current
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 isCreator by rememberSaveable { mutableStateOf(false) }
var playerListInfos: List<Player> by rememberSaveable { mutableStateOf(emptyList()) } var playerListInfos: List<Player> by rememberSaveable { mutableStateOf(emptyList()) }
@ -144,7 +139,7 @@ class ServerDetailsActivity : ComponentActivity() {
ControllerPlayer.getPlayerInfoById(playerId.toString()) ControllerPlayer.getPlayerInfoById(playerId.toString())
} }
isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId) isCreator = ControllerLobby.playerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId!!)
if(ControllerLobby.lobbyIsLaunched(lobbyId)){ if(ControllerLobby.lobbyIsLaunched(lobbyId)){
val intent = Intent(context, QuizMultiActivity::class.java) val intent = Intent(context, QuizMultiActivity::class.java)
@ -217,13 +212,13 @@ class ServerDetailsActivity : ComponentActivity() {
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
Text( Text(
text = "Chapter : ${ControllerChapter.getChapterNameById(chapterId).toString()}", text = "Chapter : ${ControllerChapter.getChapterNameById(chapterId!!).toString()}",
fontSize = 19.sp, fontSize = 19.sp,
color = Color.White color = Color.White
) )
Row { Row {
Text( Text(
text = "Players : ${ControllerLobby.getNbPlayerInLobby(lobbyId)}/${nbPlayers}", text = "Players : ${ControllerLobby.getNbPlayerInLobby(lobbyId!!)}/${nbPlayers}",
fontSize = 19.sp, fontSize = 19.sp,
color = (if(ControllerLobby.getNbPlayerInLobby(lobbyId)==nbPlayers) Color.Red else Color.White) color = (if(ControllerLobby.getNbPlayerInLobby(lobbyId)==nbPlayers) Color.Red else Color.White)
) )
@ -271,7 +266,7 @@ class ServerDetailsActivity : ComponentActivity() {
formDataBuilder.addFormDataPart("launched", "1") formDataBuilder.addFormDataPart("launched", "1")
Button( Button(
onClick = { onClick = {
ControllerLobby.updateLobbyLauched(lobbyId,formDataBuilder) ControllerLobby.updateLobbyLauched(lobbyId!!,formDataBuilder)
}, },
shape = RoundedCornerShape(15), shape = RoundedCornerShape(15),
enabled = isCreator, enabled = isCreator,
@ -323,4 +318,3 @@ class ServerDetailsActivity : ComponentActivity() {
) )
} }
}

@ -2,7 +2,6 @@ package com.example.mathseduc.ui
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.res.Configuration import android.content.res.Configuration
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
@ -57,7 +56,6 @@ import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController import androidx.navigation.NavController
import com.example.mathseduc.MainActivity import com.example.mathseduc.MainActivity
import com.example.mathseduc.ServerDetailsActivity
import com.example.mathseduc.controllers.ControllerChapter import com.example.mathseduc.controllers.ControllerChapter
import com.example.mathseduc.controllers.ControllerLobby import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.controllers.ControllerUtiliser import com.example.mathseduc.controllers.ControllerUtiliser
@ -65,6 +63,7 @@ import com.example.mathseduc.models.Lobby
import com.example.mathseduc.ui.theme.Colors import com.example.mathseduc.ui.theme.Colors
import com.example.mathseduc.viewModel.MultiPageViewModel import com.example.mathseduc.viewModel.MultiPageViewModel
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import okhttp3.MultipartBody import okhttp3.MultipartBody
@ -224,14 +223,10 @@ private suspend fun createUtiliserForLobby(context: Context, lobby: Lobby, navCo
ControllerUtiliser.createUtiliserByIdLobby(formDataBuilder) ControllerUtiliser.createUtiliserByIdLobby(formDataBuilder)
// Naviguer vers l'activité ServerDetails avec les détails du lobby // Naviguer vers l'activité ServerDetails avec les détails du lobby
val intent = Intent(context, ServerDetailsActivity::class.java) val mainScope = MainScope()
intent.putExtra("serverName", lobby.name) mainScope.launch {
intent.putExtra("lobbyId", lobby.id) navController.navigate("serverDetails/${lobby.name}/${lobby.id}/${lobby.idchapter}/${lobby.nbplayers}/${lobby.difficulty}")
intent.putExtra("chapterId", lobby.idchapter) }
intent.putExtra("nbPlayers", lobby.nbplayers)
intent.putExtra("lobbyDifficulty", lobby.difficulty)
context.startActivity(intent)
//navController.navigate("serverDetails/${lobby.name}/${lobby.id}")
} }
} }

Loading…
Cancel
Save