Skip to content

Commit edd4c56

Browse files
committed
optimize code
1 parent e0f2506 commit edd4c56

File tree

10 files changed

+59
-86
lines changed

10 files changed

+59
-86
lines changed

.github/workflows/create_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
body: "create by workflows"
4242
allowUpdates: true
4343
artifactErrorsFailBuild: true
44-
generateReleaseNotes: false
44+
generateReleaseNotes: true
4545
token: ${{secrets.ACTION_TOKEN}}
4646
name: ${{steps.currentTime.outputs.formattedTime}}
4747
tag: ${{steps.currentTime.outputs.formattedTime}}

app/src/main/java/github/leavesczy/compose_chat/ui/chat/ChatActivity.kt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import android.os.Bundle
77
import androidx.compose.foundation.layout.Box
88
import androidx.compose.foundation.layout.fillMaxSize
99
import androidx.compose.foundation.layout.padding
10-
import androidx.compose.material.pullrefresh.PullRefreshIndicator
11-
import androidx.compose.material.pullrefresh.pullRefresh
12-
import androidx.compose.material.pullrefresh.rememberPullRefreshState
1310
import androidx.compose.material3.Scaffold
11+
import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults
12+
import androidx.compose.material3.pulltorefresh.pullToRefresh
13+
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
1414
import androidx.compose.runtime.Composable
1515
import androidx.compose.ui.Alignment
1616
import androidx.compose.ui.Modifier
@@ -121,32 +121,31 @@ private fun ChatPage(chatViewModel: ChatViewModel, chatPageAction: ChatPageActio
121121
ChatPageBottomBar(chatViewModel = chatViewModel)
122122
}
123123
) { innerPadding ->
124-
val pullRefreshState = rememberPullRefreshState(
125-
refreshing = chatViewModel.loadMessageViewState.refreshing,
126-
onRefresh = {
127-
chatViewModel.loadMoreMessage()
128-
}
129-
)
124+
val pullRefreshState = rememberPullToRefreshState()
130125
Box(
131126
modifier = Modifier
132127
.padding(paddingValues = innerPadding)
133128
.fillMaxSize()
134-
.pullRefresh(
129+
.pullToRefresh(
135130
state = pullRefreshState,
136-
enabled = !chatViewModel.loadMessageViewState.loadFinish
131+
enabled = !chatViewModel.loadMessageViewState.loadFinish,
132+
isRefreshing = chatViewModel.loadMessageViewState.refreshing,
133+
onRefresh = {
134+
chatViewModel.loadMoreMessage()
135+
}
137136
)
138137
) {
139138
MessagePanel(
140139
pageViewState = chatViewModel.chatPageViewState,
141140
chatPageAction = chatPageAction
142141
)
143-
PullRefreshIndicator(
142+
PullToRefreshDefaults.Indicator(
144143
modifier = Modifier
145144
.align(alignment = Alignment.TopCenter),
146-
refreshing = chatViewModel.loadMessageViewState.refreshing,
145+
isRefreshing = chatViewModel.loadMessageViewState.refreshing,
147146
state = pullRefreshState,
148-
backgroundColor = ComposeChatTheme.colorScheme.c_FFFFFFFF_FF101010.color,
149-
contentColor = ComposeChatTheme.colorScheme.c_FF42A5F5_FF26A69A.color
147+
color = ComposeChatTheme.colorScheme.c_FFFFFFFF_FF101010.color,
148+
containerColor = ComposeChatTheme.colorScheme.c_FF42A5F5_FF26A69A.color
150149
)
151150
}
152151
}

app/src/main/java/github/leavesczy/compose_chat/ui/preview/PreviewImageActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import github.leavesczy.compose_chat.provider.ToastProvider
3838
import github.leavesczy.compose_chat.ui.base.BaseActivity
3939
import github.leavesczy.compose_chat.ui.theme.ComposeChatTheme
4040
import github.leavesczy.compose_chat.ui.theme.WindowInsetsEmpty
41-
import github.leavesczy.compose_chat.ui.widgets.ZoomableComponentImage
41+
import github.leavesczy.compose_chat.ui.widgets.ComponentImage
4242
import github.leavesczy.compose_chat.utils.AlbumUtils
4343
import kotlinx.coroutines.launch
4444
import kotlin.math.absoluteValue
@@ -231,7 +231,7 @@ private fun PreviewPage(
231231
},
232232
contentAlignment = Alignment.Center
233233
) {
234-
ZoomableComponentImage(
234+
ComponentImage(
235235
modifier = Modifier
236236
.fillMaxSize(),
237237
model = imageUrl,

app/src/main/java/github/leavesczy/compose_chat/ui/widgets/Images.kt

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package github.leavesczy.compose_chat.ui.widgets
22

33
import androidx.compose.animation.core.Animatable
4-
import androidx.compose.animation.core.FastOutSlowInEasing
4+
import androidx.compose.animation.core.LinearEasing
55
import androidx.compose.animation.core.RepeatMode
66
import androidx.compose.animation.core.Spring
77
import androidx.compose.animation.core.SpringSpec
@@ -50,6 +50,7 @@ import github.leavesczy.compose_chat.ui.theme.ComposeChatTheme
5050
import kotlinx.coroutines.delay
5151
import kotlinx.coroutines.launch
5252
import kotlin.math.roundToInt
53+
import kotlin.math.sin
5354
import kotlin.random.Random
5455

5556
/**
@@ -93,42 +94,20 @@ fun ComponentImage(
9394
)
9495
}
9596

96-
@Composable
97-
fun ZoomableComponentImage(
98-
modifier: Modifier = Modifier,
99-
model: Any?,
100-
alignment: Alignment = Alignment.Center,
101-
contentScale: ContentScale = ContentScale.FillWidth,
102-
alpha: Float = DefaultAlpha,
103-
colorFilter: ColorFilter? = null,
104-
contentDescription: String? = null
105-
) {
106-
ComponentImage(
107-
modifier = modifier,
108-
model = model,
109-
alignment = alignment,
110-
contentScale = contentScale,
111-
alpha = alpha,
112-
colorFilter = colorFilter,
113-
contentDescription = contentDescription
114-
)
115-
}
116-
11797
@Composable
11898
fun BezierImage(modifier: Modifier, model: Any) {
11999
val animateFloat by rememberInfiniteTransition(label = "")
120100
.animateFloat(
121101
initialValue = 0f,
122102
targetValue = 1f,
123103
animationSpec = infiniteRepeatable(
124-
animation = tween(durationMillis = 600, easing = FastOutSlowInEasing),
125-
repeatMode = RepeatMode.Reverse,
104+
animation = tween(durationMillis = 1000, easing = LinearEasing),
105+
repeatMode = RepeatMode.Reverse
126106
),
127107
label = ""
128108
)
129109
ComponentImage(
130110
modifier = Modifier
131-
.scale(scale = 1.0f + animateFloat * 0.1f)
132111
.clip(shape = BezierShape(animateValue = animateFloat))
133112
.then(other = modifier),
134113
model = model
@@ -137,19 +116,26 @@ fun BezierImage(modifier: Modifier, model: Any) {
137116

138117
private class BezierShape(private val animateValue: Float) : Shape {
139118

140-
private val path = Path()
141-
142119
override fun createOutline(
143120
size: Size, layoutDirection: LayoutDirection, density: Density
144121
): Outline {
122+
val waveHeight = 20
123+
val waveFrequency = 0.2
124+
val path = Path()
145125
path.reset()
146-
val width = size.width
147-
val height = size.height
148-
val progress = height / 7 * 5 + height / 7 * 2 * animateValue
149-
path.lineTo(0f, progress / 7 * 5)
150-
path.quadraticTo(width / 2 + width / 4 * animateValue, height, width, progress)
151-
path.lineTo(width, 0f)
126+
path.moveTo(size.width, size.height)
127+
path.lineTo(size.width, 0f)
152128
path.lineTo(0f, 0f)
129+
path.lineTo(0f, size.height)
130+
var i = 0f
131+
while (i < size.width) {
132+
val y =
133+
size.height - (waveHeight * sin((i / size.width * 2 * Math.PI * waveFrequency) + (animateValue * 2 * Math.PI)))
134+
path.lineTo(i, y.toFloat())
135+
i++
136+
}
137+
path.lineTo(size.width, size.height)
138+
path.close()
153139
return Outline.Generic(path = path)
154140
}
155141

app/src/main/java/github/leavesczy/compose_chat/ui/widgets/MatisseImageEngine.kt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package github.leavesczy.compose_chat.ui.widgets
22

33
import androidx.compose.foundation.layout.fillMaxSize
4-
import androidx.compose.foundation.layout.fillMaxWidth
54
import androidx.compose.runtime.Composable
65
import androidx.compose.ui.Modifier
76
import androidx.compose.ui.layout.ContentScale
@@ -29,22 +28,13 @@ class MatisseImageEngine : ImageEngine {
2928

3029
@Composable
3130
override fun Image(mediaResource: MediaResource) {
32-
if (mediaResource.isVideo) {
33-
ComponentImage(
34-
modifier = Modifier
35-
.fillMaxWidth(),
36-
model = mediaResource.uri,
37-
contentScale = ContentScale.Fit,
38-
contentDescription = mediaResource.name
39-
)
40-
} else {
41-
ZoomableComponentImage(
42-
modifier = Modifier
43-
.fillMaxSize(),
44-
model = mediaResource.uri,
45-
contentDescription = mediaResource.name
46-
)
47-
}
31+
ComponentImage(
32+
modifier = Modifier
33+
.fillMaxSize(),
34+
model = mediaResource.uri,
35+
contentScale = ContentScale.FillWidth,
36+
contentDescription = mediaResource.name
37+
)
4838
}
4939

5040
}

build-logic/convention/src/main/kotlin/github/leavesczy/compose_chat/Compose.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ internal fun Project.configureCompose() {
3131
add("implementation", libs.findLibrary("androidx-compose-ui-tooling-preview").get())
3232
add("androidTestImplementation", libs.findLibrary("androidx-compose-ui-test").get())
3333
add("debugImplementation", libs.findLibrary("androidx-compose-ui-test-manifest").get())
34-
add("implementation", libs.findLibrary("androidx-compose-material").get())
3534
add("implementation", libs.findLibrary("androidx-compose-material-icons").get())
3635
add("implementation", libs.findLibrary("androidx-compose-material3").get())
3736
}

build-logic/convention/src/main/kotlin/github/leavesczy/compose_chat/Project.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal fun Project.configureAndroidProject() {
2121
extensions.findByType<ApplicationExtension>() ?: extensions.findByType<LibraryExtension>()!!
2222
commonExtension.apply {
2323
compileSdk = 36
24-
buildToolsVersion = "36.0.0"
24+
buildToolsVersion = "36.1.0"
2525
defaultConfig {
2626
minSdk = 23
2727
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

gradle/libs.versions.toml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
[versions]
2-
android-plugin = "8.13.0"
3-
kotlin-plugin = "2.2.20"
2+
android-plugin = "8.13.2"
3+
kotlin-plugin = "2.2.21"
44
track-plugin = "1.1.4"
55

66
androidx-junit = "1.3.0"
77
androidx-espresso = "3.7.0"
88
androidx-appcompat = "1.7.1"
9-
androidx-activity = "1.11.0"
10-
androidx-lifecycle-viewmodel = "2.9.4"
11-
androidx-exifinterface = "1.4.1"
12-
androidx-compose-bom = "2025.09.00"
9+
androidx-activity = "1.12.1"
10+
androidx-lifecycle = "2.10.0"
11+
androidx-exifinterface = "1.4.2"
12+
androidx-compose-bom = "2025.12.00"
1313

1414
kotlinx-coroutines = "1.10.2"
1515
kotlinx-collections-immutable = "0.4.0"
1616

1717
junit = "4.13.2"
1818
coil = "3.3.0"
19-
squareup-okHttp = "5.1.0"
20-
leavesczy-matisse = "2.2.2"
21-
tencent-imsdk = "8.7.7201"
19+
tencent-imsdk = "8.8.7359"
20+
squareup-okHttp = "5.3.2"
21+
leavesczy-matisse = "2.2.3"
2222

2323
[plugins]
2424
android-application = { id = "com.android.application", version.ref = "android-plugin" }
@@ -43,8 +43,8 @@ androidx-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-j
4343
androidx-espresso = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-espresso" }
4444
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
4545
androidx-exifinterface = { module = "androidx.exifinterface:exifinterface", version.ref = "androidx-exifinterface" }
46-
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle-viewmodel" }
4746
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
47+
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
4848

4949
androidx-compose-bom = { module = "androidx.compose:compose-bom-beta", version.ref = "androidx-compose-bom" }
5050
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
@@ -53,18 +53,17 @@ androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
5353
androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
5454
androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test-junit4" }
5555
androidx-compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" }
56-
androidx-compose-material = { module = "androidx.compose.material:material" }
5756
androidx-compose-material-icons = { module = "androidx.compose.material:material-icons-extended" }
5857
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
5958

6059
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
6160
kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlinx-collections-immutable" }
6261

63-
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
6462
coil-gif = { module = "io.coil-kt.coil3:coil-gif", version.ref = "coil" }
63+
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
6564
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" }
6665

6766
junit = { module = "junit:junit", version.ref = "junit" }
67+
tencent-imsdk = { module = "com.tencent.imsdk:imsdk-plus", version.ref = "tencent-imsdk" }
6868
squareup-okHttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "squareup-okHttp" }
69-
leavesczy-matisse = { module = "io.github.leavesczy:matisse", version.ref = "leavesczy-matisse" }
70-
tencent-imsdk = { module = "com.tencent.imsdk:imsdk-plus", version.ref = "tencent-imsdk" }
69+
leavesczy-matisse = { module = "io.github.leavesczy:matisse", version.ref = "leavesczy-matisse" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

workflows-trigger.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
trigger=25
1+
trigger=26

0 commit comments

Comments
 (0)