|
|
|
@ -6,9 +6,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.runtime.saveable.rememberSaveable
|
|
|
|
@ -30,33 +32,55 @@ 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 rememberSaveable { mutableStateOf("") }
|
|
|
|
|
var password by rememberSaveable { mutableStateOf("") }
|
|
|
|
|
var showDialog by rememberSaveable { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.padding(16.dp),
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(16.dp)
|
|
|
|
|
.weight(1f),
|
|
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
@ -67,7 +91,14 @@ fun ConnexionPlayerContent() {
|
|
|
|
|
label = { Text("Nickname") },
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
.padding(8.dp),
|
|
|
|
|
colors = OutlinedTextFieldDefaults.colors(
|
|
|
|
|
focusedContainerColor = Color.White,
|
|
|
|
|
unfocusedContainerColor = Color.White,
|
|
|
|
|
disabledContainerColor = Color.White,
|
|
|
|
|
focusedBorderColor = Color.Blue,
|
|
|
|
|
),
|
|
|
|
|
shape = RoundedCornerShape(8.dp)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
OutlinedTextField(
|
|
|
|
@ -80,7 +111,14 @@ fun ConnexionPlayerContent() {
|
|
|
|
|
),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
.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))
|
|
|
|
@ -89,9 +127,6 @@ fun ConnexionPlayerContent() {
|
|
|
|
|
onClick = {
|
|
|
|
|
val isAuthenticated = ControllerPlayer.authenticateUser(nickname, password)
|
|
|
|
|
if (isAuthenticated != -1) {
|
|
|
|
|
val intent = Intent(context, MainActivity::class.java)
|
|
|
|
|
context.startActivity(intent)
|
|
|
|
|
|
|
|
|
|
MainActivity.idPlayerConnected = isAuthenticated
|
|
|
|
|
Toast.makeText(context, "Connexion réussie, bienvenue $nickname !", Toast.LENGTH_SHORT).show()
|
|
|
|
|
} else {
|
|
|
|
@ -111,7 +146,9 @@ fun ConnexionPlayerContent() {
|
|
|
|
|
onClick = { showDialog = true },
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(48.dp)
|
|
|
|
|
.height(48.dp),
|
|
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
|
|
|
containerColor = Color(0xFF40E0D0))
|
|
|
|
|
) {
|
|
|
|
|
Text("Register")
|
|
|
|
|
}
|
|
|
|
@ -121,6 +158,7 @@ fun ConnexionPlayerContent() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun RegisterDialog(onDismiss: () -> Unit) {
|
|
|
|
@ -137,7 +175,7 @@ fun RegisterDialog(onDismiss: () -> Unit) {
|
|
|
|
|
confirmButton = {
|
|
|
|
|
Button(
|
|
|
|
|
onClick = {
|
|
|
|
|
// Save the user information or perform registration
|
|
|
|
|
val playerId = ControllerPlayer.createPlayer(nickname, password)
|
|
|
|
|
onDismiss()
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
@ -188,7 +226,8 @@ fun RegisterDialog(onDismiss: () -> Unit) {
|
|
|
|
|
@Preview(showBackground = true)
|
|
|
|
|
@Composable
|
|
|
|
|
fun ConnexionPlayerPreview() {
|
|
|
|
|
val fakeActivity = ConnexionPlayerActivity()
|
|
|
|
|
MathsEducTheme {
|
|
|
|
|
ConnexionPlayerContent()
|
|
|
|
|
ConnexionPlayerContent(activity = fakeActivity)
|
|
|
|
|
}
|
|
|
|
|
}
|