|
|
|
@ -5,9 +5,11 @@ import android.widget.Toast
|
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
|
import androidx.compose.foundation.Image
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.layout.*
|
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
import androidx.compose.material.icons.filled.ArrowBack
|
|
|
|
|
import androidx.compose.material3.*
|
|
|
|
|
import androidx.compose.runtime.*
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
@ -28,91 +30,130 @@ class ConnexionPlayerActivity : ComponentActivity() {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
setContent {
|
|
|
|
|
MathsEducTheme {
|
|
|
|
|
ConnexionPlayerContent()
|
|
|
|
|
ConnexionPlayerContent(activity = this@ConnexionPlayerActivity)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
|
|
@Composable
|
|
|
|
|
fun ConnexionPlayerContent() {
|
|
|
|
|
fun ConnexionPlayerContent(activity: ConnexionPlayerActivity) {
|
|
|
|
|
var nickname by remember { mutableStateOf("") }
|
|
|
|
|
var password by remember { mutableStateOf("") }
|
|
|
|
|
var showDialog by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.padding(16.dp),
|
|
|
|
|
verticalArrangement = Arrangement.Center,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
Image(
|
|
|
|
|
painter = painterResource(id = R.drawable.logo),
|
|
|
|
|
contentDescription = null,
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(160.dp, 130.dp)
|
|
|
|
|
.background(Color.Gray) // Replace with your background color
|
|
|
|
|
Column(modifier = Modifier.fillMaxSize()) {
|
|
|
|
|
TopAppBar(
|
|
|
|
|
colors = TopAppBarDefaults.topAppBarColors(
|
|
|
|
|
containerColor = Color.Transparent,
|
|
|
|
|
),
|
|
|
|
|
title = {},
|
|
|
|
|
navigationIcon = {
|
|
|
|
|
IconButton(
|
|
|
|
|
onClick = { activity.finish() },
|
|
|
|
|
modifier = Modifier.size(60.dp)
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Filled.ArrowBack,
|
|
|
|
|
contentDescription = "Retour",
|
|
|
|
|
modifier = Modifier.size(36.dp),
|
|
|
|
|
tint = Color.White
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(16.dp)
|
|
|
|
|
.weight(1f),
|
|
|
|
|
verticalArrangement = Arrangement.Center,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
|
Image(
|
|
|
|
|
painter = painterResource(id = R.drawable.logo),
|
|
|
|
|
contentDescription = null,
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(160.dp, 130.dp)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = nickname,
|
|
|
|
|
onValueChange = { nickname = it },
|
|
|
|
|
label = { Text("Nickname") },
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
)
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
|
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = password,
|
|
|
|
|
onValueChange = { password = it },
|
|
|
|
|
label = { Text("Password") },
|
|
|
|
|
visualTransformation = PasswordVisualTransformation(),
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
keyboardType = KeyboardType.Password
|
|
|
|
|
),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
)
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = nickname,
|
|
|
|
|
onValueChange = { nickname = it },
|
|
|
|
|
label = { Text("Nickname") },
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp),
|
|
|
|
|
colors = OutlinedTextFieldDefaults.colors(
|
|
|
|
|
focusedContainerColor = Color.White,
|
|
|
|
|
unfocusedContainerColor = Color.White,
|
|
|
|
|
disabledContainerColor = Color.White,
|
|
|
|
|
focusedBorderColor = Color.Blue,
|
|
|
|
|
),
|
|
|
|
|
shape = RoundedCornerShape(8.dp)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = password,
|
|
|
|
|
onValueChange = { password = it },
|
|
|
|
|
label = { Text("Password") },
|
|
|
|
|
visualTransformation = PasswordVisualTransformation(),
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
keyboardType = KeyboardType.Password
|
|
|
|
|
),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp),
|
|
|
|
|
colors = OutlinedTextFieldDefaults.colors(
|
|
|
|
|
focusedContainerColor = Color.White,
|
|
|
|
|
unfocusedContainerColor = Color.White,
|
|
|
|
|
disabledContainerColor = Color.White,
|
|
|
|
|
focusedBorderColor = Color.Blue,
|
|
|
|
|
),
|
|
|
|
|
shape = RoundedCornerShape(8.dp)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
val isAuthenticated = ControllerPlayer.authenticateUser(nickname, password)
|
|
|
|
|
if (isAuthenticated != -1) {
|
|
|
|
|
MainActivity.idPlayerConnected = isAuthenticated
|
|
|
|
|
Toast.makeText(context, "Connexion réussie, bienvenue $nickname !", Toast.LENGTH_SHORT).show()
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(context, "Connexion échouée. Veuillez réessayer.", Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp)
|
|
|
|
|
) {
|
|
|
|
|
Text("Login")
|
|
|
|
|
}
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
val isAuthenticated = ControllerPlayer.authenticateUser(nickname, password)
|
|
|
|
|
if (isAuthenticated != -1) {
|
|
|
|
|
MainActivity.idPlayerConnected = isAuthenticated
|
|
|
|
|
Toast.makeText(context, "Connexion réussie, bienvenue $nickname !", Toast.LENGTH_SHORT).show()
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(context, "Connexion échouée. Veuillez réessayer.", Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp)
|
|
|
|
|
) {
|
|
|
|
|
Text("Login")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
onClick = { showDialog = true },
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp)
|
|
|
|
|
) {
|
|
|
|
|
Text("Register")
|
|
|
|
|
}
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
onClick = { showDialog = true },
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp),
|
|
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
|
|
|
containerColor = Color(0xFF40E0D0))
|
|
|
|
|
) {
|
|
|
|
|
Text("Register")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showDialog) {
|
|
|
|
|
RegisterDialog(onDismiss = { showDialog = false })
|
|
|
|
|
if (showDialog) {
|
|
|
|
|
RegisterDialog(onDismiss = { showDialog = false })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -125,65 +166,66 @@ fun RegisterDialog(onDismiss: () -> Unit) {
|
|
|
|
|
var password by remember { mutableStateOf("") }
|
|
|
|
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
onDismissRequest = {
|
|
|
|
|
onDismiss()
|
|
|
|
|
},
|
|
|
|
|
title = { Text("Register") },
|
|
|
|
|
confirmButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
// Save the user information or perform registration
|
|
|
|
|
onDismiss()
|
|
|
|
|
onDismissRequest = {
|
|
|
|
|
onDismiss()
|
|
|
|
|
},
|
|
|
|
|
title = { Text("Register") },
|
|
|
|
|
confirmButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
val playerId = ControllerPlayer.createPlayer(nickname, password)
|
|
|
|
|
onDismiss()
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Text("Save")
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Text("Save")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
dismissButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
onDismiss()
|
|
|
|
|
},
|
|
|
|
|
dismissButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
onDismiss()
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Text("Dismiss")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
text = {
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
) {
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = nickname,
|
|
|
|
|
onValueChange = { nickname = it },
|
|
|
|
|
label = { Text("Nickname") },
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = password,
|
|
|
|
|
onValueChange = { password = it },
|
|
|
|
|
label = { Text("Password") },
|
|
|
|
|
visualTransformation = PasswordVisualTransformation(),
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
keyboardType = KeyboardType.Password
|
|
|
|
|
),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Text("Dismiss")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
text = {
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
) {
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = nickname,
|
|
|
|
|
onValueChange = { nickname = it },
|
|
|
|
|
label = { Text("Nickname") },
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = password,
|
|
|
|
|
onValueChange = { password = it },
|
|
|
|
|
label = { Text("Password") },
|
|
|
|
|
visualTransformation = PasswordVisualTransformation(),
|
|
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
|
|
keyboardType = KeyboardType.Password
|
|
|
|
|
),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Preview(showBackground = true)
|
|
|
|
|
@Composable
|
|
|
|
|
fun ConnexionPlayerPreview() {
|
|
|
|
|
val fakeActivity = ConnexionPlayerActivity()
|
|
|
|
|
MathsEducTheme {
|
|
|
|
|
ConnexionPlayerContent()
|
|
|
|
|
ConnexionPlayerContent(activity = fakeActivity)
|
|
|
|
|
}
|
|
|
|
|
}
|