Skip to content

Commit 1ff546b

Browse files
committed
optimize code
1 parent edd4c56 commit 1ff546b

File tree

103 files changed

+1437
-1272
lines changed

Some content is hidden

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

103 files changed

+1437
-1272
lines changed
Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,58 @@
1-
name: create release
1+
name: Build & Release
22

33
on:
44
push:
55
branches: [ master ]
66
paths:
77
- "**/workflows-trigger.properties"
88

9+
workflow_dispatch:
10+
inputs:
11+
release_notes:
12+
description: "Release Notes"
13+
required: false
14+
default: "Auto-generated release from GitHub Actions."
15+
16+
env:
17+
DEFAULT_RELEASE_NOTES: "Auto-generated release from GitHub Actions."
18+
19+
permissions:
20+
contents: write
21+
922
jobs:
1023
build:
1124
runs-on: ubuntu-latest
1225

1326
steps:
14-
- name: set up jdk
27+
- name: checkout code
28+
uses: actions/checkout@v6
29+
30+
- name: setup jdk
1531
uses: actions/setup-java@v5
1632
with:
17-
distribution: "zulu"
1833
java-version: "21"
19-
architecture: x64
20-
21-
- name: checkout
22-
uses: actions/checkout@v5
34+
distribution: "zulu"
2335

2436
- name: grant execute permission for gradlew
2537
run: chmod +x gradlew
2638

2739
- name: assembleRelease
28-
run: ./gradlew assembleRelease
40+
run: ./gradlew clean assembleRelease
2941

3042
- name: get current time
31-
id: currentTime
32-
uses: josStorer/get-current-time@v2
33-
with:
34-
format: YYYY.MM.DD
35-
utcOffset: "+08:00"
43+
id: time_formats
44+
run: |
45+
export TZ='Asia/Shanghai'
46+
echo "date_tag=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT
3647
37-
- name: draft a new release
48+
- name: create github release
3849
uses: ncipollo/release-action@v1
3950
with:
40-
artifacts: "app/build/outputs/apk/release/*.apk"
41-
body: "create by workflows"
4251
allowUpdates: true
52+
generateReleaseNotes: false
4353
artifactErrorsFailBuild: true
44-
generateReleaseNotes: true
45-
token: ${{secrets.ACTION_TOKEN}}
46-
name: ${{steps.currentTime.outputs.formattedTime}}
47-
tag: ${{steps.currentTime.outputs.formattedTime}}
54+
artifacts: "app/build/outputs/apk/release/*.apk"
55+
body: ${{ github.event.inputs.release_notes || env.DEFAULT_RELEASE_NOTES }}
56+
tag: ${{ steps.time_formats.outputs.date_tag }}
57+
name: ${{ steps.time_formats.outputs.date_tag }}
58+
token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ compose_chat 也使用到了我另外两个开源库
1515
图片视频选择框架:[Matisse](https://github.com/leavesCZY/Matisse)
1616
- 一个 Android 字节码插桩库:[Track](https://github.com/leavesCZY/Track)
1717

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

2020
- Jetpack
2121
- Compose

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ dependencies {
1919
implementation(libs.kotlinx.coroutines)
2020
implementation(libs.kotlinx.collections.immutable)
2121
implementation(libs.leavesczy.matisse)
22-
implementation(libs.coil.compose)
2322
implementation(libs.coil.gif)
23+
implementation(libs.coil.compose)
2424
implementation(libs.coil.network.okhttp)
2525
implementation(libs.squareup.okHttp)
2626
}

app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
88
<uses-permission
99
android:name="android.permission.READ_MEDIA_IMAGES"
10-
tools:ignore="SelectedPhotoAccess" />
10+
tools:ignore="PhotoAndVideoPolicy,SelectedPhotoAccess" />
1111
<uses-permission
1212
android:name="android.permission.READ_EXTERNAL_STORAGE"
1313
android:maxSdkVersion="32" />
@@ -16,16 +16,15 @@
1616
android:maxSdkVersion="28" />
1717

1818
<application
19-
android:name=".MainApplication"
19+
android:name=".ChatApplication"
2020
android:allowBackup="false"
2121
android:fullBackupContent="false"
22-
android:icon="@mipmap/icon_logo"
22+
android:icon="@mipmap/ic_launcher"
2323
android:label="@string/app_name"
24-
android:roundIcon="@mipmap/icon_logo"
24+
android:roundIcon="@mipmap/ic_launcher_round"
2525
android:supportsRtl="false"
2626
android:theme="@style/Theme.Compose.Chat"
27-
tools:ignore="DataExtractionRules"
28-
tools:replace="android:supportsRtl">
27+
tools:ignore="DataExtractionRules">
2928
<activity
3029
android:name=".ui.login.LoginActivity"
3130
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
@@ -48,28 +47,30 @@
4847
android:windowSoftInputMode="adjustResize"
4948
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
5049
<activity
51-
android:name=".ui.chat.GroupProfileActivity"
50+
android:name=".ui.chat.group.GroupProfileActivity"
5251
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
5352
android:exported="false"
53+
android:launchMode="singleTop"
5454
android:screenOrientation="portrait"
55-
android:windowSoftInputMode="adjustResize"
5655
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
5756
<activity
5857
android:name=".ui.friend.FriendProfileActivity"
5958
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
6059
android:exported="false"
60+
android:launchMode="singleTop"
6161
android:screenOrientation="portrait"
6262
android:windowSoftInputMode="adjustResize"
6363
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
6464
<activity
6565
android:name=".ui.profile.ProfileUpdateActivity"
6666
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
6767
android:exported="false"
68+
android:launchMode="singleTop"
6869
android:screenOrientation="portrait"
6970
android:windowSoftInputMode="adjustResize"
7071
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
7172
<activity
72-
android:name=".ui.chat.ChatActivity"
73+
android:name=".ui.chat.main.ChatActivity"
7374
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
7475
android:exported="false"
7576
android:screenOrientation="portrait"
@@ -79,8 +80,8 @@
7980
android:name=".ui.preview.PreviewImageActivity"
8081
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation|uiMode"
8182
android:exported="false"
83+
android:launchMode="singleTop"
8284
android:screenOrientation="portrait"
83-
android:windowSoftInputMode="adjustResize"
8485
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
8586
</application>
8687

app/src/main/java/github/leavesczy/compose_chat/MainApplication.kt renamed to app/src/main/java/github/leavesczy/compose_chat/ChatApplication.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import github.leavesczy.compose_chat.provider.AccountProvider
55
import github.leavesczy.compose_chat.provider.AppThemeProvider
66
import github.leavesczy.compose_chat.provider.ContextProvider
77
import github.leavesczy.compose_chat.ui.logic.ComposeChat
8-
import github.leavesczy.compose_chat.utils.CoilUtils
8+
import github.leavesczy.compose_chat.utils.ImageUtils
99

1010
/**
1111
* @Author: leavesCZY
1212
* @Desc:
1313
* @Github:https://github.com/leavesCZY
1414
*/
15-
class MainApplication : Application() {
15+
class ChatApplication : Application() {
1616

1717
override fun onCreate() {
1818
super.onCreate()
1919
ContextProvider.init(application = this)
2020
AppThemeProvider.init(application = this)
2121
AccountProvider.init(application = this)
2222
ComposeChat.accountProvider.init(application = this)
23-
CoilUtils.init()
23+
ImageUtils.init()
2424
}
2525

2626
}

app/src/main/java/github/leavesczy/compose_chat/provider/AccountProvider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ object AccountProvider {
2020

2121
private lateinit var preferences: SharedPreferences
2222

23-
fun init(application: Application) {
24-
preferences = application.getSharedPreferences(KEY_GROUP, Context.MODE_PRIVATE)
25-
}
26-
2723
val lastLoginUserId: String
2824
get() = preferences.getString(KEY_LAST_LOGIN_USER_ID, "") ?: ""
2925

3026
val canAutoLogin: Boolean
3127
get() = preferences.getBoolean(KEY_AUTO_LOGIN, true)
3228

29+
fun init(application: Application) {
30+
preferences = application.getSharedPreferences(KEY_GROUP, Context.MODE_PRIVATE)
31+
}
32+
3333
fun onUserLogin(userId: String) {
3434
preferences.edit().apply {
3535
putString(KEY_LAST_LOGIN_USER_ID, userId)

app/src/main/java/github/leavesczy/compose_chat/provider/ToastProvider.kt

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

33
import android.content.Context
4+
import android.view.Gravity
45
import android.widget.Toast
56

67
/**
@@ -15,6 +16,7 @@ object ToastProvider {
1516
return
1617
}
1718
val toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT)
19+
toast.setGravity(Gravity.CENTER, 0, 0)
1820
toast.show()
1921
}
2022

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.padding
66
import androidx.compose.material3.ModalNavigationDrawer
77
import androidx.compose.material3.Scaffold
88
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.Alignment
910
import androidx.compose.ui.Modifier
1011
import github.leavesczy.compose_chat.ui.conversation.ConversationPage
1112
import github.leavesczy.compose_chat.ui.conversation.logic.ConversationViewModel
@@ -43,8 +44,8 @@ fun MainPage(
4344
Scaffold(
4445
modifier = Modifier
4546
.fillMaxSize(),
46-
containerColor = ComposeChatTheme.colorScheme.c_FFFFFFFF_FF101010.color,
4747
contentWindowInsets = WindowInsetsEmpty,
48+
containerColor = ComposeChatTheme.colorScheme.c_FFFFFFFF_FF101010.color,
4849
topBar = {
4950
if (mainViewModel.bottomBarViewState.selectedTab != MainPageTab.Person) {
5051
MainPageTopBar(
@@ -61,8 +62,9 @@ fun MainPage(
6162
) { innerPadding ->
6263
Box(
6364
modifier = Modifier
64-
.fillMaxSize()
6565
.padding(paddingValues = innerPadding)
66+
.fillMaxSize(),
67+
contentAlignment = Alignment.TopCenter
6668
) {
6769
when (mainViewModel.bottomBarViewState.selectedTab) {
6870
MainPageTab.Conversation -> {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ import androidx.compose.material.icons.filled.Cabin
1919
import androidx.compose.material.icons.filled.ColorLens
2020
import androidx.compose.material.icons.filled.Sailing
2121
import androidx.compose.material3.Icon
22-
import androidx.compose.material3.Surface
2322
import androidx.compose.material3.Text
2423
import androidx.compose.runtime.Composable
2524
import androidx.compose.runtime.remember
2625
import androidx.compose.runtime.rememberCoroutineScope
2726
import androidx.compose.ui.Alignment
2827
import androidx.compose.ui.Modifier
29-
import androidx.compose.ui.graphics.Color
3028
import androidx.compose.ui.graphics.vector.ImageVector
3129
import androidx.compose.ui.text.style.TextAlign
3230
import androidx.compose.ui.unit.dp
@@ -54,13 +52,11 @@ fun MainPageDrawer(viewState: MainPageDrawerViewState) {
5452
viewState.drawerState.close()
5553
}
5654
}
57-
Surface(
55+
Box(
5856
modifier = Modifier
5957
.fillMaxWidth(fraction = 0.80f)
6058
.background(color = ComposeChatTheme.colorScheme.c_FFFFFFFF_FF161616.color)
61-
.navigationBarsPadding(),
62-
color = Color.Transparent,
63-
contentColor = Color.Transparent
59+
.navigationBarsPadding()
6460
) {
6561
Column(
6662
modifier = Modifier

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import androidx.compose.material.icons.filled.Menu
88
import androidx.compose.material.icons.filled.MoreVert
99
import androidx.compose.material3.CenterAlignedTopAppBar
1010
import androidx.compose.material3.DropdownMenu
11-
import androidx.compose.material3.DropdownMenuItem
1211
import androidx.compose.material3.Icon
1312
import androidx.compose.material3.IconButton
14-
import androidx.compose.material3.Text
1513
import androidx.compose.material3.TopAppBarDefaults
1614
import androidx.compose.runtime.Composable
1715
import androidx.compose.runtime.getValue
@@ -22,9 +20,9 @@ import androidx.compose.runtime.setValue
2220
import androidx.compose.ui.Alignment
2321
import androidx.compose.ui.Modifier
2422
import androidx.compose.ui.unit.dp
25-
import androidx.compose.ui.unit.sp
2623
import github.leavesczy.compose_chat.ui.logic.MainPageTopBarViewState
2724
import github.leavesczy.compose_chat.ui.theme.ComposeChatTheme
25+
import github.leavesczy.compose_chat.ui.widgets.ComposeDropdownMenuItem
2826
import kotlinx.coroutines.launch
2927

3028
/**
@@ -94,31 +92,17 @@ fun MainPageTopBar(
9492
menuExpanded = false
9593
}
9694
) {
97-
DropdownMenuItem(
98-
text = {
99-
Text(
100-
modifier = Modifier,
101-
text = "添加好友",
102-
fontSize = 18.sp,
103-
lineHeight = 19.sp,
104-
color = ComposeChatTheme.colorScheme.c_FF001018_DEFFFFFF.color
105-
)
106-
},
95+
ComposeDropdownMenuItem(
96+
modifier = Modifier,
97+
text = "添加好友",
10798
onClick = {
10899
menuExpanded = false
109100
showFriendshipDialog()
110101
}
111102
)
112-
DropdownMenuItem(
113-
text = {
114-
Text(
115-
modifier = Modifier,
116-
text = "加入群聊",
117-
fontSize = 18.sp,
118-
lineHeight = 19.sp,
119-
color = ComposeChatTheme.colorScheme.c_FF001018_DEFFFFFF.color
120-
)
121-
},
103+
ComposeDropdownMenuItem(
104+
modifier = Modifier,
105+
text = "加入群聊",
122106
onClick = {
123107
menuExpanded = false
124108
showFriendshipDialog()

0 commit comments

Comments
 (0)