feat: 引入 YaYaTheme 并应用到所有 Activity
新增 Theme.kt 提供 Android 12+ 动态颜色支持, 为全部 5 个 Activity 的 setContent 包裹 YaYaTheme。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2b0491d7d7
commit
f34e34e5ae
@ -4,12 +4,14 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import plus.rua.project.ui.AboutScreen
|
||||
import plus.rua.project.ui.theme.YaYaTheme
|
||||
|
||||
class AboutActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
YaYaTheme {
|
||||
AboutScreen(
|
||||
onBack = { finishWithSlideBack() },
|
||||
onNavigateToLicenses = {
|
||||
@ -19,3 +21,4 @@ class AboutActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,15 +3,18 @@ package plus.rua.project
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import plus.rua.project.ui.DateCheckerScreen
|
||||
import plus.rua.project.ui.theme.YaYaTheme
|
||||
|
||||
class DateCheckerActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
YaYaTheme {
|
||||
DateCheckerScreen(
|
||||
onBack = { finishWithSlideBack() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,15 +3,18 @@ package plus.rua.project
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import plus.rua.project.ui.LicensesScreen
|
||||
import plus.rua.project.ui.theme.YaYaTheme
|
||||
|
||||
class LicensesActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
YaYaTheme {
|
||||
LicensesScreen(
|
||||
onBack = { finishWithSlideBack() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,12 +4,14 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import plus.rua.project.ui.CalendarMonthView
|
||||
import plus.rua.project.ui.theme.YaYaTheme
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
YaYaTheme {
|
||||
CalendarMonthView(
|
||||
onNavigateToAbout = {
|
||||
startActivityWithSlide(Intent(this, AboutActivity::class.java))
|
||||
@ -21,3 +23,4 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,12 +4,14 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import plus.rua.project.ui.ToolsScreen
|
||||
import plus.rua.project.ui.theme.YaYaTheme
|
||||
|
||||
class ToolsActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
YaYaTheme {
|
||||
ToolsScreen(
|
||||
onBack = { finishWithSlideBack() },
|
||||
onNavigateToDateChecker = {
|
||||
@ -19,3 +21,4 @@ class ToolsActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
core/src/main/kotlin/plus/rua/project/ui/theme/Theme.kt
Normal file
32
core/src/main/kotlin/plus/rua/project/ui/theme/Theme.kt
Normal file
@ -0,0 +1,32 @@
|
||||
package plus.rua.project.ui.theme
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
/**
|
||||
* YaYa 应用主题,Android 12+ 使用系统动态颜色,低版本回退到 Material 3 默认方案。
|
||||
*/
|
||||
@Composable
|
||||
fun YaYaTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val colorScheme = when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
val context = LocalContext.current
|
||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
else -> MaterialTheme.colorScheme
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user