Skip to content

Commit 0f0c00a

Browse files
author
Fastace
committed
UI:M3E风格-Done
1 parent fe8ee3c commit 0f0c00a

4 files changed

Lines changed: 68 additions & 11 deletions

File tree

source/app/src/main/kotlin/com/xayah/databackup/MainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.navigation.compose.rememberNavController
1616
import androidx.navigation.navArgument
1717
import androidx.navigation.NavType
1818
import java.net.URLDecoder
19+
import com.xayah.core.ui.theme.DataBackupExpressiveTheme
1920
import com.xayah.core.ui.component.AnimatedNavHost
2021
import com.xayah.core.ui.route.MainRoutes
2122
import com.xayah.core.ui.theme.DataBackupTheme
@@ -103,7 +104,9 @@ class MainActivity : AppCompatActivity() {
103104
startDestination = MainRoutes.Dashboard.route,
104105
) {
105106
composable(MainRoutes.Dashboard.route) {
106-
PageDashboard()
107+
DataBackupExpressiveTheme {
108+
PageDashboard()
109+
}
107110
}
108111
composable(MainRoutes.Cloud.route) {
109112
PageCloud()

source/core/ui/src/main/kotlin/com/xayah/core/ui/component/Common.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import androidx.compose.material.icons.outlined.Close
2424
import androidx.compose.material.icons.outlined.Folder
2525
import androidx.compose.material.icons.outlined.Shield
2626
import androidx.compose.material.icons.rounded.MoreHoriz
27+
import androidx.compose.material3.MaterialTheme
2728
import androidx.compose.material3.Card
2829
import androidx.compose.material3.CardDefaults
2930
import androidx.compose.material3.Checkbox
@@ -83,7 +84,7 @@ fun ActionButton(
8384
val interactionSource = remember { MutableInteractionSource() }
8485
Card(
8586
modifier = modifier.wrapContentHeight(),
86-
shape = RoundedCornerShape(SizeTokens.Level18),
87+
shape = MaterialTheme.shapes.medium,
8788
colors = CardDefaults.cardColors(containerColor = colorContainer.value.withState(enabled)),
8889
onClick = onClick,
8990
enabled = enabled,

source/core/ui/src/main/kotlin/com/xayah/core/ui/theme/Theme.kt

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.xayah.core.ui.theme
22

33
//import android.app.Activity
44
import android.os.Build
5+
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
6+
import androidx.compose.material3.MaterialExpressiveTheme
57
import androidx.appcompat.app.AppCompatDelegate
68
import androidx.compose.foundation.isSystemInDarkTheme
79
import androidx.compose.material3.MaterialTheme
@@ -87,8 +89,8 @@ fun DataBackupTheme(
8789
// val window = (view.context as Activity).window
8890
// window.statusBarColor = colorScheme.primary.toArgb()
8991
// WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
90-
// }
91-
// }
92+
// }
93+
// }
9294

9395
// Transparent system bars
9496
//val systemUiController = rememberSystemUiController()
@@ -98,11 +100,11 @@ fun DataBackupTheme(
98100
// darkIcons = !darkTheme
99101
// )
100102
// systemUiController.setNavigationBarColor(
101-
// color = Color.Transparent,
102-
// darkIcons = !darkTheme,
103-
// navigationBarContrastEnforced = false
104-
//)
105-
// }
103+
// color = Color.Transparent,
104+
// darkIcons = !darkTheme,
105+
// navigationBarContrastEnforced = false
106+
//)
107+
// }
106108

107109
MaterialTheme(
108110
colorScheme = colorScheme,
@@ -122,6 +124,55 @@ fun DataBackupTheme(
122124
)
123125
}
124126

127+
/**
128+
* Material 3 Expressive theme wrapper for the Dashboard page.
129+
* Uses MaterialExpressiveTheme which provides expressive shapes, motion, and typography.
130+
*/
131+
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
132+
@Composable
133+
fun DataBackupExpressiveTheme(
134+
content: @Composable () -> Unit,
135+
) {
136+
val context = LocalContext.current
137+
val darkTheme = darkTheme()
138+
139+
// Dynamic color is available on Android 12+
140+
val dynamicColor by observeMonetEnabled()
141+
val colorScheme = when {
142+
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
143+
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
144+
}
145+
146+
darkTheme -> darkColorScheme()
147+
else -> lightColorScheme()
148+
}
149+
val themedColorScheme = when {
150+
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
151+
if (darkTheme) dynamicDarkThemedColorScheme(context) else dynamicLightThemedColorScheme(context)
152+
}
153+
154+
darkTheme -> darkThemedColorScheme()
155+
else -> lightThemedColorScheme()
156+
}
157+
158+
MaterialExpressiveTheme(
159+
colorScheme = colorScheme,
160+
typography = Typography,
161+
content = {
162+
CompositionLocalProvider(
163+
LocalThemedColorScheme provides themedColorScheme,
164+
) {
165+
// LocalThemedColorScheme should be applied first.
166+
val slotScope = rememberSlotScope()
167+
CompositionLocalProvider(
168+
LocalSlotScope provides slotScope,
169+
content = content
170+
)
171+
}
172+
}
173+
)
174+
}
175+
125176
@Composable
126177
fun observeCurrentTheme(): State<ThemeType> {
127178
return LocalContext.current.readThemeType().collectImmediatelyAsState()
@@ -138,4 +189,4 @@ private fun <T> Flow<T>.collectImmediatelyAsState(): State<T> = produceState(
138189
key1 = this,
139190
) {
140191
drop(1).collect { value = it }
141-
}
192+
}

source/gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ androidx-test-ext-junit = "1.2.1"
1616
espresso-core = "3.6.1"
1717
junit = "4.13.2"
1818
compose-bom = "2025.12.00"
19+
material3 = "1.5.0-alpha16"
1920
core-ktx = "1.16.0"
2021
core-splashscreen = "1.0.1"
2122
gson = "2.10.1"
@@ -78,7 +79,8 @@ androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
7879
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
7980
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
8081
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
81-
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
82+
#androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
83+
androidx-compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" }
8284
androidx-compose-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" }
8385
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation-compose" }
8486
androidx-palette = { module = "androidx.palette:palette", version.ref = "palette" }

0 commit comments

Comments
 (0)