Compare commits
7
Commits
9ee6cfdfee
...
74aa93abcd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74aa93abcd | ||
|
|
e10e296efa | ||
|
|
a676bef14a | ||
|
|
19384b9547 | ||
|
|
e0bd974f59 | ||
|
|
666542ce17 | ||
|
|
cfe26fd5d3 |
@@ -6,7 +6,8 @@ plugins {
|
||||
|
||||
android {
|
||||
namespace = "cn.airnan.a2fair"
|
||||
compileSdk = 35
|
||||
compileSdk = 37
|
||||
compileSdkMinor = 0
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "cn.airnan.a2fair"
|
||||
|
||||
@@ -11,11 +11,12 @@ import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material.icons.filled.Lock
|
||||
import androidx.compose.material.icons.filled.SettingsBackupRestore
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MediumFlexibleTopAppBar
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -25,7 +26,7 @@ import cn.airnan.a2fair.R
|
||||
import androidx.compose.material.icons.filled.Language
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
onNavigateToSecurity: () -> Unit,
|
||||
@@ -36,7 +37,7 @@ fun SettingsScreen(
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
MediumFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.settings)) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,10 @@ import android.content.ContextWrapper
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.MaterialExpressiveTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.MotionScheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
@@ -115,6 +118,7 @@ tailrec fun Context.findActivity(): Activity? = when (this) {
|
||||
else -> null
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun _2FAirTheme(
|
||||
themeMode: Int = 0, // 0: System, 1: Light, 2: Dark
|
||||
@@ -147,8 +151,9 @@ fun _2FAirTheme(
|
||||
}
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
MaterialExpressiveTheme(
|
||||
colorScheme = colorScheme,
|
||||
motionScheme = MotionScheme.expressive(),
|
||||
typography = Typography,
|
||||
content = content
|
||||
)
|
||||
|
||||
@@ -21,9 +21,11 @@ import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.*
|
||||
import androidx.compose.material.icons.outlined.PhotoCamera
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -53,7 +55,7 @@ import kotlinx.coroutines.launch
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun AddTokenBottomSheet(
|
||||
viewModel: TokensViewModel,
|
||||
@@ -161,13 +163,31 @@ fun AddTokenBottomSheet(
|
||||
)
|
||||
|
||||
if (!hasCameraPermission) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.align(Alignment.Center).padding(16.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(56.dp)
|
||||
.clip(MaterialShapes.Cookie9Sided.toShape())
|
||||
.background(MaterialTheme.colorScheme.primaryContainer),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.PhotoCamera,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.camera_permission_hint),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.align(Alignment.Center).padding(16.dp)
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (showScanningText) {
|
||||
Surface(
|
||||
@@ -175,9 +195,14 @@ fun AddTokenBottomSheet(
|
||||
modifier = Modifier.align(Alignment.BottomCenter).padding(8.dp),
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp)
|
||||
) {
|
||||
LoadingIndicator(modifier = Modifier.size(20.dp))
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.scanning_hint),
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
@@ -185,6 +210,7 @@ fun AddTokenBottomSheet(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(previewView, hasCameraPermission) {
|
||||
val pv = previewView ?: return@LaunchedEffect
|
||||
|
||||
@@ -13,7 +13,9 @@ import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -24,7 +26,7 @@ import cn.airnan.a2fair.data.entity.Token
|
||||
import cn.airnan.a2fair.data.entity.TokenType
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun TokenDetailSheet(
|
||||
token: Token,
|
||||
@@ -154,12 +156,14 @@ fun TokenDetailSheet(
|
||||
modifier = Modifier.size(44.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
val ringStroke = Stroke(width = with(LocalDensity.current) { 3.dp.toPx() })
|
||||
CircularWavyProgressIndicator(
|
||||
progress = { progress },
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
modifier = Modifier.size(44.dp),
|
||||
color = if (showNextPreview) warningColor else MaterialTheme.colorScheme.primary,
|
||||
trackColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||
strokeWidth = 3.dp,
|
||||
trackColor = MaterialTheme.colorScheme.outlineVariant,
|
||||
stroke = ringStroke,
|
||||
trackStroke = ringStroke,
|
||||
)
|
||||
Text(
|
||||
text = "$remainingSeconds",
|
||||
|
||||
@@ -31,7 +31,11 @@ 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.Shape
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -45,9 +49,10 @@ import cn.airnan.a2fair.R
|
||||
import cn.airnan.a2fair.data.entity.Group
|
||||
import cn.airnan.a2fair.data.entity.Token
|
||||
import cn.airnan.a2fair.data.entity.TokenType
|
||||
import kotlin.math.abs
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun TokensScreen(
|
||||
viewModel: TokensViewModel,
|
||||
@@ -59,6 +64,7 @@ fun TokensScreen(
|
||||
var searchFieldHasFocus by remember { mutableStateOf(false) }
|
||||
val searchFocusRequester = remember { FocusRequester() }
|
||||
val focusManager = LocalFocusManager.current
|
||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
||||
|
||||
LaunchedEffect(isSearchExpanded) {
|
||||
if (isSearchExpanded) {
|
||||
@@ -67,26 +73,17 @@ fun TokensScreen(
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||
topBar = {
|
||||
if (isSearchExpanded) {
|
||||
TopAppBar(
|
||||
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(
|
||||
shape = MaterialTheme.shapes.large,
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 16.dp)
|
||||
) {
|
||||
TextField(
|
||||
value = uiState.searchQuery,
|
||||
@@ -119,16 +116,18 @@ fun TokensScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
MediumFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.tokens)) },
|
||||
actions = {
|
||||
AnimatedVisibility(visible = !isSearchExpanded) {
|
||||
IconButton(onClick = { isSearchExpanded = true }) {
|
||||
Icon(Icons.Default.Search, contentDescription = stringResource(R.string.search))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
}
|
||||
},
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(onClick = { showAddBottomSheet = true }) {
|
||||
@@ -154,7 +153,8 @@ fun TokensScreen(
|
||||
EmptyState(
|
||||
icon = Icons.Outlined.SearchOff,
|
||||
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 {
|
||||
@@ -214,12 +214,14 @@ fun TokensScreen(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
private fun EmptyState(
|
||||
icon: ImageVector,
|
||||
title: String,
|
||||
hint: String,
|
||||
modifier: Modifier = Modifier,
|
||||
iconShape: Shape = MaterialShapes.Cookie9Sided.toShape(),
|
||||
actionLabel: String? = null,
|
||||
onActionClick: (() -> Unit)? = null
|
||||
) {
|
||||
@@ -233,15 +235,15 @@ private fun EmptyState(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(96.dp)
|
||||
.clip(CircleShape)
|
||||
.background(MaterialTheme.colorScheme.surfaceContainerHighest),
|
||||
.clip(iconShape)
|
||||
.background(MaterialTheme.colorScheme.primaryContainer),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(44.dp),
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
@@ -293,7 +295,7 @@ fun GroupHeader(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun TokenCard(
|
||||
token: Token,
|
||||
@@ -441,12 +443,14 @@ fun TokenCard(
|
||||
modifier = Modifier.size(44.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
val ringStroke = Stroke(width = with(LocalDensity.current) { 3.dp.toPx() })
|
||||
CircularWavyProgressIndicator(
|
||||
progress = { progress },
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
modifier = Modifier.size(44.dp),
|
||||
color = if (showNextPreview) warningColor else MaterialTheme.colorScheme.primary,
|
||||
trackColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||
strokeWidth = 3.dp,
|
||||
trackColor = MaterialTheme.colorScheme.outlineVariant,
|
||||
stroke = ringStroke,
|
||||
trackStroke = ringStroke,
|
||||
)
|
||||
Text(
|
||||
text = "$remainingSeconds",
|
||||
@@ -471,16 +475,26 @@ fun TokenCard(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun TokenIcon(token: Token) {
|
||||
val letter = token.issuer.takeIf { it.isNotBlank() }?.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(
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.clip(CircleShape)
|
||||
.clip(shape.toShape())
|
||||
.background(MaterialTheme.colorScheme.primaryContainer),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
|
||||
@@ -35,7 +35,7 @@ androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-toolin
|
||||
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
|
||||
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version = "1.5.0-beta01" }
|
||||
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
|
||||
androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
|
||||
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
|
||||
|
||||
Reference in New Issue
Block a user