Merge remote-tracking branch 'origin/androidCompose' into androidCompose

# Conflicts:
#	Android/app/src/main/java/com/example/mathseduc/ServerDetailsActivity.kt
androidCompose
Jeremy DUCOURTHIAL 1 year ago
commit 6451a27b3a

@ -1,12 +1,15 @@
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
import com.example.mathseduc.ui.QuizMultiScreen
@Composable @Composable
fun AppNavigation() { fun AppNavigation() {
@ -17,6 +20,32 @@ 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)
}
composable(
route = "quizMultiScreen/{lobbyId}",
arguments = listOf(
navArgument("lobbyId") { type = NavType.IntType }
)
) { backStackEntry ->
val lobbyId = backStackEntry.arguments?.getInt("lobbyId")
QuizMultiScreen(navController, lobbyId)
}
} }
} }

@ -4,9 +4,6 @@ import android.os.Bundle
import android.os.CountDownTimer import android.os.CountDownTimer
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.ui.tooling.preview.Preview
import com.example.mathseduc.ui.QuizMultiScreen
import com.example.mathseduc.ui.theme.MathsEducTheme import com.example.mathseduc.ui.theme.MathsEducTheme
@ -20,10 +17,12 @@ class QuizMultiActivity : ComponentActivity() {
setContent { setContent {
MathsEducTheme { MathsEducTheme {
/*
val lobbyId = intent.getIntExtra("lobbyId",-1) val lobbyId = intent.getIntExtra("lobbyId",-1)
val serverName = intent.getStringExtra("serverName") val serverName = intent.getStringExtra("serverName")
QuizMultiScreen(lobbyId, serverName!!, activity = this@QuizMultiActivity) //TODO sus QuizMultiScreen(lobbyId, serverName!!) //TODO sus
*/
} }
} }
} }

@ -59,7 +59,6 @@ import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner import androidx.lifecycle.ViewModelStoreOwner
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
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.ControllerPlayer import com.example.mathseduc.controllers.ControllerPlayer
@ -137,9 +136,9 @@ class ServerDetailsActivity : ComponentActivity() {
WindowCompat.getInsetsController(activity.window, activity.window.decorView) WindowCompat.getInsetsController(activity.window, activity.window.decorView)
} }
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
DisposableEffect(refreshState) { DisposableEffect(refreshState) {
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
@ -160,14 +159,14 @@ class ServerDetailsActivity : ComponentActivity() {
viewModel.updateRefresh(false) viewModel.updateRefresh(false)
} }
if (refreshState){ if (refreshState){
handler.postDelayed(this,3000) handler.postDelayed(this,3000)
Log.e("MainActivity", "Refresh ServerDetails") Log.e("MainActivity", "Refresh ServerDetails")
}
} }
} }
}
handler.post(refreshRunnable) handler.post(refreshRunnable)
onDispose { onDispose {
viewModel.updateRefresh(false) viewModel.updateRefresh(false)
@ -305,7 +304,6 @@ class ServerDetailsActivity : ComponentActivity() {
confirmButton = { confirmButton = {
Button( Button(
onClick = { onClick = {
myBackPressed()
onConfirmLeave() onConfirmLeave()
} }
) { ) {

@ -2,7 +2,6 @@ package com.example.mathseduc.ui
import android.app.Activity import android.app.Activity
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
@ -36,7 +35,6 @@ import androidx.compose.runtime.remember
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.layout.onGloballyPositioned import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalConfiguration
@ -46,7 +44,6 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
@ -57,7 +54,6 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner import androidx.lifecycle.ViewModelStoreOwner
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
@ -294,13 +290,7 @@ fun CreateLobbyPage(navController: NavController) {
ControllerUtiliser.createUtiliserByIdLobby(formDataBuilderConnexion) ControllerUtiliser.createUtiliserByIdLobby(formDataBuilderConnexion)
Toast.makeText(context, "Lobby created successfully!", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Lobby created successfully!", Toast.LENGTH_SHORT).show()
val intent = Intent(context, ServerDetailsActivity::class.java) navController.navigate("serverDetails/${lobbyName}/${lobbyId}/${selectedChapter.id.toInt()}/${nbPlayers}/${difficultyNum}")
intent.putExtra("lobbyId", lobbyId)
intent.putExtra("serverName", lobbyName)
intent.putExtra("chapterId", selectedChapter.id.toInt())
intent.putExtra("nbPlayers", nbPlayers.toInt())
intent.putExtra("lobbyDifficulty", difficultyNum)
context.startActivity(intent)
} else { } else {
Toast.makeText(context, "Failed to create lobby. Please try again.", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Failed to create lobby. Please try again.", Toast.LENGTH_SHORT).show()
} }

@ -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}")
} }
} }

@ -1,6 +1,6 @@
package com.example.mathseduc.ui package com.example.mathseduc.ui
import android.content.Intent import android.app.Activity
import android.widget.Toast import android.widget.Toast
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
@ -26,15 +26,15 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.WindowInsetsControllerCompat
import androidx.navigation.NavController
import com.example.mathseduc.MainActivity import com.example.mathseduc.MainActivity
import com.example.mathseduc.QuizMultiActivity
import com.example.mathseduc.ServerDetailsActivity
import com.example.mathseduc.controllers.ControllerLobby import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.controllers.ControllerQuestion import com.example.mathseduc.controllers.ControllerQuestion
import com.example.mathseduc.ui.theme.Colors import com.example.mathseduc.ui.theme.Colors
@ -43,16 +43,17 @@ import okhttp3.MultipartBody
@Composable @Composable
fun QuizMultiScreen(lobbyId: Int,serverName: String,activity: QuizMultiActivity) { fun QuizMultiScreen(navController: NavController, lobbyId: Int?) {
val context = LocalContext.current val context = LocalContext.current
val activity = LocalView.current.context as Activity
var chronoValue by remember { mutableStateOf(0.0f) } var chronoValue by remember { mutableStateOf(0.0f) }
var listQuestion by remember { mutableStateOf(ControllerQuestion.getQuestionsForLobby(ControllerLobby.getIdQuestionsLobby(lobbyId))) } var listQuestion by remember { mutableStateOf(ControllerQuestion.getQuestionsForLobby(ControllerLobby.getIdQuestionsLobby(lobbyId!!))) }
var listPlayer by remember { mutableStateOf(ControllerLobby.getPlayerInLobby(lobbyId)) } var listPlayer by remember { mutableStateOf(ControllerLobby.getPlayerInLobby(lobbyId!!)) }
var currentQuestionIndex by remember { mutableIntStateOf(0) } var currentQuestionIndex by remember { mutableIntStateOf(0) }
val progressBarValues by remember { mutableStateOf(Array(listPlayer.size) { 0.0f }) } val progressBarValues by remember { mutableStateOf(Array(listPlayer.size) { 0.0f }) }
val progressBarTotalValues by remember { mutableStateOf(Array(listPlayer.size) { 0.0f }) } val progressBarTotalValues by remember { mutableStateOf(Array(listPlayer.size) { 0.0f }) }
var quizFinished by remember { mutableStateOf(false) } // Variable pour indiquer si le quiz est terminé ou non var quizFinished by remember { mutableStateOf(false) }
val windowInsetsController = remember { val windowInsetsController = remember {
WindowCompat.getInsetsController(activity.window, activity.window.decorView) WindowCompat.getInsetsController(activity.window, activity.window.decorView)
@ -81,7 +82,7 @@ fun QuizMultiScreen(lobbyId: Int,serverName: String,activity: QuizMultiActivity)
val timer = ticker(delayMillis = 3000) val timer = ticker(delayMillis = 3000)
for (tick in timer) { for (tick in timer) {
if (quizFinished) break if (quizFinished) break
var valueBD = ControllerLobby.getPlayerInLobby(lobbyId) var valueBD = ControllerLobby.getPlayerInLobby(lobbyId!!)
for ((index, player) in listPlayer.withIndex()) { for ((index, player) in listPlayer.withIndex()) {
progressBarTotalValues[index] = progressBarValues[index] + valueBD[index].playertime progressBarTotalValues[index] = progressBarValues[index] + valueBD[index].playertime
} }
@ -150,7 +151,7 @@ fun QuizMultiScreen(lobbyId: Int,serverName: String,activity: QuizMultiActivity)
Toast.makeText(context, "Oh ouii !!", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Oh ouii !!", Toast.LENGTH_SHORT).show()
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM) val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
val playertime = ControllerLobby.getLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected) + 10 val playertime = ControllerLobby.getLobbyUtiliserPlayerTime(lobbyId!!,MainActivity.idPlayerConnected) + 10
formDataBuilder.addFormDataPart("playertime", playertime.toString()) formDataBuilder.addFormDataPart("playertime", playertime.toString())
ControllerLobby.updateLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected,formDataBuilder) ControllerLobby.updateLobbyUtiliserPlayerTime(lobbyId,MainActivity.idPlayerConnected,formDataBuilder)
@ -191,10 +192,7 @@ fun QuizMultiScreen(lobbyId: Int,serverName: String,activity: QuizMultiActivity)
} }
} else { } else {
Toast.makeText(context, "Fini !!", Toast.LENGTH_SHORT).show() Toast.makeText(context, "Fini !!", Toast.LENGTH_SHORT).show()
val intent = Intent(context, MainActivity::class.java) navController.navigate("home")
//intent.putExtra("serverName", serverName)
//intent.putExtra("lobbyId", lobbyId)
context.startActivity(intent)
quizFinished = true quizFinished = true
} }
} }

Loading…
Cancel
Save