首页无令牌时显示空状态提示
This commit is contained in:
@@ -20,6 +20,8 @@ import androidx.compose.material.icons.filled.ExpandLess
|
|||||||
import androidx.compose.material.icons.filled.ExpandMore
|
import androidx.compose.material.icons.filled.ExpandMore
|
||||||
import androidx.compose.material.icons.filled.Refresh
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
import androidx.compose.material.icons.filled.Search
|
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.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
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.focusRequester
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
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.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
@@ -137,38 +141,56 @@ fun TokensScreen(
|
|||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
) {
|
) {
|
||||||
// Token List
|
if (uiState.groupedTokens.isEmpty()) {
|
||||||
LazyColumn(
|
if (uiState.searchQuery.isBlank()) {
|
||||||
modifier = Modifier.fillMaxSize(),
|
EmptyState(
|
||||||
contentPadding = PaddingValues(bottom = 80.dp)
|
icon = Icons.Outlined.QrCode2,
|
||||||
) {
|
title = stringResource(R.string.empty_tokens_title),
|
||||||
uiState.groupedTokens.forEach { (group, tokens) ->
|
hint = stringResource(R.string.empty_tokens_hint),
|
||||||
val groupId = group?.id
|
actionLabel = stringResource(R.string.add_token),
|
||||||
val isCollapsed = uiState.collapsedGroups.contains(groupId ?: -1L)
|
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"}") {
|
item(key = "group_${groupId ?: "unassigned"}") {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 16.dp, vertical = 6.dp),
|
.padding(horizontal = 16.dp, vertical = 6.dp),
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp)
|
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp)
|
||||||
) {
|
) {
|
||||||
Column {
|
Column {
|
||||||
GroupHeader(
|
GroupHeader(
|
||||||
group = group,
|
group = group,
|
||||||
isCollapsed = isCollapsed,
|
isCollapsed = isCollapsed,
|
||||||
onToggle = { viewModel.toggleGroupCollapse(groupId) }
|
onToggle = { viewModel.toggleGroupCollapse(groupId) }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isCollapsed) {
|
if (!isCollapsed) {
|
||||||
tokens.forEachIndexed { index, token ->
|
tokens.forEachIndexed { index, token ->
|
||||||
TokenCard(
|
TokenCard(
|
||||||
token = token,
|
token = token,
|
||||||
onIncrement = { viewModel.incrementCounter(token) },
|
onIncrement = { viewModel.incrementCounter(token) },
|
||||||
onEdit = { onNavigateToTokenEdit(token.id) }
|
onEdit = { onNavigateToTokenEdit(token.id) }
|
||||||
)
|
)
|
||||||
if (index < tokens.lastIndex) {
|
if (index < tokens.lastIndex) {
|
||||||
HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp))
|
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
|
@Composable
|
||||||
fun GroupHeader(
|
fun GroupHeader(
|
||||||
group: Group?,
|
group: Group?,
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
<string name="edit">编辑</string>
|
<string name="edit">编辑</string>
|
||||||
<string name="delete">删除</string>
|
<string name="delete">删除</string>
|
||||||
<string name="code_copied">已复制 %s 的验证码</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 -->
|
<!-- Add Token -->
|
||||||
<string name="scan_qr_code">扫描二维码</string>
|
<string name="scan_qr_code">扫描二维码</string>
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
<string name="edit">編輯</string>
|
<string name="edit">編輯</string>
|
||||||
<string name="delete">刪除</string>
|
<string name="delete">刪除</string>
|
||||||
<string name="code_copied">已複製 %s 的驗證碼</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 -->
|
<!-- Add Token -->
|
||||||
<string name="scan_qr_code">掃描 QR 碼</string>
|
<string name="scan_qr_code">掃描 QR 碼</string>
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
<string name="edit">Edit</string>
|
<string name="edit">Edit</string>
|
||||||
<string name="delete">Delete</string>
|
<string name="delete">Delete</string>
|
||||||
<string name="code_copied">Code for %s copied</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 -->
|
<!-- Add Token -->
|
||||||
<string name="scan_qr_code">Scan QR Code</string>
|
<string name="scan_qr_code">Scan QR Code</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user