Skip to content

Commit 8d6a740

Browse files
committed
optimize code
1 parent 97c98bb commit 8d6a740

File tree

129 files changed

+2776
-2431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+2776
-2431
lines changed

.github/workflows/android.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
body: "create by workflows"
4343
allowUpdates: true
4444
artifactErrorsFailBuild: true
45-
generateReleaseNotes: true
45+
generateReleaseNotes: false
4646
token: ${{ secrets.ACTION_TOKEN }}
4747
tag: ${{ steps.currentTime.outputs.time }}
4848
name: v${{ steps.currentTime.outputs.time }}

.gitignore

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
/local.properties
21
/.idea/
32
/app/release/
43
/build
5-
/captures
4+
/local.properties
65
*.iml
7-
.gradle
8-
.DS_Store
9-
.externalNativeBuild
10-
.cxx
11-
.idea
126
*.apk
13-
*.json
14-
local.properties
15-
build
7+
.gradle
8+
.DS_Store

README.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,35 @@
22

33
Jetpack Compose 最佳实践,用 Jetpack Compose 写一个 IM APP
44

5-
关联的文章
5+
相关联的文章
66

77
- [学不动也要学,用 Jetpack Compose 写一个 IM APP(一)](https://juejin.cn/post/6991429231821684773)
88
- [学不动也要学,用 Jetpack Compose 写一个 IM APP(二)](https://juejin.cn/post/7028397244894330917)
99

1010
Apk 下载:[releases](https://github.com/leavesCZY/compose_chat/releases)
1111

12-
由于腾讯云 IM SDK 免费版最多只能注册一百个账号,如果已经发现注册不了的话,可以使用以下几个账号进行登录
12+
腾讯云 IM SDK 的免费版本最多只能注册一百个账号,目前数量已经超限了,开发者可以使用以下几个账号进行登录
1313

14-
- Android
15-
- Google
16-
- Apple
1714
- Jetpack
1815
- Compose
1916
- Chat
20-
- Flutter
2117
- Java
2218
- Kotlin
2319
- Dart
20+
- Android
21+
- Apple
22+
- Google
23+
- Flutter
2424
- Admin
2525
- Hello
26+
- Good
27+
- Nice
2628
- Test
2729

28-
![](https://user-images.githubusercontent.com/30774063/221415412-57eb8da5-e85c-4409-9a0f-37df11f71a70.gif)
30+
![](https://github.com/leavesCZY/compose_chat/assets/30774063/fbb36fb3-52b8-4719-b783-ec7f0c5b2d92)
2931

30-
Compose Chat 也使用到了我的另外两个开源库
32+
compose_chat 也使用到了我另外的两个开源库
3133

32-
- 一个用 Jetpack Compose 实现的 Android 图片/视频 选择框架:[Matisse](https://github.com/leavesCZY/Matisse)
33-
- 一个适用于 Android 的字节码插桩库:[Trace](https://github.com/leavesCZY/Trace)
34+
- 一个用 Jetpack Compose 实现的 Android 图片/视频
35+
选择框架:[Matisse](https://github.com/leavesCZY/Matisse)
36+
- 一个 Android 字节码插桩库:[Trace](https://github.com/leavesCZY/Trace)

app/build.gradle.kts

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
plugins {
2+
alias(libs.plugins.chat.android.application)
3+
alias(libs.plugins.chat.android.compose)
4+
alias(libs.plugins.chat.kotlin.parcelize)
5+
alias(libs.plugins.chat.leavesczy.trace)
6+
}
7+
18
android {
29
namespace = "github.leavesczy.compose_chat"
310
}
411

512
dependencies {
613
implementation(project(":base"))
714
implementation(project(":proxy"))
8-
implementationTest()
9-
implementationCompose()
10-
implementationCoil()
11-
implementation(Dependencies.Accompanist.uiController)
12-
implementation(Dependencies.Components.appcompat)
13-
implementation(Dependencies.Components.exifinterface)
14-
implementation(Dependencies.Components.coroutines)
15-
implementation(Dependencies.Components.matisse)
16-
}
17-
18-
composeClickTrace {
19-
onClickClass = "github.leavesczy.compose_chat.extend.ComposeOnClick"
20-
onClickWhiteList = "notCheck"
15+
implementation(libs.androidx.appcompat)
16+
implementation(libs.androidx.activity.compose)
17+
implementation(libs.androidx.lifecycle.viewmodel.compose)
18+
implementation(libs.androidx.exifinterface)
19+
implementation(libs.kotlinx.coroutines)
20+
implementation(libs.leavesczy.matisse)
21+
implementation(libs.coil.compose)
22+
implementation(libs.coil.gif)
23+
implementation(libs.coil.network.okhttp)
2124
}

app/proguard-rules.pro

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# hide the original source file name.
2121
#-renamesourcefileattribute SourceFile
2222

23+
-optimizationpasses 10
2324
-packageobfuscationdictionary dictionary.txt
2425
-classobfuscationdictionary dictionary.txt
2526
-obfuscationdictionary dictionary.txt

app/src/androidTest/java/github/leavesczy/compose_chat/ExampleInstrumentedTest.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class ExampleInstrumentedTest {
1717
fun useAppContext() {
1818
// Context of the app under test.
1919
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
20-
assertEquals(
21-
"github.leavesczy.compose_chat", appContext.packageName
22-
)
20+
assertEquals("github.leavesczy.compose_chat", appContext.packageName)
2321
}
2422
}

app/src/main/AndroidManifest.xml

+13-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<uses-permission android:name="android.permission.INTERNET" />
66
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
77
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
8-
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
8+
<uses-permission
9+
android:name="android.permission.READ_MEDIA_IMAGES"
10+
tools:ignore="SelectedPhotoAccess" />
911
<uses-permission
1012
android:name="android.permission.READ_EXTERNAL_STORAGE"
1113
android:maxSdkVersion="32" />
@@ -15,19 +17,22 @@
1517

1618
<application
1719
android:name=".MainApplication"
20+
android:allowBackup="false"
21+
android:fullBackupContent="false"
1822
android:icon="@drawable/icon_logo"
1923
android:label="@string/app_name"
2024
android:roundIcon="@drawable/icon_logo_round"
2125
android:supportsRtl="false"
2226
android:theme="@style/Theme.ComposeChat"
27+
tools:ignore="DataExtractionRules"
2328
tools:replace="android:supportsRtl">
2429
<activity
2530
android:name=".ui.login.LoginActivity"
2631
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
2732
android:exported="true"
2833
android:screenOrientation="portrait"
2934
android:windowSoftInputMode="adjustResize"
30-
tools:ignore="LockedOrientationActivity">
35+
tools:ignore="DiscouragedApi,LockedOrientationActivity">
3136
<intent-filter>
3237
<action android:name="android.intent.action.MAIN" />
3338

@@ -41,42 +46,42 @@
4146
android:launchMode="singleTask"
4247
android:screenOrientation="portrait"
4348
android:windowSoftInputMode="adjustResize"
44-
tools:ignore="LockedOrientationActivity" />
49+
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
4550
<activity
4651
android:name=".ui.chat.GroupProfileActivity"
4752
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
4853
android:exported="false"
4954
android:screenOrientation="portrait"
5055
android:windowSoftInputMode="adjustResize"
51-
tools:ignore="LockedOrientationActivity" />
56+
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
5257
<activity
5358
android:name=".ui.friend.FriendProfileActivity"
5459
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
5560
android:exported="false"
5661
android:screenOrientation="portrait"
5762
android:windowSoftInputMode="adjustResize"
58-
tools:ignore="LockedOrientationActivity" />
63+
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
5964
<activity
6065
android:name=".ui.profile.ProfileUpdateActivity"
6166
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
6267
android:exported="false"
6368
android:screenOrientation="portrait"
6469
android:windowSoftInputMode="adjustResize"
65-
tools:ignore="LockedOrientationActivity" />
70+
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
6671
<activity
6772
android:name=".ui.chat.ChatActivity"
6873
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
6974
android:exported="false"
7075
android:screenOrientation="portrait"
7176
android:windowSoftInputMode="adjustResize"
72-
tools:ignore="LockedOrientationActivity" />
77+
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
7378
<activity
7479
android:name=".ui.preview.PreviewImageActivity"
7580
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
7681
android:exported="false"
7782
android:screenOrientation="portrait"
7883
android:windowSoftInputMode="adjustResize"
79-
tools:ignore="LockedOrientationActivity" />
84+
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
8085
</application>
8186

8287
</manifest>

app/src/main/java/github/leavesczy/compose_chat/MainApplication.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import android.app.Application
44
import github.leavesczy.compose_chat.provider.AccountProvider
55
import github.leavesczy.compose_chat.provider.AppThemeProvider
66
import github.leavesczy.compose_chat.provider.ContextProvider
7-
import github.leavesczy.compose_chat.provider.ImageLoaderProvider
87
import github.leavesczy.compose_chat.provider.ToastProvider
98
import github.leavesczy.compose_chat.ui.logic.ComposeChat
9+
import github.leavesczy.compose_chat.utils.CoilUtils
1010

1111
/**
1212
* @Author: leavesCZY
@@ -19,9 +19,9 @@ class MainApplication : Application() {
1919
super.onCreate()
2020
ContextProvider.init(application = this)
2121
ToastProvider.init(application = this)
22+
CoilUtils.init(application = this)
2223
AppThemeProvider.init(application = this)
2324
AccountProvider.init(application = this)
24-
ImageLoaderProvider.init(application = this)
2525
ComposeChat.accountProvider.init(application = this)
2626
}
2727

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package github.leavesczy.compose_chat
2+
3+
/**
4+
* @Author: leavesCZY
5+
* @Desc:
6+
* @Github:https://github.com/leavesCZY
7+
*/
8+
object WorkflowsTrigger {
9+
10+
val trigger = 1
11+
12+
}

app/src/main/java/github/leavesczy/compose_chat/extend/ComposeOnClick.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ComposeOnClick(private val onClick: () -> Unit) : Function0<Unit> {
1111

1212
companion object {
1313

14-
private const val MIN_DURATION = 300L
14+
private const val MIN_DURATION = 250L
1515

1616
private var lastClickTime = 0L
1717

app/src/main/java/github/leavesczy/compose_chat/extend/ModifierExtends.kt

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package github.leavesczy.compose_chat.extend
22

33
import androidx.compose.foundation.clickable
44
import androidx.compose.foundation.interaction.MutableInteractionSource
5+
import androidx.compose.runtime.Composable
56
import androidx.compose.runtime.remember
67
import androidx.compose.ui.Modifier
7-
import androidx.compose.ui.composed
88
import androidx.compose.ui.draw.drawWithContent
99
import androidx.compose.ui.graphics.Color
1010

@@ -18,10 +18,14 @@ fun Modifier.scrim(color: Color): Modifier = drawWithContent {
1818
drawRect(color = color)
1919
}
2020

21-
fun Modifier.clickableNoRipple(onClick: () -> Unit): Modifier = composed {
22-
clickable(
23-
onClick = onClick,
24-
interactionSource = remember { MutableInteractionSource() },
25-
indication = null
21+
@Composable
22+
fun Modifier.clickableNoRipple(onClick: () -> Unit): Modifier {
23+
return then(
24+
other = Modifier.clickable(
25+
onClickLabel = null,
26+
indication = null,
27+
interactionSource = remember { MutableInteractionSource() },
28+
onClick = onClick
29+
)
2630
)
2731
}

app/src/main/java/github/leavesczy/compose_chat/ui/MainActivity.kt

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import android.content.Intent
44
import android.os.Bundle
55
import androidx.activity.viewModels
66
import androidx.lifecycle.lifecycleScope
7-
import github.leavesczy.compose_chat.base.model.ServerState
7+
import github.leavesczy.compose_chat.base.models.ServerState
88
import github.leavesczy.compose_chat.provider.AccountProvider
99
import github.leavesczy.compose_chat.ui.base.BaseActivity
10+
import github.leavesczy.compose_chat.ui.conversation.logic.ConversationViewModel
11+
import github.leavesczy.compose_chat.ui.friendship.logic.FriendshipViewModel
1012
import github.leavesczy.compose_chat.ui.logic.MainViewModel
1113
import github.leavesczy.compose_chat.ui.login.LoginActivity
14+
import github.leavesczy.compose_chat.ui.person.logic.PersonProfileViewModel
1215
import kotlinx.coroutines.launch
1316

1417
/**
@@ -20,10 +23,21 @@ class MainActivity : BaseActivity() {
2023

2124
private val mainViewModel by viewModels<MainViewModel>()
2225

26+
private val conversationViewModel by viewModels<ConversationViewModel>()
27+
28+
private val friendshipViewModel by viewModels<FriendshipViewModel>()
29+
30+
private val personProfileViewModel by viewModels<PersonProfileViewModel>()
31+
2332
override fun onCreate(savedInstanceState: Bundle?) {
2433
super.onCreate(savedInstanceState)
2534
setContent {
26-
MainPage(mainViewModel = mainViewModel)
35+
MainPage(
36+
mainViewModel = mainViewModel,
37+
conversationViewModel = conversationViewModel,
38+
friendshipViewModel = friendshipViewModel,
39+
personProfileViewModel = personProfileViewModel
40+
)
2741
}
2842
initEvent()
2943
}

0 commit comments

Comments
 (0)