Optimize - ToolGroupCard - performance optimization

This commit is contained in:
2024-03-31 23:35:23 +08:00
parent f81f26a5cb
commit 96cc7c221f
4 changed files with 18 additions and 14 deletions

3
app/.gitignore vendored
View File

@@ -1,2 +1,3 @@
/build /build
/src/main/res/raw/dependencies.json /src/main/res/raw/dependencies.json
/release/

View File

@@ -25,15 +25,12 @@ android {
vectorDrawables { vectorDrawables {
useSupportLibrary = true useSupportLibrary = true
} }
// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
} }
buildTypes { buildTypes {
release { release {
isMinifyEnabled = true isMinifyEnabled = false
isShrinkResources = true isShrinkResources = false
proguardFiles( proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"), getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro" "proguard-rules.pro"
@@ -116,6 +113,7 @@ task("exportLibrariesToJson", AboutLibrariesTask::class) {
afterEvaluate { afterEvaluate {
tasks.findByName("preBuild")?.dependsOn(tasks.findByName("exportLibrariesToJson")) tasks.findByName("preBuild")?.dependsOn(tasks.findByName("exportLibrariesToJson"))
tasks.findByName("kspDebugKotlin")?.dependsOn(tasks.findByName("generateDebugProto")) tasks.findByName("kspDebugKotlin")?.dependsOn(tasks.findByName("generateDebugProto"))
tasks.findByName("kspReleaseKotlin")?.dependsOn(tasks.findByName("generateReleaseProto"))
} }
dependencies { dependencies {

View File

@@ -18,4 +18,7 @@
# If you keep the line number information, uncomment this to # If you keep the line number information, uncomment this to
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
-dontwarn kotlinx.serialization.KSerializer
-dontwarn kotlinx.serialization.Serializable

View File

@@ -45,7 +45,7 @@ fun ToolGroupCard(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
toolGroup: ToolGroup, toolGroup: ToolGroup,
isExpanded: Boolean = true, isExpanded: Boolean = true,
onExpandSwitch: ((newStatus: Boolean) -> Unit)? = null onExpandSwitch: (() -> Unit)? = null
) { ) {
val (_, icon, title, tools) = toolGroup val (_, icon, title, tools) = toolGroup
@@ -55,11 +55,13 @@ fun ToolGroupCard(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface) colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface)
) { ) {
Column { Column {
ToolGroupTitle(modifier = Modifier.padding(16.dp), ToolGroupTitle(
modifier = Modifier.padding(16.dp),
icon = icon, icon = icon,
title = title, title = title,
isExpanded = isExpanded, isExpanded = isExpanded,
onClick = { onExpandSwitch?.let { it(!isExpanded) } }) onClick = onExpandSwitch
)
AnimatedVisibility(visible = isExpanded) { AnimatedVisibility(visible = isExpanded) {
ToolGroupContent(modifier = Modifier.padding(16.dp), toolList = tools) ToolGroupContent(modifier = Modifier.padding(16.dp), toolList = tools)
} }
@@ -75,7 +77,7 @@ fun ToolGroupTitle(
isExpanded: Boolean, isExpanded: Boolean,
onClick: (() -> Unit)? = null onClick: (() -> Unit)? = null
) { ) {
Surface(onClick = { onClick?.let { it() } }) { Surface(onClick = onClick ?: {}) {
Row( Row(
modifier = modifier, modifier = modifier,
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
@@ -99,7 +101,7 @@ fun ToolGroupContent(
modifier = modifier, modifier = modifier,
horizontalArrangement = Arrangement.spacedBy(8.dp) horizontalArrangement = Arrangement.spacedBy(8.dp)
) { ) {
toolList.mapIndexed { index, it -> toolList.map {
ToolGroupItem(icon = it.icon, title = it.name) ToolGroupItem(icon = it.icon, title = it.name)
} }
} }
@@ -115,7 +117,7 @@ fun ToolGroupItem(
Card( Card(
modifier = modifier, modifier = modifier,
shape = RoundedCornerShape(100), shape = RoundedCornerShape(100),
onClick = { onClick?.let { it() } } onClick = onClick ?: { }
) { ) {
Box( Box(
modifier = Modifier.padding(8.dp) modifier = Modifier.padding(8.dp)
@@ -167,7 +169,7 @@ private fun ToolGroupCardPreview() {
ToolGroupCard( ToolGroupCard(
toolGroup = item, toolGroup = item,
isExpanded = isExpanded, isExpanded = isExpanded,
onExpandSwitch = { isExpanded = it }) onExpandSwitch = { isExpanded = !isExpanded })
} }
} }
} }