diff --git a/README.md b/README.md
index 1aa0971..a71cff1 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
com.king.app
app-updater
- 1.0.6
+ 1.0.7
pom
@@ -49,7 +49,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
com.king.app
app-dialog
- 1.0.6
+ 1.0.7
pom
```
@@ -58,25 +58,25 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
//----------AndroidX 版本
//app-updater
- implementation 'com.king.app:app-updater:1.0.6-androidx'
+ implementation 'com.king.app:app-updater:1.0.7-androidx'
//app-dialog
- implementation 'com.king.app:app-dialog:1.0.6-androidx'
+ implementation 'com.king.app:app-dialog:1.0.7-androidx'
//----------Android Support 版本
//app-updater
- implementation 'com.king.app:app-updater:1.0.6'
+ implementation 'com.king.app:app-updater:1.0.7'
//app-dialog
- implementation 'com.king.app:app-dialog:1.0.6'
+ implementation 'com.king.app:app-dialog:1.0.7'
```
### Lvy:
```lvy
//app-updater
-
+
//app-dialog
-
+
```
@@ -142,6 +142,9 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
## 版本记录
+#### v1.0.7:2019-12-18
+* 优化细节
+
#### v1.0.6:2019-11-27
* 新增OkHttpManager 如果使用了OkHttpManager则必须依赖[okhttp](https://github.com/square/okhttp)
* 优化细节 (progress,total 变更 int -> long)
diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
index f829f31..8329476 100644
--- a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
+++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
@@ -55,7 +55,9 @@ public enum AppDialog {
try{
//不强制要求要有中间的线
View line = view.findViewById(R.id.line);
- line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
+ if(line != null){
+ line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
+ }
}catch (Exception e){
}
diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
index 70acaa4..485037f 100644
--- a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
+++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
@@ -4,6 +4,7 @@ import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
+import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
@@ -129,6 +130,11 @@ public class AppDialogConfig {
return this;
}
+ public AppDialogConfig setTitle(@NonNull Context context,@StringRes int resId) {
+ this.title = context.getString(resId);
+ return this;
+ }
+
public CharSequence getContent() {
return content;
}
@@ -147,6 +153,11 @@ public class AppDialogConfig {
return this;
}
+ public AppDialogConfig setCancel(@NonNull Context context,@StringRes int resId) {
+ this.cancel = context.getString(resId);
+ return this;
+ }
+
public CharSequence getOk() {
return ok;
}
@@ -156,6 +167,11 @@ public class AppDialogConfig {
return this;
}
+ public AppDialogConfig setOk(@NonNull Context context,@StringRes int resId) {
+ this.ok = context.getString(resId);
+ return this;
+ }
+
public boolean isHideCancel() {
return isHideCancel;
}
diff --git a/app-updater/src/main/java/com/king/app/updater/AppUpdater.java b/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
index fbfa2b2..76c4535 100644
--- a/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
+++ b/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
@@ -286,8 +286,8 @@ public class AppUpdater {
}
/**
- * 设置下载失败是是否支持点击通知栏重新下载
- * @param reDownload 下载失败时是否支持点击通知栏重新下载,默认true 最多重新下载3次
+ * 设置下载失败时,是否支持点击通知栏重新下载。与之相关联的方法{@link #setReDownloads(int)}
+ * @param reDownload 下载失败时是否支持点击通知栏重新下载,默认true
* @return
*/
public Builder setReDownload(boolean reDownload) {
@@ -295,6 +295,16 @@ public class AppUpdater {
return this;
}
+ /**
+ * 设置下载失败时,最多重新下载次数。与之相关联的方法{@link #setReDownload(boolean)}
+ * @param reDownloads 下载失败时是否支持点击通知栏重新下载,默认最多重新下载3次
+ * @return
+ */
+ public Builder setReDownloads(int reDownloads) {
+ mConfig.setReDownloads(reDownloads);
+ return this;
+ }
+
/**
* 设置要下载APK的versionCode
* @param versionCode 为null表示不处理,默认不存在则下载,存在则重新下载。不为null时,表示会优先校验本地是否存在已下载版本号为versionCode的APK。
diff --git a/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java b/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
index 2ecc07e..2c23423 100644
--- a/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
+++ b/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
@@ -59,9 +59,13 @@ public class UpdateConfig implements Parcelable {
*/
private String mAuthority;
/**
- * 下载失败是否支持点击通知栏重复下载
+ * 下载失败是否支持点击通知栏重新下载
*/
private boolean isReDownload = true;
+ /**
+ * 下载失败后,最大重新下载次数
+ */
+ private int reDownloads = 3;
/**
* 是否显示百分比
*/
@@ -193,6 +197,14 @@ public class UpdateConfig implements Parcelable {
isReDownload = reDownload;
}
+ public int getReDownloads() {
+ return reDownloads;
+ }
+
+ public void setReDownloads(int reDownloads) {
+ this.reDownloads = reDownloads;
+ }
+
public boolean isVibrate() {
return isVibrate;
}
@@ -237,7 +249,6 @@ public class UpdateConfig implements Parcelable {
}
}
-
public boolean isDeleteCancelFile() {
return isDeleteCancelFile;
}
@@ -265,17 +276,21 @@ public class UpdateConfig implements Parcelable {
dest.writeString(this.mChannelName);
dest.writeString(this.mAuthority);
dest.writeByte(this.isReDownload ? (byte) 1 : (byte) 0);
+ dest.writeInt(this.reDownloads);
dest.writeByte(this.isShowPercentage ? (byte) 1 : (byte) 0);
dest.writeByte(this.isVibrate ? (byte) 1 : (byte) 0);
dest.writeByte(this.isSound ? (byte) 1 : (byte) 0);
dest.writeValue(this.versionCode);
- dest.writeInt(mRequestProperty!=null ? this.mRequestProperty.size() : 0);
if(mRequestProperty!=null){
+ dest.writeInt(this.mRequestProperty.size());
for (Map.Entry entry : this.mRequestProperty.entrySet()) {
dest.writeString(entry.getKey());
dest.writeString(entry.getValue());
}
+ }else{
+ dest.writeInt(0);
}
+
dest.writeByte(this.isDeleteCancelFile ? (byte) 1 : (byte) 0);
}
@@ -291,6 +306,7 @@ public class UpdateConfig implements Parcelable {
this.mChannelName = in.readString();
this.mAuthority = in.readString();
this.isReDownload = in.readByte() != 0;
+ this.reDownloads = in.readInt();
this.isShowPercentage = in.readByte() != 0;
this.isVibrate = in.readByte() != 0;
this.isSound = in.readByte() != 0;
diff --git a/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java b/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
index 39dc89a..125e124 100644
--- a/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
+++ b/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
@@ -227,12 +227,15 @@ public class DownloadService extends Service {
private UpdateCallback callback;
+ private int reDownloads;
+
private AppDownloadCallback(UpdateConfig config,UpdateCallback callback){
this.config = config;
this.callback = callback;
this.isShowNotification = config.isShowNotification();
this.notifyId = config.getNotificationId();
+ this.reDownloads = config.getReDownloads();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
this.channelId = TextUtils.isEmpty(config.getChannelId()) ? Constants.DEFAULT_NOTIFICATION_CHANNEL_ID : config.getChannelId();
@@ -280,7 +283,7 @@ public class DownloadService extends Service {
mLastTime = curTime;
int currProgress = Math.round(progress * 1.0f / total * 100.0f);
- if(currProgress!=mLastProgress){//百分比改变了才更新
+ if(currProgress != mLastProgress){//百分比改变了才更新
isChange = true;
String percentage = currProgress + "%";
if(isShowNotification) {
@@ -319,8 +322,8 @@ public class DownloadService extends Service {
public void onError(Exception e) {
Log.w(Constants.TAG,"onError:"+ e.getMessage());
isDownloading = false;
- //支持下载失败重新并最多支持失败下载3次
- boolean isReDownload = this.isReDownload && mCount < 3;
+ //支持下载失败时重新下载,当重新下载次数不超过限制时才被允许
+ boolean isReDownload = this.isReDownload && mCount < reDownloads;
String content = isReDownload ? getString(R.string.app_updater_error_notification_content_re_download) : getString(R.string.app_updater_error_notification_content);
showErrorNotification(notifyId,channelId,notificationIcon,getString(R.string.app_updater_error_notification_title),content,isReDownload,config);
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
index 739275e..0f294df 100644
Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ
diff --git a/app/release/output.json b/app/release/output.json
index ba0c81b..9a9599b 100644
--- a/app/release/output.json
+++ b/app/release/output.json
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":9,"versionName":"1.0.6","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":11,"versionName":"1.0.7","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
diff --git a/app/src/main/java/com/king/appupdater/MainActivity.java b/app/src/main/java/com/king/appupdater/MainActivity.java
index 285112a..1b442d3 100644
--- a/app/src/main/java/com/king/appupdater/MainActivity.java
+++ b/app/src/main/java/com/king/appupdater/MainActivity.java
@@ -31,6 +31,7 @@ public class MainActivity extends AppCompatActivity {
private final Object mLock = new Object();
+ //下载出现Failed to connect to raw.githubusercontent.com时,可以换个下载链接测试,github的raw.githubusercontent.com目前不太稳定。
private String mUrl = "https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk";
private ProgressBar progressBar;
diff --git a/versions.gradle b/versions.gradle
index a0daf94..afb2e76 100644
--- a/versions.gradle
+++ b/versions.gradle
@@ -1,7 +1,7 @@
//App
def app_version = [:]
-app_version.versionCode = 9 //androidx 10
-app_version.versionName = "1.0.6"
+app_version.versionCode = 11 //androidx 12
+app_version.versionName = "1.0.7"
ext.app_version = app_version
//build version