主页换 Flexible 大标题,空状态与令牌图标采用 Expressive 形状底座
This commit is contained in:
@@ -31,7 +31,9 @@ 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.Shape
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
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
|
||||||
@@ -45,9 +47,10 @@ import cn.airnan.a2fair.R
|
|||||||
import cn.airnan.a2fair.data.entity.Group
|
import cn.airnan.a2fair.data.entity.Group
|
||||||
import cn.airnan.a2fair.data.entity.Token
|
import cn.airnan.a2fair.data.entity.Token
|
||||||
import cn.airnan.a2fair.data.entity.TokenType
|
import cn.airnan.a2fair.data.entity.TokenType
|
||||||
|
import kotlin.math.abs
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun TokensScreen(
|
fun TokensScreen(
|
||||||
viewModel: TokensViewModel,
|
viewModel: TokensViewModel,
|
||||||
@@ -59,6 +62,7 @@ fun TokensScreen(
|
|||||||
var searchFieldHasFocus by remember { mutableStateOf(false) }
|
var searchFieldHasFocus by remember { mutableStateOf(false) }
|
||||||
val searchFocusRequester = remember { FocusRequester() }
|
val searchFocusRequester = remember { FocusRequester() }
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
|
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
||||||
|
|
||||||
LaunchedEffect(isSearchExpanded) {
|
LaunchedEffect(isSearchExpanded) {
|
||||||
if (isSearchExpanded) {
|
if (isSearchExpanded) {
|
||||||
@@ -67,26 +71,17 @@ fun TokensScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||||
topBar = {
|
topBar = {
|
||||||
|
if (isSearchExpanded) {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = {
|
title = {
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
AnimatedVisibility(visible = !isSearchExpanded) {
|
|
||||||
Text(stringResource(R.string.tokens))
|
|
||||||
}
|
|
||||||
AnimatedVisibility(
|
|
||||||
visible = isSearchExpanded,
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.padding(end = 16.dp)
|
|
||||||
) {
|
|
||||||
Surface(
|
Surface(
|
||||||
shape = MaterialTheme.shapes.large,
|
shape = MaterialTheme.shapes.large,
|
||||||
color = MaterialTheme.colorScheme.surfaceContainerHighest,
|
color = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(end = 16.dp)
|
||||||
) {
|
) {
|
||||||
TextField(
|
TextField(
|
||||||
value = uiState.searchQuery,
|
value = uiState.searchQuery,
|
||||||
@@ -119,16 +114,18 @@ fun TokensScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
},
|
} else {
|
||||||
|
MediumFlexibleTopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.tokens)) },
|
||||||
actions = {
|
actions = {
|
||||||
AnimatedVisibility(visible = !isSearchExpanded) {
|
|
||||||
IconButton(onClick = { isSearchExpanded = true }) {
|
IconButton(onClick = { isSearchExpanded = true }) {
|
||||||
Icon(Icons.Default.Search, contentDescription = stringResource(R.string.search))
|
Icon(Icons.Default.Search, contentDescription = stringResource(R.string.search))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
scrollBehavior = scrollBehavior
|
||||||
)
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
FloatingActionButton(onClick = { showAddBottomSheet = true }) {
|
FloatingActionButton(onClick = { showAddBottomSheet = true }) {
|
||||||
@@ -154,7 +151,8 @@ fun TokensScreen(
|
|||||||
EmptyState(
|
EmptyState(
|
||||||
icon = Icons.Outlined.SearchOff,
|
icon = Icons.Outlined.SearchOff,
|
||||||
title = stringResource(R.string.empty_search_title),
|
title = stringResource(R.string.empty_search_title),
|
||||||
hint = stringResource(R.string.empty_search_hint)
|
hint = stringResource(R.string.empty_search_hint),
|
||||||
|
iconShape = MaterialShapes.Sunny.toShape()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -214,12 +212,14 @@ fun TokensScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun EmptyState(
|
private fun EmptyState(
|
||||||
icon: ImageVector,
|
icon: ImageVector,
|
||||||
title: String,
|
title: String,
|
||||||
hint: String,
|
hint: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
iconShape: Shape = MaterialShapes.Cookie9Sided.toShape(),
|
||||||
actionLabel: String? = null,
|
actionLabel: String? = null,
|
||||||
onActionClick: (() -> Unit)? = null
|
onActionClick: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
@@ -233,15 +233,15 @@ private fun EmptyState(
|
|||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(96.dp)
|
.size(96.dp)
|
||||||
.clip(CircleShape)
|
.clip(iconShape)
|
||||||
.background(MaterialTheme.colorScheme.surfaceContainerHighest),
|
.background(MaterialTheme.colorScheme.primaryContainer),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = icon,
|
imageVector = icon,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(44.dp),
|
modifier = Modifier.size(44.dp),
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(20.dp))
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
@@ -471,16 +471,26 @@ fun TokenCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun TokenIcon(token: Token) {
|
fun TokenIcon(token: Token) {
|
||||||
val letter = token.issuer.takeIf { it.isNotBlank() }?.firstOrNull()?.uppercaseChar()
|
val letter = token.issuer.takeIf { it.isNotBlank() }?.firstOrNull()?.uppercaseChar()
|
||||||
?: token.serviceName.firstOrNull()?.uppercaseChar()
|
?: token.serviceName.firstOrNull()?.uppercaseChar()
|
||||||
?: '?'
|
?: '?'
|
||||||
|
|
||||||
|
// Deterministic per-token shape: keep 4 understated options, no randomness between recompositions
|
||||||
|
val shapes = listOf(
|
||||||
|
MaterialShapes.Circle,
|
||||||
|
MaterialShapes.Cookie9Sided,
|
||||||
|
MaterialShapes.Pill,
|
||||||
|
MaterialShapes.Sunny,
|
||||||
|
)
|
||||||
|
val shape = shapes[abs(token.issuer.hashCode() * 31 + token.serviceName.hashCode()) % shapes.size]
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(48.dp)
|
.size(48.dp)
|
||||||
.clip(CircleShape)
|
.clip(shape.toShape())
|
||||||
.background(MaterialTheme.colorScheme.primaryContainer),
|
.background(MaterialTheme.colorScheme.primaryContainer),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user