From 96cc7c221f4ce8f518eb0e3c356ecaeb498a3060 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 31 Mar 2024 23:35:23 +0800 Subject: [PATCH] Optimize - ToolGroupCard - performance optimization --- app/.gitignore | 3 ++- app/build.gradle.kts | 8 +++----- app/proguard-rules.pro | 5 ++++- .../oxygen/toolbox/ui/component/ToolGroupCard.kt | 16 +++++++++------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/.gitignore b/app/.gitignore index 1d10f0e..6372e33 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,2 +1,3 @@ /build -/src/main/res/raw/dependencies.json \ No newline at end of file +/src/main/res/raw/dependencies.json +/release/ diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d8eeaa9..0ac630a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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 { diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb43..3c04e7d 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -18,4 +18,7 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile + +-dontwarn kotlinx.serialization.KSerializer +-dontwarn kotlinx.serialization.Serializable \ No newline at end of file diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/ToolGroupCard.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/ToolGroupCard.kt index 03ae22e..c92489d 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/ToolGroupCard.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/ToolGroupCard.kt @@ -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 }) } } }