Skip to content

Commit d43fcea

Browse files
更好的背景设计
1 parent 02435dc commit d43fcea

5 files changed

Lines changed: 312 additions & 30 deletions

File tree

app/src/main/java/me/bmax/apatch/ui/MainActivity.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ import me.bmax.apatch.APApplication
4949
import me.bmax.apatch.ui.screen.BottomBarDestination
5050
import me.bmax.apatch.ui.theme.APatchTheme
5151
import me.bmax.apatch.ui.theme.APatchThemeWithBackground
52+
import me.bmax.apatch.ui.theme.BackgroundConfig
53+
import androidx.compose.material3.NavigationBarDefaults
54+
import androidx.compose.material3.MaterialTheme
5255
import me.bmax.apatch.util.PermissionRequestHandler
5356
import me.bmax.apatch.util.PermissionUtils
5457
import me.bmax.apatch.util.ui.LocalSnackbarHost
@@ -186,7 +189,14 @@ private fun BottomBar(navController: NavHostController) {
186189
val kPatchReady = state != APApplication.State.UNKNOWN_STATE
187190
val aPatchReady = state == APApplication.State.ANDROIDPATCH_INSTALLED
188191

189-
NavigationBar(tonalElevation = 8.dp) {
192+
NavigationBar(
193+
tonalElevation = 8.dp,
194+
containerColor = if (BackgroundConfig.isCustomBackgroundEnabled) {
195+
MaterialTheme.colorScheme.surface
196+
} else {
197+
NavigationBarDefaults.containerColor
198+
}
199+
) {
190200
BottomBarDestination.entries.forEach { destination ->
191201
val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction)
192202

app/src/main/java/me/bmax/apatch/ui/screen/Settings.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
7171
import androidx.compose.runtime.setValue
7272
import androidx.compose.ui.Alignment
7373
import androidx.compose.ui.Modifier
74+
import androidx.compose.ui.graphics.Color
7475
import androidx.compose.ui.platform.LocalContext
7576
import androidx.compose.ui.platform.LocalView
7677
import androidx.compose.ui.res.stringArrayResource
@@ -156,6 +157,11 @@ fun SettingScreen() {
156157
title = { Text(stringResource(R.string.settings)) },
157158
)
158159
},
160+
containerColor = if (BackgroundConfig.isCustomBackgroundEnabled) {
161+
Color.Transparent
162+
} else {
163+
MaterialTheme.colorScheme.background
164+
},
159165
snackbarHost = { SnackbarHost(snackBarHost) }
160166
) { paddingValues ->
161167

app/src/main/java/me/bmax/apatch/ui/theme/Theme.kt

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,25 @@ fun APatchTheme(
182182
}
183183

184184
val colorScheme = baseColorScheme.copy(
185-
background = if (BackgroundConfig.isCustomBackgroundEnabled && !isSettingsScreen) Color.Transparent else baseColorScheme.background,
186-
surface = if (BackgroundConfig.isCustomBackgroundEnabled && !isSettingsScreen) {
185+
background = if (BackgroundConfig.isCustomBackgroundEnabled) Color.Transparent else baseColorScheme.background,
186+
surface = if (BackgroundConfig.isCustomBackgroundEnabled) {
187187
// 在自定义背景模式下,为surface添加半透明效果
188188
baseColorScheme.surface.copy(alpha = 0.75f)
189189
} else {
190190
baseColorScheme.surface
191191
},
192192
// 同样处理primary和secondary颜色,确保KStatusCard也有半透明效果
193-
primary = if (BackgroundConfig.isCustomBackgroundEnabled && !isSettingsScreen) {
193+
primary = if (BackgroundConfig.isCustomBackgroundEnabled) {
194194
baseColorScheme.primary.copy(alpha = 0.75f)
195195
} else {
196196
baseColorScheme.primary
197197
},
198-
secondary = if (BackgroundConfig.isCustomBackgroundEnabled && !isSettingsScreen) {
198+
secondary = if (BackgroundConfig.isCustomBackgroundEnabled) {
199199
baseColorScheme.secondary.copy(alpha = 0.75f)
200200
} else {
201201
baseColorScheme.secondary
202202
},
203-
secondaryContainer = if (BackgroundConfig.isCustomBackgroundEnabled && !isSettingsScreen) {
203+
secondaryContainer = if (BackgroundConfig.isCustomBackgroundEnabled) {
204204
baseColorScheme.secondaryContainer.copy(alpha = 0.75f)
205205
} else {
206206
baseColorScheme.secondaryContainer
@@ -240,11 +240,10 @@ fun APatchThemeWithBackground(
240240

241241
APatchTheme(isSettingsScreen = isSettingsScreen) {
242242
Box(modifier = Modifier.fillMaxSize()) {
243-
// 只有不在设置页面时才显示背景层
244-
if (!isSettingsScreen) {
245-
BackgroundLayer()
246-
}
247-
// 内容层 - 添加zIndex确保在背景之上
243+
// Always show background layer if enabled
244+
BackgroundLayer()
245+
246+
// Content layer - add zIndex to ensure it's above the background
248247
Box(modifier = Modifier.fillMaxSize().zIndex(1f)) {
249248
content()
250249
}
@@ -299,22 +298,5 @@ fun BackgroundLayer() {
299298
.zIndex(-1f)
300299
.paint(painter = painter, contentScale = ContentScale.Crop)
301300
)
302-
303-
// 只在暗色模式下添加半透明遮罩层,白天模式下不添加
304-
if (darkTheme) {
305-
Box(
306-
modifier = Modifier
307-
.fillMaxSize()
308-
.zIndex(-1f)
309-
.background(
310-
Brush.verticalGradient(
311-
colors = listOf(
312-
Color.Black.copy(alpha = 0.4f),
313-
Color.Black.copy(alpha = 0.2f)
314-
)
315-
)
316-
)
317-
)
318-
}
319301
}
320302
}

0 commit comments

Comments
 (0)