Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/zzgs6gk6rmgcvz48untitledPlain Text
package com.negocio.desinfectantes.ui.auth
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.negocio.desinfectantes.R
import android.content.Context
import androidx.compose.ui.platform.LocalContext
private val LoginNavy = Color(0xFF101D35)
private val LoginCardBlue = Color(0xFF1B2D4A)
private val LoginAccentBlue = Color(0xFF2585F5)
private val LoginSoftBlue = Color(0xFFA9BEDB)
private val LoginWhite = Color(0xFFFFFFFF)
@Composable
fun LoginScreen(
onLogin: (String, String) -> Unit,
onBiometricLogin: () -> Unit,
biometricEnabled: Boolean = false,
isLoading: Boolean = false,
errorMessage: String? = null
) {
val context = LocalContext.current
val preferencias = remember(context) {
context.getSharedPreferences(
"prestige_clean_login",
Context.MODE_PRIVATE
)
}
var recordarUsuario by remember {
mutableStateOf(
preferencias.getBoolean("recordar_usuario", false)
)
}
var usuario by remember {
mutableStateOf(
if (recordarUsuario) {
preferencias.getString("nombre_usuario", "").orEmpty()
} else {
""
}
)
}
var password by remember { mutableStateOf("") }
var mostrarPassword by remember { mutableStateOf(false) }
val puedeIngresar = usuario.isNotBlank() &&
password.isNotBlank() &&
!isLoading
Box(
modifier = Modifier
.fillMaxSize()
.background(LoginNavy)
.imePadding()
) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(horizontal = 26.dp, vertical = 30.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Spacer(modifier = Modifier.height(20.dp))
Surface(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(24.dp),
color = LoginWhite
) {
ImageLogo()
}
Spacer(modifier = Modifier.height(28.dp))
Text(
text = "Bienvenido",
color = LoginWhite,
fontSize = 28.sp,
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.height(6.dp))
Text(
text = "Ingresa a tu cuenta Prestige Clean",
color = LoginSoftBlue,
fontSize = 14.sp
)
Spacer(modifier = Modifier.height(30.dp))
Surface(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(22.dp),
color = LoginCardBlue
) {
Column(
modifier = Modifier.padding(22.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
OutlinedTextField(
value = usuario,
onValueChange = { usuario = it },
modifier = Modifier.fillMaxWidth(),
label = { Text("Nombre de usuario") },
singleLine = true,
enabled = !isLoading,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Next
),
shape = RoundedCornerShape(12.dp),
colors = loginTextFieldColors()
)
OutlinedTextField(
value = password,
onValueChange = { password = it },
modifier = Modifier.fillMaxWidth(),
label = { Text("Contraseña") },
singleLine = true,
enabled = !isLoading,
visualTransformation = if (mostrarPassword) {
VisualTransformation.None
} else {
PasswordVisualTransformation()
},
trailingIcon = {
TextButton(
onClick = {
mostrarPassword = !mostrarPassword
}
) {
Text(
if (mostrarPassword) "Ocultar" else "Ver",
color = LoginSoftBlue
)
}
},
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Password,
imeAction = ImeAction.Done
),
shape = RoundedCornerShape(12.dp),
colors = loginTextFieldColors()
)
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Checkbox(
checked = recordarUsuario,
onCheckedChange = { marcado ->
recordarUsuario = marcado
preferencias.edit()
.putBoolean("recordar_usuario", marcado)
.apply()
if (!marcado) {
preferencias.edit()
.remove("nombre_usuario")
.apply()
}
},
colors = CheckboxDefaults.colors(
checkedColor = LoginAccentBlue,
uncheckedColor = LoginSoftBlue,
checkmarkColor = LoginWhite
)
)
Text(
text = "Recordar usuario",
color = LoginSoftBlue,
fontSize = 14.sp
)
}
if (errorMessage != null) {
Text(
text = errorMessage,
color = Color(0xFFFF8A80),
fontSize = 13.sp
)
}
Button(
onClick = {
if (recordarUsuario) {
preferencias.edit()
.putString("nombre_usuario", usuario.trim())
.putBoolean("recordar_usuario", true)
.apply()
} else {
preferencias.edit()
.remove("nombre_usuario")
.putBoolean("recordar_usuario", false)
.apply()
}
onLogin(usuario.trim(), password)
},
modifier = Modifier
.fillMaxWidth()
.height(54.dp),
enabled = puedeIngresar,
shape = RoundedCornerShape(14.dp),
colors = ButtonDefaults.buttonColors(
containerColor = LoginAccentBlue,
disabledContainerColor = LoginAccentBlue.copy(
alpha = 0.4f
)
)
) {
if (isLoading) {
CircularProgressIndicator(
modifier = Modifier.size(22.dp),
color = LoginWhite,
strokeWidth = 2.dp
)
} else {
Text(
text = "Iniciar sesión",
fontSize = 16.sp,
fontWeight = FontWeight.Bold
)
}
}
if (biometricEnabled) {
HorizontalDivider(
color = LoginSoftBlue.copy(alpha = 0.25f)
)
OutlinedButton(
onClick = onBiometricLogin,
modifier = Modifier
.fillMaxWidth()
.height(54.dp),
enabled = !isLoading,
shape = RoundedCornerShape(14.dp),
colors = ButtonDefaults.outlinedButtonColors(
contentColor = LoginWhite
)
) {
Text(
text = "◎",
fontSize = 24.sp
)
Spacer(modifier = Modifier.width(10.dp))
Text(
text = "Ingresar con biometría",
fontWeight = FontWeight.SemiBold
)
}
}
}
}
Spacer(modifier = Modifier.height(26.dp))
Text(
text = "Limpieza que se ve, protección que se siente",
color = LoginSoftBlue,
fontSize = 12.sp
)
Spacer(modifier = Modifier.height(20.dp))
}
}
}
@Composable
private fun ImageLogo() {
androidx.compose.foundation.Image(
painter = painterResource(id = R.drawable.prestige_clean_logo),
contentDescription = "Logo Prestige Clean",
modifier = Modifier
.fillMaxWidth()
.height(145.dp)
.padding(16.dp),
contentScale = androidx.compose.ui.layout.ContentScale.Fit
)
}
@Composable
private fun loginTextFieldColors() =
OutlinedTextFieldDefaults.colors(
focusedTextColor = LoginWhite,
unfocusedTextColor = LoginWhite,
focusedBorderColor = LoginAccentBlue,
unfocusedBorderColor = LoginSoftBlue.copy(alpha = 0.5f),
focusedLabelColor = LoginAccentBlue,
unfocusedLabelColor = LoginSoftBlue,
cursorColor = LoginAccentBlue
)
11,966 chars · codepastes.com