Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7a89b10

Browse files
committedAug 7, 2019
更新弹窗内容支持SpannableString
1 parent a4f71b0 commit 7a89b10

File tree

6 files changed

+1425
-13
lines changed

6 files changed

+1425
-13
lines changed
 

‎README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ UpdateAppUtils在应用启动时,通过对比当前应用和已下载apk的Ver
178178
<img src="https://github.com/teprinciple/UpdateAppUtils/blob/master/img/demo.png" width="220">
179179

180180
### 更新日志
181-
#### 2.0.2
182-
* 9.0Http适配
181+
#### 2.0.3
182+
* 更新弹窗内容支持SpannableString
183183
##### [更多历史版本](https://github.com/teprinciple/UpdateAppUtils/blob/master/readme/version.md)

‎app/src/main/java/com/example/teprinciple/updateappdemo/MainActivity.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,21 @@ class MainActivity : AppCompatActivity() {
4242

4343
// 浏览器下载
4444
btn_download_by_browser.setOnClickListener {
45+
46+
// 使用SpannableString
47+
val content = SpanUtils(this)
48+
.appendLine("1、Kotlin重构版")
49+
.appendLine("2、支持自定义UI").setForegroundColor(Color.RED)
50+
.appendLine("3、增加md5校验").setForegroundColor(Color.parseColor("#88e16531")).setFontSize(20, true)
51+
.appendLine("4、更多功能等你探索").setBoldItalic()
52+
.appendLine().appendImage(R.mipmap.ic_launcher).setBoldItalic()
53+
.create()
54+
4555
UpdateAppUtils
4656
.getInstance()
4757
.apkUrl(apkUrl)
4858
.updateTitle(updateTitle)
49-
.updateContent(updateContent)
59+
.updateContent(content)
5060
.updateConfig(UpdateConfig().apply {
5161
downloadBy = DownLoadBy.APP
5262
// alwaysShow = false
@@ -79,7 +89,7 @@ class MainActivity : AppCompatActivity() {
7989
startActivity(Intent(this, JavaDemoActivity::class.java))
8090
}
8191

82-
// md5校验
92+
// md5校验
8393
btn_check_md5.setOnClickListener {
8494
startActivity(Intent(this, CheckMd5DemoActivity::class.java))
8595
}

‎app/src/main/java/com/example/teprinciple/updateappdemo/SpanUtils.java

Lines changed: 1402 additions & 0 deletions
Large diffs are not rendered by default.

‎updateapputils/src/main/java/model/UiConfig.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ data class UiConfig(
2727
var updateBtnBgRes: Int? = null,
2828
var updateBtnTextColor: Int? = null,
2929
var updateBtnTextSize: Float? = null,
30-
var updateBtnText: String = GlobalContextProvider.getGlobalContext().getString(R.string.update_now),
30+
var updateBtnText: CharSequence = GlobalContextProvider.getGlobalContext().getString(R.string.update_now),
3131
// 取消按钮相关设置
3232
var cancelBtnBgColor: Int? = null,
3333
var cancelBtnBgRes: Int? = null,
3434
var cancelBtnTextColor: Int? = null,
3535
var cancelBtnTextSize: Float? = null,
36-
var cancelBtnText: String = GlobalContextProvider.getGlobalContext().getString(R.string.update_cancel),
36+
var cancelBtnText: CharSequence = GlobalContextProvider.getGlobalContext().getString(R.string.update_cancel),
3737

3838
// 开始下载时的Toast提示文字
39-
var downloadingToastText: String = GlobalContextProvider.getGlobalContext().getString(R.string.toast_download_apk),
39+
var downloadingToastText: CharSequence = GlobalContextProvider.getGlobalContext().getString(R.string.toast_download_apk),
4040
// 下载中 下载按钮以及通知栏标题前缀,进度自动拼接在后面
41-
var downloadingBtnText: String = GlobalContextProvider.getGlobalContext().getString(R.string.downloading),
41+
var downloadingBtnText: CharSequence = GlobalContextProvider.getGlobalContext().getString(R.string.downloading),
4242
// 下载出错时,下载按钮及通知栏标题
43-
var downloadFailText: String = GlobalContextProvider.getGlobalContext().getString(R.string.download_fail)
43+
var downloadFailText: CharSequence = GlobalContextProvider.getGlobalContext().getString(R.string.download_fail)
4444
)

‎updateapputils/src/main/java/model/UpdateInfo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import util.GlobalContextProvider
1010
*/
1111
internal data class UpdateInfo(
1212
// 更新标题
13-
var updateTitle: String = GlobalContextProvider.getGlobalContext().getString(R.string.update_title),
13+
var updateTitle: CharSequence = GlobalContextProvider.getGlobalContext().getString(R.string.update_title),
1414
// 更新内容
15-
var updateContent: String = GlobalContextProvider.getGlobalContext().getString(R.string.update_content),
15+
var updateContent: CharSequence = GlobalContextProvider.getGlobalContext().getString(R.string.update_content),
1616
// apk 下载地址
1717
var apkUrl: String = "",
1818
// 更新配置

‎updateapputils/src/main/java/update/UpdateAppUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ object UpdateAppUtils {
4747
/**
4848
* 设置更新标题
4949
*/
50-
fun updateTitle(title: String): UpdateAppUtils {
50+
fun updateTitle(title: CharSequence): UpdateAppUtils {
5151
updateInfo.updateTitle = title
5252
return this
5353
}
5454

5555
/**
5656
* 设置更新内容
5757
*/
58-
fun updateContent(content: String): UpdateAppUtils {
58+
fun updateContent(content: CharSequence): UpdateAppUtils {
5959
updateInfo.updateContent = content
6060
return this
6161
}

0 commit comments

Comments
 (0)
Please sign in to comment.