优化细节

android 1.0.7
jenly1314 5 years ago
parent 946b6e8550
commit 32e71c030e
  1. 19
      README.md
  2. 2
      app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
  3. 16
      app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
  4. 14
      app-updater/src/main/java/com/king/app/updater/AppUpdater.java
  5. 22
      app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
  6. 9
      app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
  7. BIN
      app/release/app-release.apk
  8. 2
      app/release/output.json
  9. 1
      app/src/main/java/com/king/appupdater/MainActivity.java
  10. 4
      versions.gradle

@ -41,7 +41,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
<dependency> <dependency>
<groupId>com.king.app</groupId> <groupId>com.king.app</groupId>
<artifactId>app-updater</artifactId> <artifactId>app-updater</artifactId>
<version>1.0.6</version> <version>1.0.7</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
@ -49,7 +49,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
<dependency> <dependency>
<groupId>com.king.app</groupId> <groupId>com.king.app</groupId>
<artifactId>app-dialog</artifactId> <artifactId>app-dialog</artifactId>
<version>1.0.6</version> <version>1.0.7</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
``` ```
@ -58,25 +58,25 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
//----------AndroidX 版本 //----------AndroidX 版本
//app-updater //app-updater
implementation 'com.king.app:app-updater:1.0.6-androidx' implementation 'com.king.app:app-updater:1.0.7-androidx'
//app-dialog //app-dialog
implementation 'com.king.app:app-dialog:1.0.6-androidx' implementation 'com.king.app:app-dialog:1.0.7-androidx'
//----------Android Support 版本 //----------Android Support 版本
//app-updater //app-updater
implementation 'com.king.app:app-updater:1.0.6' implementation 'com.king.app:app-updater:1.0.7'
//app-dialog //app-dialog
implementation 'com.king.app:app-dialog:1.0.6' implementation 'com.king.app:app-dialog:1.0.7'
``` ```
### Lvy: ### Lvy:
```lvy ```lvy
//app-updater //app-updater
<dependency org='com.king.app' name='app-dialog' rev='1.0.6'> <dependency org='com.king.app' name='app-dialog' rev='1.0.7'>
<artifact name='$AID' ext='pom'></artifact> <artifact name='$AID' ext='pom'></artifact>
</dependency> </dependency>
//app-dialog //app-dialog
<dependency org='com.king.app' name='app-dialog' rev='1.0.6'> <dependency org='com.king.app' name='app-dialog' rev='1.0.7'>
<artifact name='$AID' ext='pom'></artifact> <artifact name='$AID' ext='pom'></artifact>
</dependency> </dependency>
``` ```
@ -142,6 +142,9 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
## 版本记录 ## 版本记录
#### v1.0.7:2019-12-18
* 优化细节
#### v1.0.6:2019-11-27 #### v1.0.6:2019-11-27
* 新增OkHttpManager 如果使用了OkHttpManager则必须依赖[okhttp](https://github.com/square/okhttp) * 新增OkHttpManager 如果使用了OkHttpManager则必须依赖[okhttp](https://github.com/square/okhttp)
* 优化细节 (progress,total 变更 int -> long) * 优化细节 (progress,total 变更 int -> long)

@ -55,7 +55,9 @@ public enum AppDialog {
try{ try{
//不强制要求要有中间的线 //不强制要求要有中间的线
View line = view.findViewById(R.id.line); View line = view.findViewById(R.id.line);
if(line != null){
line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
}
}catch (Exception e){ }catch (Exception e){
} }

@ -4,6 +4,7 @@ import android.content.Context;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -129,6 +130,11 @@ public class AppDialogConfig {
return this; return this;
} }
public AppDialogConfig setTitle(@NonNull Context context,@StringRes int resId) {
this.title = context.getString(resId);
return this;
}
public CharSequence getContent() { public CharSequence getContent() {
return content; return content;
} }
@ -147,6 +153,11 @@ public class AppDialogConfig {
return this; return this;
} }
public AppDialogConfig setCancel(@NonNull Context context,@StringRes int resId) {
this.cancel = context.getString(resId);
return this;
}
public CharSequence getOk() { public CharSequence getOk() {
return ok; return ok;
} }
@ -156,6 +167,11 @@ public class AppDialogConfig {
return this; return this;
} }
public AppDialogConfig setOk(@NonNull Context context,@StringRes int resId) {
this.ok = context.getString(resId);
return this;
}
public boolean isHideCancel() { public boolean isHideCancel() {
return isHideCancel; return isHideCancel;
} }

@ -286,8 +286,8 @@ public class AppUpdater {
} }
/** /**
* 设置下载失败是是否支持点击通知栏重新下载 * 设置下载失败是否支持点击通知栏重新下载与之相关联的方法{@link #setReDownloads(int)}
* @param reDownload 下载失败时是否支持点击通知栏重新下载默认true 最多重新下载3次 * @param reDownload 下载失败时是否支持点击通知栏重新下载默认true
* @return * @return
*/ */
public Builder setReDownload(boolean reDownload) { public Builder setReDownload(boolean reDownload) {
@ -295,6 +295,16 @@ public class AppUpdater {
return this; return this;
} }
/**
* 设置下载失败时最多重新下载次数与之相关联的方法{@link #setReDownload(boolean)}
* @param reDownloads 下载失败时是否支持点击通知栏重新下载默认最多重新下载3次
* @return
*/
public Builder setReDownloads(int reDownloads) {
mConfig.setReDownloads(reDownloads);
return this;
}
/** /**
* 设置要下载APK的versionCode * 设置要下载APK的versionCode
* @param versionCode 为null表示不处理默认不存在则下载存在则重新下载不为null时表示会优先校验本地是否存在已下载版本号为versionCode的APK * @param versionCode 为null表示不处理默认不存在则下载存在则重新下载不为null时表示会优先校验本地是否存在已下载版本号为versionCode的APK

@ -59,9 +59,13 @@ public class UpdateConfig implements Parcelable {
*/ */
private String mAuthority; private String mAuthority;
/** /**
* 下载失败是否支持点击通知栏重下载 * 下载失败是否支持点击通知栏重下载
*/ */
private boolean isReDownload = true; private boolean isReDownload = true;
/**
* 下载失败后最大重新下载次数
*/
private int reDownloads = 3;
/** /**
* 是否显示百分比 * 是否显示百分比
*/ */
@ -193,6 +197,14 @@ public class UpdateConfig implements Parcelable {
isReDownload = reDownload; isReDownload = reDownload;
} }
public int getReDownloads() {
return reDownloads;
}
public void setReDownloads(int reDownloads) {
this.reDownloads = reDownloads;
}
public boolean isVibrate() { public boolean isVibrate() {
return isVibrate; return isVibrate;
} }
@ -237,7 +249,6 @@ public class UpdateConfig implements Parcelable {
} }
} }
public boolean isDeleteCancelFile() { public boolean isDeleteCancelFile() {
return isDeleteCancelFile; return isDeleteCancelFile;
} }
@ -265,17 +276,21 @@ public class UpdateConfig implements Parcelable {
dest.writeString(this.mChannelName); dest.writeString(this.mChannelName);
dest.writeString(this.mAuthority); dest.writeString(this.mAuthority);
dest.writeByte(this.isReDownload ? (byte) 1 : (byte) 0); dest.writeByte(this.isReDownload ? (byte) 1 : (byte) 0);
dest.writeInt(this.reDownloads);
dest.writeByte(this.isShowPercentage ? (byte) 1 : (byte) 0); dest.writeByte(this.isShowPercentage ? (byte) 1 : (byte) 0);
dest.writeByte(this.isVibrate ? (byte) 1 : (byte) 0); dest.writeByte(this.isVibrate ? (byte) 1 : (byte) 0);
dest.writeByte(this.isSound ? (byte) 1 : (byte) 0); dest.writeByte(this.isSound ? (byte) 1 : (byte) 0);
dest.writeValue(this.versionCode); dest.writeValue(this.versionCode);
dest.writeInt(mRequestProperty!=null ? this.mRequestProperty.size() : 0);
if(mRequestProperty!=null){ if(mRequestProperty!=null){
dest.writeInt(this.mRequestProperty.size());
for (Map.Entry<String, String> entry : this.mRequestProperty.entrySet()) { for (Map.Entry<String, String> entry : this.mRequestProperty.entrySet()) {
dest.writeString(entry.getKey()); dest.writeString(entry.getKey());
dest.writeString(entry.getValue()); dest.writeString(entry.getValue());
} }
}else{
dest.writeInt(0);
} }
dest.writeByte(this.isDeleteCancelFile ? (byte) 1 : (byte) 0); dest.writeByte(this.isDeleteCancelFile ? (byte) 1 : (byte) 0);
} }
@ -291,6 +306,7 @@ public class UpdateConfig implements Parcelable {
this.mChannelName = in.readString(); this.mChannelName = in.readString();
this.mAuthority = in.readString(); this.mAuthority = in.readString();
this.isReDownload = in.readByte() != 0; this.isReDownload = in.readByte() != 0;
this.reDownloads = in.readInt();
this.isShowPercentage = in.readByte() != 0; this.isShowPercentage = in.readByte() != 0;
this.isVibrate = in.readByte() != 0; this.isVibrate = in.readByte() != 0;
this.isSound = in.readByte() != 0; this.isSound = in.readByte() != 0;

@ -227,12 +227,15 @@ public class DownloadService extends Service {
private UpdateCallback callback; private UpdateCallback callback;
private int reDownloads;
private AppDownloadCallback(UpdateConfig config,UpdateCallback callback){ private AppDownloadCallback(UpdateConfig config,UpdateCallback callback){
this.config = config; this.config = config;
this.callback = callback; this.callback = callback;
this.isShowNotification = config.isShowNotification(); this.isShowNotification = config.isShowNotification();
this.notifyId = config.getNotificationId(); this.notifyId = config.getNotificationId();
this.reDownloads = config.getReDownloads();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
this.channelId = TextUtils.isEmpty(config.getChannelId()) ? Constants.DEFAULT_NOTIFICATION_CHANNEL_ID : config.getChannelId(); this.channelId = TextUtils.isEmpty(config.getChannelId()) ? Constants.DEFAULT_NOTIFICATION_CHANNEL_ID : config.getChannelId();
@ -280,7 +283,7 @@ public class DownloadService extends Service {
mLastTime = curTime; mLastTime = curTime;
int currProgress = Math.round(progress * 1.0f / total * 100.0f); int currProgress = Math.round(progress * 1.0f / total * 100.0f);
if(currProgress!=mLastProgress){//百分比改变了才更新 if(currProgress != mLastProgress){//百分比改变了才更新
isChange = true; isChange = true;
String percentage = currProgress + "%"; String percentage = currProgress + "%";
if(isShowNotification) { if(isShowNotification) {
@ -319,8 +322,8 @@ public class DownloadService extends Service {
public void onError(Exception e) { public void onError(Exception e) {
Log.w(Constants.TAG,"onError:"+ e.getMessage()); Log.w(Constants.TAG,"onError:"+ e.getMessage());
isDownloading = false; 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); 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); showErrorNotification(notifyId,channelId,notificationIcon,getString(R.string.app_updater_error_notification_title),content,isReDownload,config);

Binary file not shown.

@ -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":{}}] [{"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":{}}]

@ -31,6 +31,7 @@ public class MainActivity extends AppCompatActivity {
private final Object mLock = new Object(); 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 String mUrl = "https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk";
private ProgressBar progressBar; private ProgressBar progressBar;

@ -1,7 +1,7 @@
//App //App
def app_version = [:] def app_version = [:]
app_version.versionCode = 9 //androidx 10 app_version.versionCode = 11 //androidx 12
app_version.versionName = "1.0.6" app_version.versionName = "1.0.7"
ext.app_version = app_version ext.app_version = app_version
//build version //build version

Loading…
Cancel
Save