Compare commits

..
4 Commits
9 changed files with 305 additions and 40 deletions
+2
View File
@@ -16,6 +16,8 @@ captures/
.cxx/ .cxx/
*.apk *.apk
output.json output.json
output-metadata.json
app/release/
# IntelliJ # IntelliJ
*.iml *.iml
+14 -1
View File
@@ -41,4 +41,17 @@
} }
# Base32 and algorithms (in case of reflection or specific needs) # Base32 and algorithms (in case of reflection or specific needs)
-keep class cn.airnan.a2fair.core.algorithm.** { *; } -keep class cn.airnan.a2fair.core.algorithm.** { *; }
# ML Kit references optional google-http-client / joda-time paths that are
# absent from the Android artifact; the code paths are never exercised.
# Generated by AGP in app/build/outputs/mapping/release/missing_rules.txt
-dontwarn com.google.api.client.http.GenericUrl
-dontwarn com.google.api.client.http.HttpHeaders
-dontwarn com.google.api.client.http.HttpRequest
-dontwarn com.google.api.client.http.HttpRequestFactory
-dontwarn com.google.api.client.http.HttpResponse
-dontwarn com.google.api.client.http.HttpTransport
-dontwarn com.google.api.client.http.javanet.NetHttpTransport$Builder
-dontwarn com.google.api.client.http.javanet.NetHttpTransport
-dontwarn org.joda.time.Instant
@@ -216,6 +216,26 @@ fun AppNavigation(
} }
) { ) {
cn.airnan.a2fair.ui.settings.AboutScreen( cn.airnan.a2fair.ui.settings.AboutScreen(
onNavigateBack = { appState.navController.popBackStack() },
onNavigateToLicenses = { appState.navController.navigate("licenses") }
)
}
composable(
route = "licenses",
enterTransition = {
slideInHorizontally(initialOffsetX = { it }, animationSpec = tween(animDuration))
},
exitTransition = {
slideOutHorizontally(targetOffsetX = { -it / 3 }, animationSpec = tween(animDuration))
},
popEnterTransition = {
slideInHorizontally(initialOffsetX = { -it / 3 }, animationSpec = tween(animDuration))
},
popExitTransition = {
slideOutHorizontally(targetOffsetX = { it }, animationSpec = tween(animDuration))
}
) {
cn.airnan.a2fair.ui.settings.OpenSourceLicensesScreen(
onNavigateBack = { appState.navController.popBackStack() } onNavigateBack = { appState.navController.popBackStack() }
) )
} }
@@ -34,7 +34,8 @@ import cn.airnan.a2fair.R
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun AboutScreen( fun AboutScreen(
onNavigateBack: () -> Unit onNavigateBack: () -> Unit,
onNavigateToLicenses: () -> Unit = {}
) { ) {
val context = LocalContext.current val context = LocalContext.current
@@ -87,18 +88,16 @@ fun AboutScreen(
ListItem( ListItem(
headlineContent = { Text(stringResource(R.string.source_code)) }, headlineContent = { Text(stringResource(R.string.source_code)) },
supportingContent = { Text(stringResource(R.string.view_on_github)) }, supportingContent = { Text(stringResource(R.string.view_on_gitea)) },
modifier = Modifier.clickable { modifier = Modifier.clickable {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/")) val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://git.airnan.cn/wangairnan/2FAir"))
context.startActivity(intent) context.startActivity(intent)
} }
) )
ListItem( ListItem(
headlineContent = { Text(stringResource(R.string.open_source_licenses)) }, headlineContent = { Text(stringResource(R.string.open_source_licenses)) },
modifier = Modifier.clickable { modifier = Modifier.clickable { onNavigateToLicenses() }
// TODO: Implement license viewer or navigation
}
) )
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
@@ -0,0 +1,142 @@
package cn.airnan.a2fair.ui.settings
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
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.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import cn.airnan.a2fair.R
private data class LibraryLicense(
val name: String,
val url: String
)
private data class LicenseGroup(
val license: String,
val licenseUrl: String,
val libraries: List<LibraryLicense>
)
private val APACHE_2_0_URL = "https://www.apache.org/licenses/LICENSE-2.0"
private val licenseGroups = listOf(
LicenseGroup(
license = "Apache License 2.0",
licenseUrl = APACHE_2_0_URL,
libraries = listOf(
LibraryLicense(
name = "AndroidX & Jetpack Compose",
url = "https://developer.android.com/jetpack"
),
LibraryLicense(
name = "Material Components for Android",
url = "https://github.com/material-components/material-components-android"
),
LibraryLicense(
name = "Kotlin & Coroutines",
url = "https://github.com/JetBrains/kotlin"
),
LibraryLicense(
name = "KSP (Kotlin Symbol Processing)",
url = "https://github.com/google/ksp"
),
LibraryLicense(
name = "ZXing Core",
url = "https://github.com/zxing/zxing"
),
LibraryLicense(
name = "Gson",
url = "https://github.com/google/gson"
)
)
),
LicenseGroup(
license = "ML Kit Terms of Service",
licenseUrl = "https://developers.google.com/ml-kit/terms",
libraries = listOf(
LibraryLicense(
name = "ML Kit Barcode Scanning",
url = "https://developers.google.com/ml-kit"
)
)
)
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun OpenSourceLicensesScreen(
onNavigateBack: () -> Unit
) {
val context = LocalContext.current
val openUrl: (String) -> Unit = { url ->
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}
Scaffold(
topBar = {
TopAppBar(
title = { Text(stringResource(R.string.open_source_licenses)) },
navigationIcon = {
IconButton(onClick = onNavigateBack) {
Icon(Icons.Default.ArrowBack, contentDescription = stringResource(R.string.back))
}
}
)
}
) { padding ->
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(padding)
) {
item {
Text(
text = stringResource(R.string.licenses_desc),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(start = 16.dp, top = 8.dp, end = 16.dp, bottom = 8.dp)
)
}
licenseGroups.forEach { group ->
item(key = "license_${group.license}") {
ListItem(
headlineContent = { Text(group.license) },
supportingContent = { Text(group.licenseUrl, maxLines = 1, overflow = TextOverflow.Ellipsis) },
modifier = Modifier.clickable { openUrl(group.licenseUrl) }
)
HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp))
}
items(group.libraries, key = { "lib_${group.license}_${it.name}" }) { library ->
ListItem(
headlineContent = { Text(library.name) },
supportingContent = { Text(library.url, maxLines = 1, overflow = TextOverflow.Ellipsis) },
modifier = Modifier.clickable { openUrl(library.url) }
)
HorizontalDivider(modifier = Modifier.padding(horizontal = 16.dp))
}
}
}
}
}
@@ -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?,
+6 -1
View File
@@ -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>
@@ -148,7 +152,8 @@
<string name="app_icon">应用图标</string> <string name="app_icon">应用图标</string>
<string name="version_format">版本 %s</string> <string name="version_format">版本 %s</string>
<string name="source_code">源代码</string> <string name="source_code">源代码</string>
<string name="view_on_github">在 GitHub 上查看</string> <string name="view_on_gitea">在作者的 Gitea 上查看</string>
<string name="licenses_desc">本应用使用了以下开源项目。</string>
<string name="open_source_licenses">开源许可</string> <string name="open_source_licenses">开源许可</string>
<string name="copyright">© 2026 2FAir</string> <string name="copyright">© 2026 2FAir</string>
+6 -1
View File
@@ -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>
@@ -148,7 +152,8 @@
<string name="app_icon">應用程式圖示</string> <string name="app_icon">應用程式圖示</string>
<string name="version_format">版本 %s</string> <string name="version_format">版本 %s</string>
<string name="source_code">原始碼</string> <string name="source_code">原始碼</string>
<string name="view_on_github">在 GitHub 上檢視</string> <string name="view_on_gitea">在作者的 Gitea 上檢視</string>
<string name="licenses_desc">本應用程式使用了以下開放原始碼專案。</string>
<string name="open_source_licenses">開放原始碼授權</string> <string name="open_source_licenses">開放原始碼授權</string>
<string name="copyright">© 2026 2FAir</string> <string name="copyright">© 2026 2FAir</string>
+6 -1
View File
@@ -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>
@@ -148,7 +152,8 @@
<string name="app_icon">App Icon</string> <string name="app_icon">App Icon</string>
<string name="version_format">Version %s</string> <string name="version_format">Version %s</string>
<string name="source_code">Source Code</string> <string name="source_code">Source Code</string>
<string name="view_on_github">View on GitHub</string> <string name="view_on_gitea">View on author\'s Gitea</string>
<string name="licenses_desc">This app is built with the help of the following open source projects.</string>
<string name="open_source_licenses">Open Source Licenses</string> <string name="open_source_licenses">Open Source Licenses</string>
<string name="copyright">© 2026 2FAir</string> <string name="copyright">© 2026 2FAir</string>