Skip to content

Commit b4a823c

Browse files
committed
代码优化
1 parent 47a4cba commit b4a823c

23 files changed

Lines changed: 335 additions & 459 deletions

File tree

.github/workflows/client.yml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@ on:
66
tags:
77
- 'v*'
88
paths:
9-
- 'client/**'
9+
- 'app/**'
10+
- 'gradle/**'
11+
- 'build.gradle.kts'
12+
- 'settings.gradle.kts'
13+
- 'gradle.properties'
1014
- '.github/workflows/client.yml'
1115
pull_request:
1216
branches: [ main ]
1317
paths:
14-
- 'client/**'
18+
- 'app/**'
19+
- 'gradle/**'
20+
- 'build.gradle.kts'
21+
- 'settings.gradle.kts'
22+
- 'gradle.properties'
1523
- '.github/workflows/client.yml'
1624

1725
jobs:
1826
check:
19-
runs-on: self-hosted
20-
defaults:
21-
run:
22-
working-directory: client
27+
runs-on: ubuntu-latest
2328

2429
steps:
2530
- uses: actions/checkout@v4
@@ -34,6 +39,25 @@ jobs:
3439
- name: Grant execute permission for gradlew
3540
run: chmod +x gradlew
3641

42+
- name: Prepare local config
43+
env:
44+
LOCALHOST: ${{ vars.LOCALHOST }}
45+
HJSERVER: ${{ vars.HJSERVER }}
46+
run: |
47+
keytool -genkeypair -alias androiddebugkey -keyalg RSA -keysize 2048 -validity 10000 \
48+
-storepass android -keypass android -keystore debug.keystore \
49+
-dname "CN=Android Debug,O=Android,C=US"
50+
{
51+
echo "KEYSTORE_PATH=debug.keystore"
52+
echo "KEYSTORE_PASSWORD=android"
53+
echo "KEY_ALIAS=androiddebugkey"
54+
echo "KEY_PASSWORD=android"
55+
} > local.properties
56+
{
57+
echo "LOCALHOST=${LOCALHOST:-http://127.0.0.1}"
58+
echo "HJSERVER=${HJSERVER:-https://example.invalid}"
59+
} >> gradle.properties
60+
3761
- name: Lint
3862
run: ./gradlew lintDebug --no-daemon
3963

@@ -44,9 +68,6 @@ jobs:
4468
runs-on: ubuntu-latest
4569
if: startsWith(github.ref, 'refs/tags/v')
4670
needs: [check]
47-
defaults:
48-
run:
49-
working-directory: client
5071

5172
steps:
5273
- uses: actions/checkout@v4
@@ -61,19 +82,35 @@ jobs:
6182
- name: Grant execute permission for gradlew
6283
run: chmod +x gradlew
6384

64-
- name: Build Release APK
65-
run: ./gradlew assembleRelease --no-daemon
85+
- name: Prepare release config
6686
env:
6787
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
6888
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
6989
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
7090
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
91+
LOCALHOST: ${{ vars.LOCALHOST }}
92+
HJSERVER: ${{ vars.HJSERVER }}
93+
run: |
94+
echo "$KEYSTORE_BASE64" | base64 --decode > release.keystore
95+
{
96+
echo "KEYSTORE_PATH=release.keystore"
97+
echo "KEYSTORE_PASSWORD=$KEYSTORE_PASSWORD"
98+
echo "KEY_ALIAS=$KEY_ALIAS"
99+
echo "KEY_PASSWORD=$KEY_PASSWORD"
100+
} > local.properties
101+
{
102+
echo "LOCALHOST=${LOCALHOST:-http://127.0.0.1}"
103+
echo "HJSERVER=${HJSERVER:-https://example.invalid}"
104+
} >> gradle.properties
105+
106+
- name: Build Release APK
107+
run: ./gradlew assembleRelease --no-daemon
71108

72109
- name: Upload APK
73110
uses: actions/upload-artifact@v4
74111
with:
75112
name: release-apk
76-
path: client/app/build/outputs/apk/release/*.apk
113+
path: app/build/outputs/apk/release/*.apk
77114
retention-days: 30
78115

79116
- name: Get version from tag
@@ -83,7 +120,7 @@ jobs:
83120
- name: Create GitHub Release
84121
uses: softprops/action-gh-release@v1
85122
with:
86-
files: client/app/build/outputs/apk/release/*.apk
123+
files: app/build/outputs/apk/release/*.apk
87124
tag_name: ${{ steps.version.outputs.VERSION }}
88125
generate_release_notes: true
89126
env:

.github/workflows/server.yml

Lines changed: 0 additions & 160 deletions
This file was deleted.

app/src/androidTest/java/com/hao/heji/ExampleInstrumentedTest.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/src/main/java/com/hao/heji/App.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class App : Application() {
4040
}
4141

4242
viewModel = get()
43+
Config.onChanged = viewModel::notifyConfigChanged
4344
}
4445

4546
companion object {

app/src/main/java/com/hao/heji/config/Config.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.hao.heji.config
22

3-
import com.hao.heji.App
43
import com.hao.heji.config.store.DataStoreManager
54
import com.hao.heji.data.db.Book
65
import com.hao.heji.ui.user.JWTParse
@@ -13,6 +12,7 @@ import com.hao.heji.ui.user.JWTParse
1312
internal val LocalUser = JWTParse.User("LocalUser", "user0", "")
1413

1514
object Config {
15+
internal var onChanged: ((Config) -> Unit)? = null
1616

1717
val serverUrl: String get() = DataStoreManager.getServerUrl()
1818
val book: Book get() = DataStoreManager.getBook()
@@ -33,12 +33,12 @@ object Config {
3333

3434
fun setBook(book: Book) {
3535
DataStoreManager.saveBook(book)
36-
App.viewModel.notifyConfigChanged(this)
36+
notifyChanged()
3737
}
3838

3939
fun setUser(user: JWTParse.User) {
4040
DataStoreManager.saveToken(user.token)
41-
App.viewModel.notifyConfigChanged(this)
41+
notifyChanged()
4242
}
4343

4444
fun setServerUrl(url: String) {
@@ -47,7 +47,7 @@ object Config {
4747

4848
fun enableOfflineMode(enable: Boolean) {
4949
DataStoreManager.saveUseMode(enable)
50-
App.viewModel.notifyConfigChanged(this)
50+
notifyChanged()
5151
}
5252

5353
fun setMqttBrokerUrl(url: String) {
@@ -62,6 +62,10 @@ object Config {
6262
removeMqttBrokerUrl()
6363
removeLastSyncTime()
6464
}
65-
App.viewModel.notifyConfigChanged(this)
65+
notifyChanged()
6666
}
67-
}
67+
68+
private fun notifyChanged() {
69+
onChanged?.invoke(this)
70+
}
71+
}

0 commit comments

Comments
 (0)