Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions app/src/main/java/me/bmax/apatch/ui/screen/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import androidx.compose.material3.Button
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Card
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand Down Expand Up @@ -473,29 +475,30 @@ private fun KStatusCard(
UninstallDialog(showDialog = showUninstallDialog, navigator)
}

val cardBackgroundColor = when (kpState) {
val (cardBackgroundColor, cardContentColor) = when (kpState) {
APApplication.State.KERNELPATCH_INSTALLED -> {
MaterialTheme.colorScheme.primary
MaterialTheme.colorScheme.primary to MaterialTheme.colorScheme.onPrimary
}

APApplication.State.KERNELPATCH_NEED_UPDATE, APApplication.State.KERNELPATCH_NEED_REBOOT -> {
MaterialTheme.colorScheme.secondary
MaterialTheme.colorScheme.secondary to MaterialTheme.colorScheme.onSecondary
}

else -> {
MaterialTheme.colorScheme.secondaryContainer
MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp) to MaterialTheme.colorScheme.onSurface
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want to do
I think you should read Android's UI design documents first Click There

You can see from this document, card colors use surfaceContainer,
we already have surface surfaceContainerLowest surfaceContainerLow surfaceContainer surfaceContainerHigh surfaceContainerHighest 6 elevation colors in theme, why manually calc that?

I think manually calc elevation colors is unnecessary, and will cause more rendering time, because you are do math calc internally rather than directly using data calculated at application startup!

}
}

ElevatedCard(
Card(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to notice to you, you no need to switch to Card, because ElevatedCard basically is an alias of Card itself

@Composable
fun ElevatedCard(
    modifier: Modifier = Modifier,
    shape: Shape = CardDefaults.elevatedShape,
    colors: CardColors = CardDefaults.elevatedCardColors(),
    elevation: CardElevation = CardDefaults.elevatedCardElevation(),
    content: @Composable ColumnScope.() -> Unit,
) =
    Card(
        modifier = modifier,
        shape = shape,
        border = null,
        elevation = elevation,
        colors = colors,
        content = content,
    )

This is a code snippet of material3-android library, as you can see, ElevatedCard is an card without border, that is all
You no need change that if you just want change contentColor, and btw, you lost elevation set

And if you want unify, you should package your own Card control, NOT CHANGE EVERYWHERE TO WASTE, THAT IS A NIGHTMARE

onClick = {
if (kpState != APApplication.State.KERNELPATCH_INSTALLED) {
navigator.navigate(InstallModeSelectScreenDestination)
}
},
colors = CardDefaults.elevatedCardColors(containerColor = cardBackgroundColor),
elevation = CardDefaults.cardElevation(
defaultElevation = if (kpState == APApplication.State.UNKNOWN_STATE) 0.dp else 6.dp
shape = RoundedCornerShape(20.dp),
colors = CardDefaults.cardColors(
containerColor = cardBackgroundColor,
contentColor = cardContentColor
)
) {
Column(
Expand Down Expand Up @@ -644,10 +647,9 @@ private fun KStatusCard(

@Composable
private fun AStatusCard(apState: APApplication.State) {
ElevatedCard(
colors = CardDefaults.elevatedCardColors(containerColor = run {
MaterialTheme.colorScheme.secondaryContainer
})
Card(
shape = RoundedCornerShape(20.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -858,7 +860,10 @@ private fun getDeviceInfo(): String {

@Composable
private fun InfoCard(kpState: APApplication.State, apState: APApplication.State) {
ElevatedCard {
Card(
shape = RoundedCornerShape(20.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
) {
Column(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -952,7 +957,10 @@ fun UpdateCard() {
fun LearnMoreCard() {
val uriHandler = LocalUriHandler.current

ElevatedCard {
Card(
shape = RoundedCornerShape(20.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
) {
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down