优化细节

pull/27/head 1.0.7-androidx
jenly1314 5 years ago
parent d29c1348ad
commit 3838ad6685
  1. 19
      README.md
  2. 2
      app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
  3. 22
      app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java
  4. 16
      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. 10
      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. 6
      versions.gradle

@ -40,7 +40,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>
@ -48,7 +48,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>
``` ```
@ -57,25 +57,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>
``` ```
@ -141,6 +141,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)

@ -56,7 +56,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){
} }

@ -7,6 +7,7 @@ import android.view.View;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes; import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
/** /**
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
@ -15,13 +16,11 @@ public class AppDialogConfig {
/** /**
* 布局ID * 布局ID
*/ */
private @LayoutRes private @LayoutRes int layoutId = R.layout.app_dialog;
int layoutId = R.layout.app_dialog;
/** /**
* 标题视图ID * 标题视图ID
*/ */
private @IdRes private @IdRes int titleId = R.id.tvDialogTitle;
int titleId = R.id.tvDialogTitle;
/** /**
* 内容视图ID * 内容视图ID
*/ */
@ -132,6 +131,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;
} }
@ -150,6 +154,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;
} }
@ -159,6 +168,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;
} }

@ -90,6 +90,7 @@ public class AppUpdater {
PermissionUtils.verifyReadAndWritePermissions((Activity) mContext,Constants.RE_CODE_STORAGE_PERMISSION); PermissionUtils.verifyReadAndWritePermissions((Activity) mContext,Constants.RE_CODE_STORAGE_PERMISSION);
} }
if(mConfig.isShowNotification() && !PermissionUtils.isNotificationEnabled(mContext)){ if(mConfig.isShowNotification() && !PermissionUtils.isNotificationEnabled(mContext)){
Log.w(Constants.TAG,"Notification permission not enabled."); Log.w(Constants.TAG,"Notification permission not enabled.");
} }
@ -286,8 +287,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 +296,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
@ -337,7 +348,6 @@ public class AppUpdater {
return this; return this;
} }
public AppUpdater build(@NonNull Context context){ public AppUpdater build(@NonNull Context context){
AppUpdater appUpdater = new AppUpdater(context,mConfig); AppUpdater appUpdater = new AppUpdater(context,mConfig);
return appUpdater; return appUpdater;

@ -60,9 +60,13 @@ public class UpdateConfig implements Parcelable {
*/ */
private String mAuthority; private String mAuthority;
/** /**
* 下载失败是否支持点击通知栏重下载 * 下载失败是否支持点击通知栏重下载
*/ */
private boolean isReDownload = true; private boolean isReDownload = true;
/**
* 下载失败后最大重新下载次数
*/
private int reDownloads = 3;
/** /**
* 是否显示百分比 * 是否显示百分比
*/ */
@ -194,6 +198,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;
} }
@ -238,7 +250,6 @@ public class UpdateConfig implements Parcelable {
} }
} }
public boolean isDeleteCancelFile() { public boolean isDeleteCancelFile() {
return isDeleteCancelFile; return isDeleteCancelFile;
} }
@ -266,17 +277,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);
} }
@ -292,6 +307,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;

@ -12,7 +12,6 @@ import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.RemoteViews;
import com.king.app.updater.R; import com.king.app.updater.R;
import com.king.app.updater.UpdateConfig; import com.king.app.updater.UpdateConfig;
@ -229,12 +228,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();
@ -282,7 +284,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) {
@ -321,8 +323,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":10,"versionName":"1.0.6-androidx","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":12,"versionName":"1.0.7-androidx","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

@ -32,6 +32,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 = 10 //androidx 10 app_version.versionCode = 12 //androidx 12
app_version.versionName = "1.0.6-androidx" app_version.versionName = "1.0.7-androidx"
ext.app_version = app_version ext.app_version = app_version
//build version //build version
@ -15,7 +15,7 @@ ext.build_versions = build_versions
// App dependencies // App dependencies
def versions = [:] def versions = [:]
//support //support
versions.supportLibrary = "1.0.0+" versions.supportLibrary = "1.1.0"
versions.constraintLayout = "1.1.3" versions.constraintLayout = "1.1.3"
//test //test

Loading…
Cancel
Save