package eu.friedcutlet.yokan.ui.screens.applock import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Lock import androidx.compose.material3.Button import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp /** * Full-screen lock surface the app root stacks above everything while locked * (Mangayomi's AppLockScreen over the router). [onUnlock] starts an authentication * and reports whether it succeeded. */ @Composable fun AppLockOverlay( unlocked: Boolean, supported: Boolean, onUnlock: (onResult: (Boolean) -> Unit) -> Unit, ) { var authenticating by remember { mutableStateOf(false) } var failed by remember { mutableStateOf(false) } fun unlock() { authenticating = true failed = false onUnlock { ok -> authenticating = false failed = !ok } } LaunchedEffect(Unit) { if (!unlocked && !authenticating) unlock() } // No AppBar — full-screen overlay. Back press is intentionally ignored // (PopScope(canPop:false) parity): the user must authenticate via the Unlock // button. We do not register a BackHandler, so the surrounding host can // decide whether back closes the screen; the screen itself takes no action. Box( modifier = Modifier .fillMaxSize() .background(MaterialTheme.colorScheme.surface), contentAlignment = Alignment.Center, ) { Column( modifier = Modifier.padding(32.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(20.dp), ) { Box( modifier = Modifier .size(96.dp) .background( MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.6f), RoundedCornerShape(24.dp), ), contentAlignment = Alignment.Center, ) { Icon( Icons.Filled.Lock, contentDescription = null, tint = MaterialTheme.colorScheme.primary, modifier = Modifier.size(56.dp), ) } Text( if (unlocked) "Unlocked" else "App is locked", style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.SemiBold, ) Text( when { unlocked -> "You can now use the app." !supported -> "Biometric authentication is unavailable on this device." failed -> "Authentication failed. Tap Unlock to try again." authenticating -> "Authenticating…" else -> "Authenticate to unlock and continue using the application." }, color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.bodyMedium, textAlign = TextAlign.Center, ) if (!unlocked) { Button( onClick = { if (!authenticating) unlock() }, enabled = !authenticating, ) { Icon(Icons.Filled.Lock, contentDescription = null) Spacer(Modifier.width(6.dp)) Text(if (authenticating) "Authenticating…" else "Unlock") } } } } }