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
/src/main/res/raw/dependencies.json
/src/main/res/raw/dependencies.json
/release/

View File

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

View File

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