首页无令牌时显示空状态提示

This commit is contained in:
2026-10-14 12:14:17 +08:00
parent 252bb1c02b
commit 86cd6fb3dc
4 changed files with 116 additions and 30 deletions
@@ -20,6 +20,8 @@ import androidx.compose.material.icons.filled.ExpandLess
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.outlined.QrCode2
import androidx.compose.material.icons.outlined.SearchOff
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
@@ -29,10 +31,12 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -137,38 +141,56 @@ fun TokensScreen(
.fillMaxSize()
.padding(padding)
) {
// Token List
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(bottom = 80.dp)
) {
uiState.groupedTokens.forEach { (group, tokens) ->
val groupId = group?.id
val isCollapsed = uiState.collapsedGroups.contains(groupId ?: -1L)
if (uiState.groupedTokens.isEmpty()) {
if (uiState.searchQuery.isBlank()) {
EmptyState(
icon = Icons.Outlined.QrCode2,
title = stringResource(R.string.empty_tokens_title),
hint = stringResource(R.string.empty_tokens_hint),
actionLabel = stringResource(R.string.add_token),
onActionClick = { showAddBottomSheet = true }
)
} else {
EmptyState(
icon = Icons.Outlined.SearchOff,
title = stringResource(R.string.empty_search_title),
hint = stringResource(R.string.empty_search_hint)
)
}
} else {
// Token List
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(bottom = 80.dp)
) {
uiState.groupedTokens.forEach { (group, tokens) ->
val groupId = group?.id
val isCollapsed = uiState.collapsedGroups.contains(groupId ?: -1L)
item(key = "group_${groupId ?: "unassigned"}") {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 6.dp),
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp)
) {
Column {
GroupHeader(
group = group,
isCollapsed = isCollapsed,
onToggle = { viewModel.toggleGroupCollapse(groupId) }
)
item(key = "group_${groupId ?: "unassigned"}") {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 6.dp),
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp)
) {
Column {
GroupHeader(
group = group,
isCollapsed = isCollapsed,
onToggle = { viewModel.toggleGroupCollapse(groupId) }
)
if (!isCollapsed) {
tokens.forEachIndexed { index, token ->
TokenCard(
token = token,
onIncrement = { viewModel.incrementCounter(token) },
onEdit = { onNavigateToTokenEdit(token.id) }
)
if (index < tokens.lastIndex) {
HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp))
if (!isCollapsed) {
tokens.forEachIndexed { index, token ->
TokenCard(
token = token,
onIncrement = { viewModel.incrementCounter(token) },
onEdit = { onNavigateToTokenEdit(token.id) }
)
if (index < tokens.lastIndex) {
HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp))
}
}
}
}
@@ -192,6 +214,58 @@ fun TokensScreen(
}
}
@Composable
private fun EmptyState(
icon: ImageVector,
title: String,
hint: String,
modifier: Modifier = Modifier,
actionLabel: String? = null,
onActionClick: (() -> Unit)? = null
) {
Column(
modifier = modifier
.fillMaxSize()
.padding(horizontal = 32.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Box(
modifier = Modifier
.size(96.dp)
.clip(CircleShape)
.background(MaterialTheme.colorScheme.surfaceContainerHighest),
contentAlignment = Alignment.Center
) {
Icon(
imageVector = icon,
contentDescription = null,
modifier = Modifier.size(44.dp),
tint = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Spacer(modifier = Modifier.height(20.dp))
Text(
text = title,
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.SemiBold
)
Spacer(modifier = Modifier.height(6.dp))
Text(
text = hint,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center
)
if (actionLabel != null && onActionClick != null) {
Spacer(modifier = Modifier.height(20.dp))
FilledTonalButton(onClick = onActionClick) {
Text(actionLabel)
}
}
}
}
@Composable
fun GroupHeader(
group: Group?,
@@ -19,6 +19,10 @@
<string name="edit">编辑</string>
<string name="delete">删除</string>
<string name="code_copied">已复制 %s 的验证码</string>
<string name="empty_tokens_title">还没有令牌</string>
<string name="empty_tokens_hint">扫描二维码或手动输入,添加你的第一个两步验证令牌。</string>
<string name="empty_search_title">未找到匹配的令牌</string>
<string name="empty_search_hint">换个关键词试试</string>
<!-- Add Token -->
<string name="scan_qr_code">扫描二维码</string>
@@ -19,6 +19,10 @@
<string name="edit">編輯</string>
<string name="delete">刪除</string>
<string name="code_copied">已複製 %s 的驗證碼</string>
<string name="empty_tokens_title">還沒有權杖</string>
<string name="empty_tokens_hint">掃描 QR 碼或手動輸入,新增你的第一個兩步驟驗證權杖。</string>
<string name="empty_search_title">未找到符合的權杖</string>
<string name="empty_search_hint">換個關鍵字試試</string>
<!-- Add Token -->
<string name="scan_qr_code">掃描 QR 碼</string>
+4
View File
@@ -19,6 +19,10 @@
<string name="edit">Edit</string>
<string name="delete">Delete</string>
<string name="code_copied">Code for %s copied</string>
<string name="empty_tokens_title">No tokens yet</string>
<string name="empty_tokens_hint">Scan a QR code or enter one manually to add your first 2FA token.</string>
<string name="empty_search_title">No matching tokens</string>
<string name="empty_search_hint">Try a different keyword</string>
<!-- Add Token -->
<string name="scan_qr_code">Scan QR Code</string>