diff --git a/app/src/main/java/cn/airnan/a2fair/ui/navigation/AppNavigation.kt b/app/src/main/java/cn/airnan/a2fair/ui/navigation/AppNavigation.kt index 38a7e9e..66c837b 100644 --- a/app/src/main/java/cn/airnan/a2fair/ui/navigation/AppNavigation.kt +++ b/app/src/main/java/cn/airnan/a2fair/ui/navigation/AppNavigation.kt @@ -216,6 +216,26 @@ fun AppNavigation( } ) { 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() } ) } diff --git a/app/src/main/java/cn/airnan/a2fair/ui/settings/AboutScreen.kt b/app/src/main/java/cn/airnan/a2fair/ui/settings/AboutScreen.kt index cbbec84..82e4079 100644 --- a/app/src/main/java/cn/airnan/a2fair/ui/settings/AboutScreen.kt +++ b/app/src/main/java/cn/airnan/a2fair/ui/settings/AboutScreen.kt @@ -34,7 +34,8 @@ import cn.airnan.a2fair.R @OptIn(ExperimentalMaterial3Api::class) @Composable fun AboutScreen( - onNavigateBack: () -> Unit + onNavigateBack: () -> Unit, + onNavigateToLicenses: () -> Unit = {} ) { val context = LocalContext.current @@ -87,18 +88,16 @@ fun AboutScreen( ListItem( 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 { - 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) } ) ListItem( headlineContent = { Text(stringResource(R.string.open_source_licenses)) }, - modifier = Modifier.clickable { - // TODO: Implement license viewer or navigation - } + modifier = Modifier.clickable { onNavigateToLicenses() } ) Spacer(modifier = Modifier.weight(1f)) diff --git a/app/src/main/java/cn/airnan/a2fair/ui/settings/OpenSourceLicensesScreen.kt b/app/src/main/java/cn/airnan/a2fair/ui/settings/OpenSourceLicensesScreen.kt new file mode 100644 index 0000000..c8ddabd --- /dev/null +++ b/app/src/main/java/cn/airnan/a2fair/ui/settings/OpenSourceLicensesScreen.kt @@ -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 +) + +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)) + } + } + } + } +} diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index a8553ae..2d0c3bf 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -152,7 +152,8 @@ 应用图标 版本 %s 源代码 - 在 GitHub 上查看 + 在作者的 Gitea 上查看 + 本应用使用了以下开源项目。 开源许可 © 2026 2FAir diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index efe6391..148ab75 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -152,7 +152,8 @@ 應用程式圖示 版本 %s 原始碼 - 在 GitHub 上檢視 + 在作者的 Gitea 上檢視 + 本應用程式使用了以下開放原始碼專案。 開放原始碼授權 © 2026 2FAir diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7b98f76..14907a7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -152,7 +152,8 @@ App Icon Version %s Source Code - View on GitHub + View on author\'s Gitea + This app is built with the help of the following open source projects. Open Source Licenses © 2026 2FAir