Skip to content

Commit 5f625d9

Browse files
committed
chore: show more build info in about preference
1 parent 384f48f commit 5f625d9

File tree

7 files changed

+58
-8
lines changed

7 files changed

+58
-8
lines changed

app/build.gradle

+36
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ android {
1212
versionCode 20220701
1313
versionName "3.2.7"
1414
setProperty("archivesBaseName", "trime-$versionName")
15+
resValue "string", "trime_url", getGitUrl()
16+
buildConfigField 'String', 'BUILD_INFO' , '"Build by '+getGitUser()+ ', in ' + getBuildTime() + ' UTC, branch ' + getGitBranch() + '"'
17+
buildConfigField 'String', 'BUILD_VERSION' , '"'+"$versionName" + '-'+ gitGitVersionCode() +'-g'+ getGitVersion()+ '-' + getBuildDate() + '"'
1518
}
1619

1720
signingConfigs {
@@ -102,3 +105,36 @@ dependencies {
102105
repositories {
103106
mavenCentral()
104107
}
108+
109+
def getBuildDate() {
110+
return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))
111+
}
112+
113+
def getBuildTime() {
114+
return new Date().format("yyyy-MM-dd HH:mm", TimeZone.getTimeZone("UTC"))
115+
}
116+
117+
def getGitBranch(){
118+
' git symbolic-ref --short -q HEAD'.execute().text.trim()
119+
}
120+
121+
def getGitVersion() {
122+
return 'git rev-parse --short HEAD'.execute().text.trim()
123+
}
124+
125+
def gitGitVersionCode() {
126+
try {
127+
return 'git rev-list HEAD --first-parent --count'.execute().text.trim().toInteger()
128+
}
129+
catch (ignored) {
130+
return 1
131+
}
132+
}
133+
134+
def getGitUser() {
135+
return 'git config user.name'.execute().text.trim()
136+
}
137+
138+
def getGitUrl() {
139+
return 'git remote get-url origin'.execute().text.trim().replaceFirst("\\.git\$","")
140+
}

app/src/main/java/com/osfans/trime/settings/AboutActivity.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.appcompat.widget.Toolbar
99
import androidx.fragment.app.Fragment
1010
import androidx.preference.Preference
1111
import androidx.preference.PreferenceFragmentCompat
12+
import com.osfans.trime.BuildConfig
1213
import com.osfans.trime.R
1314
import com.osfans.trime.core.Rime
1415
import com.osfans.trime.databinding.AboutActivityBinding
@@ -71,7 +72,10 @@ class AboutActivity : AppCompatActivity() {
7172
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
7273
setPreferencesFromResource(R.xml.about_preference, rootKey)
7374
findPreference<Preference>("about__changelog")
74-
?.writeLibraryVersionToSummary(Rime.get_trime_version())
75+
?.writeLibraryVersionToSummary(BuildConfig.BUILD_VERSION)
76+
77+
findPreference<Preference>("about__buildinfo")
78+
?.writeLibraryVersionToSummary(BuildConfig.BUILD_INFO)
7579

7680
findPreference<Preference>("about__librime_version")
7781
?.writeLibraryVersionToSummary(Rime.get_librime_version())

app/src/main/java/com/osfans/trime/util/AppVersionUtils.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ object AppVersionUtils {
2828
}
2929
this.summary = versionCode
3030
val intent = this.intent
31-
intent.data = Uri.withAppendedPath(intent.data, "commits/$commitHash")
32-
this.intent = intent
31+
if (intent != null) {
32+
intent.data = Uri.withAppendedPath(intent.data, "commits/$commitHash")
33+
this.intent = intent
34+
}
3335
}
3436
}

app/src/main/res/values-zh-rCN/strings.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<string name="about__opencc_version">OpenCC版本</string>
3737
<string name="about__changelog">更新日志</string>
3838
<string name="about__licensing_title">许可证</string>
39-
<string name="pref_credits">鸣谢</string>
39+
<string name="pref_credits">贡献代码</string>
4040
<string name="about__product_prime">微软平台PRIME输入法</string>
4141
<string name="about__privacy_policy">隐私策略</string>
4242
<string name="settings__configuration_title">输入配置</string>
@@ -197,4 +197,5 @@
197197
<string name="keyboard__swipe_enabled">允许触发按键的滑动手势</string>
198198
<string name="keyboard__key_swipe_velocity">触发按键滑动手势的速度(距离/速度满足其一即可)</string>
199199
<string name="keyboard__key_swipe_velocity_hi">连续击键时触发滑动手势的速度</string>
200+
<string name="about__buildinfo">编译信息</string>
200201
</resources>

app/src/main/res/values-zh-rTW/strings.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<string name="about__opencc_version">OpenCC版本</string>
3838
<string name="about__changelog">更新日誌</string>
3939
<string name="about__licensing_title">許可證</string>
40-
<string name="pref_credits">鳴謝</string>
40+
<string name="pref_credits">貢獻代碼</string>
4141
<string name="about__product_prime">Win10 PRIME輸入法平臺</string>
4242
<string name="about__privacy_policy">隱私權政策</string>
4343
<string name="settings__configuration_title">輸入配置</string>
@@ -198,4 +198,5 @@
198198
<string name="keyboard__swipe_enabled">允許觸發按鍵的滑動手勢</string>
199199
<string name="keyboard__key_swipe_velocity">觸發按鍵滑動手勢的速度(距離/速度滿足其一即可)</string>
200200
<string name="keyboard__key_swipe_velocity_hi">連續擊鍵時觸發滑動手勢的速度</string>
201+
<string name="about__buildinfo">編譯信息</string>
201202
</resources>

app/src/main/res/values/strings.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<string name="about__opencc_version">OpenCC Version</string>
3838
<string name="about__changelog">Change Log</string>
3939
<string name="about__licensing_title">License</string>
40-
<string name="pref_credits">Credits</string>
40+
<string name="pref_credits">Contribute</string>
4141
<string name="about__product_prime">Win10 PRIME Platform</string>
4242
<string name="about__privacy_policy">Privacy Policy</string>
4343
<string name="settings__configuration_title">Configurations</string>
@@ -199,4 +199,5 @@
199199
<string name="keyboard__swipe_enabled">Allow swipe gestures to trigger keys</string>
200200
<string name="keyboard__key_swipe_velocity">The speed of triggering the button swipe gesture (the distance/velocity is sufficient)</string>
201201
<string name="keyboard__key_swipe_velocity_hi">The velocity of the swipe gesture on consecutive keystrokes</string>
202+
<string name="about__buildinfo">Build info</string>
202203
</resources>

app/src/main/res/xml/about_preference.xml

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
app:title="@string/about__changelog"
1111
app:iconSpaceReserved="false">
1212
<intent android:action="android.intent.action.VIEW"
13-
android:data="https://github.com/osfans/trime" />
13+
android:data="@string/trime_url" />
14+
</Preference>
15+
16+
<Preference app:key="about__buildinfo"
17+
app:title="@string/about__buildinfo"
18+
app:iconSpaceReserved="false"> />
1419
</Preference>
1520

1621
<Preference app:key="about__librime_version"
@@ -66,7 +71,7 @@
6671
<Preference android:key="pref_credits" android:title="@string/pref_credits"
6772
app:iconSpaceReserved="false">
6873
<intent android:action="android.intent.action.VIEW"
69-
android:data="https://github.com/osfans/trime#%E9%B3%B4%E8%AC%9Dcredits" />
74+
android:data="https://github.com/osfans/trime" />
7075
</Preference>
7176

7277
<Preference app:key="about__product_prime"

0 commit comments

Comments
 (0)