diff --git a/README.md b/README.md index b5846bb..2993b69 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版 com.king.app app-updater - 1.0.6 + 1.0.7 pom @@ -48,7 +48,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版 com.king.app app-dialog - 1.0.6 + 1.0.7 pom ``` @@ -57,25 +57,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 - + ``` @@ -141,6 +141,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 c9eca29..14706fa 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 @@ -56,7 +56,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 5e7fdc2..d1c88e2 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 @@ -7,6 +7,7 @@ import android.view.View; import androidx.annotation.IdRes; import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; +import androidx.annotation.StringRes; /** * @author Jenly Jenly @@ -15,13 +16,11 @@ public class AppDialogConfig { /** * 布局ID */ - private @LayoutRes - int layoutId = R.layout.app_dialog; + private @LayoutRes int layoutId = R.layout.app_dialog; /** * 标题视图ID */ - private @IdRes - int titleId = R.id.tvDialogTitle; + private @IdRes int titleId = R.id.tvDialogTitle; /** * 内容视图ID */ @@ -132,6 +131,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; } @@ -150,6 +154,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; } @@ -159,6 +168,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; } @@ -204,4 +218,4 @@ public class AppDialogConfig { -} +} \ No newline at end of file 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 e10c49b..4d02fb6 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 @@ -90,6 +90,7 @@ public class AppUpdater { PermissionUtils.verifyReadAndWritePermissions((Activity) mContext,Constants.RE_CODE_STORAGE_PERMISSION); } + if(mConfig.isShowNotification() && !PermissionUtils.isNotificationEnabled(mContext)){ Log.w(Constants.TAG,"Notification permission not enabled."); } @@ -286,8 +287,8 @@ public class AppUpdater { } /** - * 设置下载失败是是否支持点击通知栏重新下载 - * @param reDownload 下载失败时是否支持点击通知栏重新下载,默认true 最多重新下载3次 + * 设置下载失败时,是否支持点击通知栏重新下载。与之相关联的方法{@link #setReDownloads(int)} + * @param reDownload 下载失败时是否支持点击通知栏重新下载,默认true * @return */ public Builder setReDownload(boolean reDownload) { @@ -295,6 +296,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。 @@ -337,7 +348,6 @@ public class AppUpdater { return this; } - public AppUpdater build(@NonNull Context context){ AppUpdater appUpdater = new AppUpdater(context,mConfig); return appUpdater; 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 6df82e0..ccda1f4 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 @@ -60,9 +60,13 @@ public class UpdateConfig implements Parcelable { */ private String mAuthority; /** - * 下载失败是否支持点击通知栏重复下载 + * 下载失败是否支持点击通知栏重新下载 */ private boolean isReDownload = true; + /** + * 下载失败后,最大重新下载次数 + */ + private int reDownloads = 3; /** * 是否显示百分比 */ @@ -194,6 +198,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; } @@ -238,7 +250,6 @@ public class UpdateConfig implements Parcelable { } } - public boolean isDeleteCancelFile() { return isDeleteCancelFile; } @@ -266,17 +277,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); } @@ -292,6 +307,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 311f0e6..5a6dd6d 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 @@ -12,7 +12,6 @@ import android.os.Build; import android.os.IBinder; import android.text.TextUtils; import android.util.Log; -import android.widget.RemoteViews; import com.king.app.updater.R; import com.king.app.updater.UpdateConfig; @@ -229,12 +228,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(); @@ -282,7 +284,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) { @@ -321,8 +323,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 9ef9e9d..7ef4fe3 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 7f0091e..747e74b 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -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":{}}] \ No newline at end of file +[{"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":{}}] \ 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 bae36c8..386ddb7 100644 --- a/app/src/main/java/com/king/appupdater/MainActivity.java +++ b/app/src/main/java/com/king/appupdater/MainActivity.java @@ -32,6 +32,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 e8d9d24..2b49549 100644 --- a/versions.gradle +++ b/versions.gradle @@ -1,7 +1,7 @@ //App def app_version = [:] -app_version.versionCode = 10 //androidx 10 -app_version.versionName = "1.0.6-androidx" +app_version.versionCode = 12 //androidx 12 +app_version.versionName = "1.0.7-androidx" ext.app_version = app_version //build version @@ -15,7 +15,7 @@ ext.build_versions = build_versions // App dependencies def versions = [:] //support -versions.supportLibrary = "1.0.0+" +versions.supportLibrary = "1.1.0" versions.constraintLayout = "1.1.3" //test