feat : Confirmdialog password lobby
continuous-integration/drone/push Build is passing Details

androidCompose
Maxence GUITARD 1 year ago
parent ab3563723e
commit ef784ff3d3

@ -15,12 +15,15 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
@ -34,6 +37,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.mathseduc.CreateLobbyActivity
@ -154,6 +159,7 @@ fun MultiPage() {
if (ControllerLobby.getNbPlayerInLobby(selectedItem!!.id) < selectedItem!!.nbplayers) {
// Créer un Utiliser si le lobby n'est pas plein
scope.launch {
createUtiliserForLobby(context, selectedItem!!)
}
@ -192,13 +198,19 @@ private suspend fun createUtiliserForLobby(context: Context, lobby: Lobby) {
@Composable
fun LobbyItem(lobby: Lobby, isSelected: Boolean, onItemClick: (Lobby) -> Unit) {
val context = LocalContext.current
var showDialog by rememberSaveable { mutableStateOf(false) }
Row(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.clickable {
if (lobby.password.isNotEmpty()) {
showDialog = true
} else {
onItemClick(lobby)
}
}
.background(if (isSelected) Colors.Orange else Colors.Grey)
.padding(16.dp)
.clip(RoundedCornerShape(8.dp))
@ -227,5 +239,73 @@ fun LobbyItem(lobby: Lobby, isSelected: Boolean, onItemClick: (Lobby) -> Unit) {
color = Colors.White,
modifier = Modifier.weight(1f)
)
if (showDialog) {
ConfirmDialog(
onDismiss = { showDialog = false },
onConfirm = { password ->
println("Password input : $password")
if (password == lobby.password) {
showDialog = false
onItemClick(lobby)
} else {
Toast.makeText(context, "Wrong password!", Toast.LENGTH_SHORT).show()
}
}
)
}
}
}
@Composable
fun ConfirmDialog(onDismiss: () -> Unit, onConfirm: (String) -> Unit) {
val context = LocalContext.current
var password by remember { mutableStateOf("") }
AlertDialog(
onDismissRequest = {
onDismiss()
},
title = { Text("Enter Password") },
confirmButton = {
Button(
onClick = {
onConfirm(password)
}
) {
Text("Confirm")
}
},
dismissButton = {
Button(
onClick = {
onDismiss()
}
) {
Text("Dismiss")
}
},
text = {
Column(
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)
)
}
}
)
}
Loading…
Cancel
Save