Skip to content

Commit 86746fc

Browse files
改进卡片设计
1 parent 1476317 commit 86746fc

3 files changed

Lines changed: 143 additions & 43 deletions

File tree

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,95 @@
11
package me.bmax.apatch.ui.component
22

3+
import androidx.compose.foundation.layout.ColumnScope
34
import androidx.compose.foundation.shape.CornerBasedShape
45
import androidx.compose.foundation.shape.RoundedCornerShape
6+
import androidx.compose.material3.DropdownMenu
7+
import androidx.compose.material3.DropdownMenuItem
58
import androidx.compose.material3.MaterialTheme
69
import androidx.compose.runtime.Composable
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.draw.shadow
12+
import androidx.compose.ui.graphics.Color
713
import androidx.compose.ui.unit.dp
14+
import me.bmax.apatch.ui.theme.BackgroundConfig
815

916
@Composable
1017
fun ProvideMenuShape(
1118
value: CornerBasedShape = RoundedCornerShape(8.dp), content: @Composable () -> Unit
1219
) = MaterialTheme(
1320
shapes = MaterialTheme.shapes.copy(extraSmall = value), content = content
14-
)
21+
)
22+
23+
@Composable
24+
fun WallpaperAwareDropdownMenu(
25+
expanded: Boolean,
26+
onDismissRequest: () -> Unit,
27+
modifier: Modifier = Modifier,
28+
shape: CornerBasedShape = RoundedCornerShape(10.dp),
29+
containerColor: androidx.compose.ui.graphics.Color = androidx.compose.material3.MaterialTheme.colorScheme.surfaceContainer,
30+
content: @Composable ColumnScope.() -> Unit
31+
) {
32+
// 在壁纸模式下移除阴影效果
33+
if (BackgroundConfig.isCustomBackgroundEnabled) {
34+
DropdownMenu(
35+
expanded = expanded,
36+
onDismissRequest = onDismissRequest,
37+
modifier = modifier.shadow(
38+
elevation = 0.dp,
39+
shape = shape,
40+
ambientColor = Color.Transparent,
41+
spotColor = Color.Transparent
42+
),
43+
shape = shape,
44+
tonalElevation = 0.dp, // 在壁纸模式下不使用阴影
45+
shadowElevation = 0.dp, // 确保没有阴影
46+
containerColor = containerColor.copy(alpha = 0.95f), // 略微透明,与壁纸更好地融合
47+
content = content
48+
)
49+
} else {
50+
DropdownMenu(
51+
expanded = expanded,
52+
onDismissRequest = onDismissRequest,
53+
modifier = modifier,
54+
shape = shape,
55+
tonalElevation = 3.dp, // 默认阴影
56+
shadowElevation = 3.dp, // 默认阴影
57+
containerColor = containerColor,
58+
content = content
59+
)
60+
}
61+
}
62+
63+
@Composable
64+
fun WallpaperAwareDropdownMenuItem(
65+
text: @Composable () -> Unit,
66+
onClick: () -> Unit,
67+
modifier: Modifier = Modifier,
68+
leadingIcon: @Composable (() -> Unit)? = null,
69+
trailingIcon: @Composable (() -> Unit)? = null,
70+
enabled: Boolean = true
71+
) {
72+
if (BackgroundConfig.isCustomBackgroundEnabled) {
73+
DropdownMenuItem(
74+
text = text,
75+
onClick = onClick,
76+
modifier = modifier.shadow(
77+
elevation = 0.dp,
78+
ambientColor = Color.Transparent,
79+
spotColor = Color.Transparent
80+
),
81+
leadingIcon = leadingIcon,
82+
trailingIcon = trailingIcon,
83+
enabled = enabled
84+
)
85+
} else {
86+
DropdownMenuItem(
87+
text = text,
88+
onClick = onClick,
89+
modifier = modifier,
90+
leadingIcon = leadingIcon,
91+
trailingIcon = trailingIcon,
92+
enabled = enabled
93+
)
94+
}
95+
}

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

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import androidx.compose.material3.BasicAlertDialog
4040
import androidx.compose.material3.Button
4141
import androidx.compose.material3.CardDefaults
4242
import androidx.compose.material3.DropdownMenu
43-
import me.bmax.apatch.ui.theme.BackgroundConfig
4443
import androidx.compose.material3.DropdownMenuItem
44+
import me.bmax.apatch.ui.theme.BackgroundConfig
4545
import androidx.compose.material3.ElevatedCard
4646
import androidx.compose.material3.ExperimentalMaterial3Api
4747
import androidx.compose.material3.Icon
@@ -88,6 +88,8 @@ import me.bmax.apatch.Natives
8888
import me.bmax.apatch.R
8989
import me.bmax.apatch.apApp
9090
import me.bmax.apatch.ui.component.ProvideMenuShape
91+
import me.bmax.apatch.ui.component.WallpaperAwareDropdownMenu
92+
import me.bmax.apatch.ui.component.WallpaperAwareDropdownMenuItem
9193
import me.bmax.apatch.ui.component.rememberConfirmDialog
9294
import me.bmax.apatch.ui.viewmodel.PatchesViewModel
9395
import me.bmax.apatch.util.Version
@@ -410,18 +412,31 @@ private fun TopBar(
410412
contentDescription = stringResource(id = R.string.reboot)
411413
)
412414

413-
ProvideMenuShape(RoundedCornerShape(10.dp)) {
414-
DropdownMenu(
415-
expanded = showDropdownReboot,
416-
onDismissRequest = { showDropdownReboot = false },
417-
containerColor = MaterialTheme.colorScheme.surfaceContainer
418-
) {
419-
RebootDropdownItem(id = R.string.reboot)
420-
RebootDropdownItem(id = R.string.reboot_recovery, reason = "recovery")
421-
RebootDropdownItem(id = R.string.reboot_bootloader, reason = "bootloader")
422-
RebootDropdownItem(id = R.string.reboot_download, reason = "download")
423-
RebootDropdownItem(id = R.string.reboot_edl, reason = "edl")
424-
}
415+
WallpaperAwareDropdownMenu(
416+
expanded = showDropdownReboot,
417+
onDismissRequest = { showDropdownReboot = false },
418+
shape = RoundedCornerShape(10.dp)
419+
) {
420+
WallpaperAwareDropdownMenuItem(
421+
text = { Text(stringResource(id = R.string.reboot)) },
422+
onClick = { reboot() }
423+
)
424+
WallpaperAwareDropdownMenuItem(
425+
text = { Text(stringResource(id = R.string.reboot_recovery)) },
426+
onClick = { reboot("recovery") }
427+
)
428+
WallpaperAwareDropdownMenuItem(
429+
text = { Text(stringResource(id = R.string.reboot_bootloader)) },
430+
onClick = { reboot("bootloader") }
431+
)
432+
WallpaperAwareDropdownMenuItem(
433+
text = { Text(stringResource(id = R.string.reboot_download)) },
434+
onClick = { reboot("download") }
435+
)
436+
WallpaperAwareDropdownMenuItem(
437+
text = { Text(stringResource(id = R.string.reboot_edl)) },
438+
onClick = { reboot("edl") }
439+
)
425440
}
426441
}
427442
}
@@ -432,25 +447,25 @@ private fun TopBar(
432447
imageVector = Icons.Filled.MoreVert,
433448
contentDescription = stringResource(id = R.string.settings)
434449
)
435-
ProvideMenuShape(RoundedCornerShape(10.dp)) {
436-
DropdownMenu(
437-
expanded = showDropdownMoreOptions,
438-
onDismissRequest = { showDropdownMoreOptions = false },
439-
containerColor = MaterialTheme.colorScheme.surfaceContainer
440-
) {
441-
DropdownMenuItem(text = {
442-
Text(stringResource(R.string.home_more_menu_feedback_or_suggestion))
443-
}, onClick = {
450+
WallpaperAwareDropdownMenu(
451+
expanded = showDropdownMoreOptions,
452+
onDismissRequest = { showDropdownMoreOptions = false },
453+
shape = RoundedCornerShape(10.dp)
454+
) {
455+
WallpaperAwareDropdownMenuItem(
456+
text = { Text(stringResource(R.string.home_more_menu_feedback_or_suggestion)) },
457+
onClick = {
444458
showDropdownMoreOptions = false
445459
uriHandler.openUri("https://github.com/matsuzaka-yuki/FolkPatch/issues/new/choose")
446-
})
447-
DropdownMenuItem(text = {
448-
Text(stringResource(R.string.home_more_menu_about))
449-
}, onClick = {
460+
}
461+
)
462+
WallpaperAwareDropdownMenuItem(
463+
text = { Text(stringResource(R.string.home_more_menu_about)) },
464+
onClick = {
450465
navigator.navigate(AboutScreenDestination)
451466
showDropdownMoreOptions = false
452-
})
453-
}
467+
}
468+
)
454469
}
455470
}
456471
}

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import me.bmax.apatch.R
5858
import me.bmax.apatch.ui.component.ProvideMenuShape
5959
import me.bmax.apatch.ui.component.SearchAppBar
6060
import me.bmax.apatch.ui.component.SwitchItem
61+
import me.bmax.apatch.ui.component.WallpaperAwareDropdownMenu
62+
import me.bmax.apatch.ui.component.WallpaperAwareDropdownMenuItem
6163
import me.bmax.apatch.ui.component.rememberConfirmDialog
6264
import me.bmax.apatch.ui.viewmodel.SuperUserViewModel
6365
import me.bmax.apatch.util.PkgConfig
@@ -111,34 +113,36 @@ fun SuperUserScreen() {
111113
contentDescription = stringResource(id = R.string.settings)
112114
)
113115

114-
ProvideMenuShape(RoundedCornerShape(10.dp)) {
115-
DropdownMenu(
116-
expanded = showDropdown,
117-
onDismissRequest = { showDropdown = false },
118-
containerColor = MaterialTheme.colorScheme.surfaceContainer
119-
) {
120-
DropdownMenuItem(text = {
121-
Text(stringResource(R.string.su_refresh))
122-
}, onClick = {
116+
WallpaperAwareDropdownMenu(
117+
expanded = showDropdown,
118+
onDismissRequest = { showDropdown = false },
119+
shape = RoundedCornerShape(10.dp)
120+
) {
121+
WallpaperAwareDropdownMenuItem(
122+
text = { Text(stringResource(R.string.su_refresh)) },
123+
onClick = {
123124
scope.launch {
124125
viewModel.fetchAppList()
125126
}
126127
showDropdown = false
127-
})
128+
}
129+
)
128130

129-
DropdownMenuItem(text = {
131+
WallpaperAwareDropdownMenuItem(
132+
text = {
130133
Text(
131134
if (viewModel.showSystemApps) {
132135
stringResource(R.string.su_hide_system_apps)
133136
} else {
134137
stringResource(R.string.su_show_system_apps)
135138
}
136139
)
137-
}, onClick = {
140+
},
141+
onClick = {
138142
viewModel.showSystemApps = !viewModel.showSystemApps
139143
showDropdown = false
140-
})
141-
}
144+
}
145+
)
142146
}
143147
}
144148
},

0 commit comments

Comments
 (0)