Skip to content

Commit 5c14547

Browse files
author
azhon
committed
fix: refactor code using kotlin
1 parent 8823411 commit 5c14547

File tree

2 files changed

+38
-81
lines changed

2 files changed

+38
-81
lines changed

README-EN.md

Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<p align="center"><img src="https://github.com/azhon/AppUpdate/blob/main/img/logo.png"></p>
44
<p align="center">
55
<img src="https://img.shields.io/badge/miniSdk-15%2B-blue.svg">
6-
<img src="https://img.shields.io/badge/jitpack%20version-3.0.7-brightgreen.svg">
6+
<img src="https://img.shields.io/badge/jitpack%20version-4.0.0-brightgreen.svg">
77
<img src="https://img.shields.io/badge/author-azhon-%23E066FF.svg">
88
<img src="https://img.shields.io/badge/license-Apache2.0-orange.svg">
99
</p>
@@ -15,8 +15,6 @@
1515
* Rendering
1616
* Function introduction
1717
* Demo download experience
18-
* DownloadManager
19-
* UpdateConfiguration
2018
* Steps for usage
2119
* Skills
2220
* Version update record
@@ -43,46 +41,7 @@
4341
* [x] Support download completion Delete old APK file after opening new version
4442
* [x] Download using HttpURLConnection, no other third-party framework is integrated
4543

46-
### [Demo download experience](https://github.com/azhon/AppUpdate/releases/tag/3.0.7)
47-
48-
### DownloadManager:Configuration Doc
49-
50-
> Initial use`DownloadManager.getInstance(this)`
51-
52-
| Attributes | Description | Default Value | Must be set |
53-
|:-------------- |:---------------------------------------------------------------------------------------------------------------------------- |:--------------------- |:----------- |
54-
| context | Context | null | true |
55-
| apkUrl | Apk download Url | null | true |
56-
| apkName | Apk download name | null | true |
57-
| downloadPath | apk download path(2.7.0 or higher is deprecated) | getExternalCacheDir() | false |
58-
| showNewerToast | Whether to prompt the user<br> "currently the latest version" toast | false | false |
59-
| smallIcon | Notification icon (resource id) | -1 | true |
60-
| configuration | Additional configuration of this library | null | false |
61-
| apkVersionCode | new apk versionCode <br>(If set, the version will be judged in the library,<br>The following properties also need to be set) | Integer.MIN_VALUE | false |
62-
| apkVersionName | new apk versionName | null | false |
63-
| apkDescription | Update description | null | false |
64-
| apkSize | New version of the apk size (unit M) | null | false |
65-
| apkMD5 | Md5 (32 bit) of the new apk | null | false |
66-
67-
### UpdateConfiguration:Configuration Doc
68-
69-
| Attributes | Description | Default Value |
70-
|:--------------------- |:--------------------------------------------------------------------------------------- |:-------------------------- |
71-
| notifyId | notification id | 1011 |
72-
| notificationChannel | Adapt to Android O notifications | See the source for details |
73-
| httpManager | Set up your own download process | null |
74-
| enableLog | Whether need to log output | true |
75-
| onDownloadListener | Callback of the download process | null |
76-
| jumpInstallPage | Whether the download completes automatically<br> pops up the installation page | true |
77-
| showNotification | Whether to display the progress of the<br> notification bar (background download toast) | true |
78-
| forcedUpgrade | Whether to force an upgrade | false |
79-
| showBgdToast | Whether need to “Downloading new version in the background…” | true |
80-
| usePlatform | Whether to use AppUpdate website | true |
81-
| onButtonClickListener | Button click event listener | null |
82-
| dialogImage | Dialog background image resource<br> (picture specification reference demo) | -1 |
83-
| dialogButtonColor | The color of the dialog button | -1 |
84-
| dialogButtonTextColor | The text color of the dialog button | -1 |
85-
| dialogProgressBarColor | Dialog progress bar and text color | -1 |
44+
### [Demo download experience](https://github.com/azhon/AppUpdate/releases/tag/4.0.0)
8645

8746
### Steps for usage
8847

@@ -102,24 +61,23 @@ allprojects {
10261
- `app/build.gradle`
10362

10463
```groovy
105-
implementation 'com.github.azhon:AppUpdate:3.0.7'
64+
implementation 'com.github.azhon:AppUpdate:4.0.0'
10665
```
10766

108-
#### Step2:Create `DownloadManager`,For more usage, please see [sample code here](https://github.com/azhon/AppUpdate/blob/main/app/src/main/java/com/azhon/app/MainActivity.java)
67+
#### Step2:Create `DownloadManager`,For more usage, please see [sample code here](https://github.com/azhon/AppUpdate/blob/main/app/src/main/java/com/azhon/app/MainActivity.kt)
10968

11069
```java
111-
UpdateConfiguration configuration = new UpdateConfiguration()
112-
113-
DownloadManager manager = DownloadManager.getInstance(this);
114-
manager.setApkName("appupdate.apk")
115-
.setApkUrl("https://raw.githubusercontent.com/azhon/AppUpdate/main/apk/appupdate.apk")
116-
.setSmallIcon(R.mipmap.ic_launcher)
117-
//Optional parameters
118-
.setConfiguration(configuration)
119-
//If this parameter is set, it will automatically determine whether to show tip dialog
120-
.setApkVersionCode(2)
121-
.setApkDescription("description...")
122-
.download();
70+
val manager = DownloadManager.Builder(this).run {
71+
apkUrl("your apk url")
72+
apkName("appupdate.apk")
73+
smallIcon(R.mipmap.ic_launcher)
74+
//If this parameter is set, it will automatically determine whether to show tip dialog
75+
apkVersionCode(2)
76+
apkDescription("description...")
77+
//Optional parameters...
78+
build()
79+
}
80+
manager?.download()
12381
```
12482

12583
#### Step3:ProGuard Rules
@@ -137,21 +95,21 @@ manager.setApkName("appupdate.apk")
13795

13896
```java
13997
//Old version apk file save path
140-
boolean b = ApkUtil.deleteOldApk(this, getExternalCacheDir().getPath() + "/appupdate.apk");
98+
val result = ApkUtil.deleteOldApk(this, "${externalCacheDir?.path}/appupdate.apk")
14199
```
142100

143101
* Tips: The contents of the upgrade dialog can be swiped up and down!
144102
* If you need to implement your own set of download process, you only need to `extends` `BaseHttpDownloadManager` and update the progress with listener.
145103

146104
```java
147-
public class MyDownload extends BaseHttpDownloadManager {}
105+
class MyDownload : BaseHttpDownloadManager() {}
148106
```
149107

150108
### Version update record
151109

152-
* v3.0.7 (2022/02/19)
110+
* v4.0.0 (2022/04/08)
153111

154-
* [Fix] Fix the problem of content leakage when the host activity is destroy
112+
* [Refactor] Refactoring with Kotlin and coroutines
155113

156114
#### [More update records click here to view](https://github.com/azhon/AppUpdate/wiki/更新日志)
157115

README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<p align="center"><img src="https://github.com/azhon/AppUpdate/blob/main/img/logo.png"></p>
44
<p align="center">
55
<img src="https://img.shields.io/badge/miniSdk-15%2B-blue.svg">
6-
<img src="https://img.shields.io/badge/jitpack%20version-3.0.7-brightgreen.svg">
6+
<img src="https://img.shields.io/badge/jitpack%20version-4.0.0-brightgreen.svg">
77
<img src="https://img.shields.io/badge/author-azhon-%23E066FF.svg">
88
<img src="https://img.shields.io/badge/license-Apache2.0-orange.svg">
99
</p>
@@ -51,7 +51,7 @@ src="https://github.com/azhon/AppUpdate/blob/main/img/qq_group.png">
5151

5252
### Demo下载体验
5353

54-
[点击下载Demo进行体验](https://github.com/azhon/AppUpdate/releases/tag/3.0.7)
54+
[点击下载Demo进行体验](https://github.com/azhon/AppUpdate/releases/tag/4.0.0)
5555

5656

5757
### 使用步骤
@@ -81,24 +81,23 @@ dependencyResolutionManagement {
8181
##### `app/build.gradle`添加依赖
8282
8383
```groovy
84-
implementation 'com.github.azhon:AppUpdate:3.0.7'
84+
implementation 'com.github.azhon:AppUpdate:4.0.0'
8585
```
8686

87-
#### 第二步:创建`DownloadManager`,更多用法请查看[这里示例代码](https://github.com/azhon/AppUpdate/blob/main/app/src/main/java/com/azhon/app/MainActivity.java)
87+
#### 第二步:创建`DownloadManager`,更多用法请查看[这里示例代码](https://github.com/azhon/AppUpdate/blob/main/app/src/main/java/com/azhon/app/MainActivity.kt)
8888

8989
```java
90-
UpdateConfiguration configuration = new UpdateConfiguration()
91-
92-
DownloadManager manager = DownloadManager.getInstance(this);
93-
manager.setApkName("appupdate.apk")
94-
.setApkUrl("https://raw.githubusercontent.com/azhon/AppUpdate/main/apk/appupdate.apk")
95-
.setSmallIcon(R.mipmap.ic_launcher)
96-
//非必须参数
97-
.setConfiguration(configuration)
98-
//设置了此参数,那么会自动判断是否需要更新弹出提示框
99-
.setApkVersionCode(2)
100-
.setApkDescription("更新描述信息(取服务端返回数据)")
101-
.download();
90+
val manager = DownloadManager.Builder(this).run {
91+
apkUrl("your apk url")
92+
apkName("appupdate.apk")
93+
smallIcon(R.mipmap.ic_launcher)
94+
//设置了此参数,那么会自动判断是否需要更新弹出提示框
95+
apkVersionCode(2)
96+
apkDescription("更新描述信息(取服务端返回数据)")
97+
//省略一些非必须参数...
98+
build()
99+
}
100+
manager?.download()
102101
```
103102
如果需要显示内置的对话框那么你需要调用`manager.setApkVersionCode()`将新版本的versionCode填进去
104103

@@ -119,21 +118,21 @@ manager.setApkName("appupdate.apk")
119118

120119
```java
121120
//旧版本apk的文件保存地址
122-
boolean b = ApkUtil.deleteOldApk(this, getExternalCacheDir().getPath() + "/appupdate.apk");
121+
val result = ApkUtil.deleteOldApk(this, "${externalCacheDir?.path}/appupdate.apk")
123122
```
124123

125124
* 温馨提示:升级对话框中的内容是可以上下滑动的哦!
126125
* 如果需要实现自己一套下载过程,只需要继承`BaseHttpDownloadManager` 并使用listener更新进度
127126

128127
```java
129-
public class MyDownload extends BaseHttpDownloadManager {}
128+
class MyDownload : BaseHttpDownloadManager() {}
130129
```
131130

132131
### 版本更新记录
133132

134-
* v3.0.7(2022/02/19
133+
* v4.0.0(2022/04/08
135134

136-
* [修复] 修复宿主页面关闭内容泄漏问题
135+
* [重构] 使用Kotlin和协程进行重构
137136

138137
* [更多更新记录点此查看](https://github.com/azhon/AppUpdate/wiki/更新日志)
139138

0 commit comments

Comments
 (0)