### Display Download Progress with Custom Update Dialog Source: https://github.com/wvector/appupdate/blob/master/kotlin.md Extends the custom dialog example to include a download progress listener. It shows how to display a horizontal progress dialog during download and handle completion or errors, with an option to automatically install upon finish. ```Kotlin updateAppManager.download { onStart { HProgressDialogUtils.showHorizontalProgressDialog(this@KotlinActivity, "下载进度", false) } onProgress { progress, _ -> HProgressDialogUtils.setProgress(Math.round(progress * 100)) } onFinish { HProgressDialogUtils.cancel() true } onError { toast(it) HProgressDialogUtils.cancel() } } ``` -------------------------------- ### Integrate Custom Dialog for App Updates Source: https://github.com/wvector/appupdate/blob/master/kotlin.md Demonstrates how to override the `hasNewApp` callback to display a custom update dialog. The dialog retrieves new version information and allows the user to initiate or defer the app download and installation. ```Kotlin hasNewApp { updateApp, updateAppManager -> showDiyDialog(updateApp, updateAppManager) } ``` ```Kotlin dialog("是否升级到${updateApp.newVersion}版本?" , "新版本大小:${updateApp.targetSize}\n\n${updateApp.updateLog}") { positiveButton("升级") { updateAppManager.download() dismiss() } negativeButton("暂不升级") { dismiss() } show() } ``` -------------------------------- ### Silent Update with Custom User Confirmation Dialog Source: https://github.com/wvector/appupdate/blob/master/kotlin.md Combines silent download with a custom dialog for user confirmation before installation. The update is downloaded silently, and then a custom dialog is presented to the user to confirm the installation of the new version. ```Kotlin updateApp(mUpdateUrl, UpdateAppHttpUtil()) { setOnlyWifi() }.checkNewApp(object : SilenceUpdateCallback() { override fun showDialog(updateApp: UpdateAppBean, updateAppManager: UpdateAppManager?, appFile: File) { showSilenceDiyDialog(updateApp, appFile) } }) ``` ```Kotlin /** * 自定义对话框 */ private fun showSilenceDiyDialog(updateApp: UpdateAppBean, appFile: File?) { dialog("是否升级到${updateApp.newVersion}版本?" , "新版本大小:${updateApp.targetSize}\n\n${updateApp.updateLog}") { positiveButton("升级") { AppUpdateUtils.installApp(this@KotlinActivity, appFile) dismiss() } negativeButton("暂不升级") { dismiss() } show() } } ``` -------------------------------- ### Implement HttpManager Interface for App Updates using OkHttpUtils in Java Source: https://github.com/wvector/appupdate/blob/master/java.md This Java code snippet demonstrates how to implement the `HttpManager` interface using `OkHttpUtils` to handle common HTTP operations required for app updates. It includes methods for asynchronous GET requests (`asyncGet`), asynchronous POST requests (`asyncPost`), and file downloads (`download`), all with custom callbacks for handling responses, errors, and progress. ```Java class UpdateAppHttpUtil implements HttpManager { /** * 异步get * * @param url get请求地址 * @param params get参数 * @param callBack 回调 */ @Override public void asyncGet(@NonNull String url, @NonNull Map params, @NonNull final Callback callBack) { OkHttpUtils.get() .url(url) .params(params) .build() .execute(new StringCallback() { @Override public void onError(Call call, Response response, Exception e, int id) { callBack.onError(validateError(e, response)); } @Override public void onResponse(String response, int id) { callBack.onResponse(response); } }); } /** * 异步post * * @param url post请求地址 * @param params post请求参数 * @param callBack 回调 */ @Override public void asyncPost(@NonNull String url, @NonNull Map params, @NonNull final Callback callBack) { OkHttpUtils.post() .url(url) .params(params) .build() .execute(new StringCallback() { @Override public void onError(Call call, Response response, Exception e, int id) { callBack.onError(validateError(e, response)); } @Override public void onResponse(String response, int id) { callBack.onResponse(response); } }); } /** * 下载 * * @param url 下载地址 * @param path 文件保存路径 * @param fileName 文件名称 * @param callback 回调 */ @Override public void download(@NonNull String url, @NonNull String path, @NonNull String fileName, @NonNull final FileCallback callback) { OkHttpUtils.get() .url(url) .build() .execute(new FileCallBack(path, fileName) { @Override public void inProgress(float progress, long total, int id) { super.inProgress(progress, total, id); callback.onProgress(progress, total); } @Override public void onError(Call call, Response response, Exception e, int id) { callback.onError(validateError(e, response)); } @Override public void onResponse(File response, int id) { callback.onResponse(response); } @Override public void onBefore(Request request, int id) { super.onBefore(request, id); callback.onBefore(); } }); } } ``` -------------------------------- ### Implement HttpManager Interface for App Updates using OkHttpUtils in Java Source: https://github.com/wvector/appupdate/blob/master/kotlin.md This Java code snippet demonstrates how to implement the `HttpManager` interface using `OkHttpUtils` for handling network requests in an app update scenario. It provides asynchronous GET and POST methods, along with a file download method, all integrating with custom `Callback` and `FileCallback` interfaces and including error validation. ```java class UpdateAppHttpUtil implements HttpManager { /** * 异步get * * @param url get请求地址 * @param params get参数 * @param callBack 回调 */ @Override public void asyncGet(@NonNull String url, @NonNull Map params, @NonNull final Callback callBack) { OkHttpUtils.get() .url(url) .params(params) .build() .execute(new StringCallback() { @Override public void onError(Call call, Response response, Exception e, int id) { callBack.onError(validateError(e, response)); } @Override public void onResponse(String response, int id) { callBack.onResponse(response); } }); } /** * 异步post * * @param url post请求地址 * @param params post请求参数 * @param callBack 回调 */ @Override public void asyncPost(@NonNull String url, @NonNull Map params, @NonNull final Callback callBack) { OkHttpUtils.post() .url(url) .params(params) .build() .execute(new StringCallback() { @Override public void onError(Call call, Response response, Exception e, int id) { callBack.onError(validateError(e, response)); } @Override public void onResponse(String response, int id) { callBack.onResponse(response); } }); } /** * 下载 * * @param url 下载地址 * @param path 文件保存路径 * @param fileName 文件名称 * @param callback 回调 */ @Override public void download(@NonNull String url, @NonNull String path, @NonNull String fileName, @NonNull final FileCallback callback) { OkHttpUtils.get() .url(url) .build() .execute(new FileCallBack(path, fileName) { @Override public void inProgress(float progress, long total, int id) { super.inProgress(progress, total, id); callback.onProgress(progress, total); } @Override public void onError(Call call, Response response, Exception e, int id) { callback.onError(validateError(e, response)); } @Override public void onResponse(File response, int id) { callback.onResponse(response); } @Override public void onBefore(Request request, int id) { super.onBefore(request, id); callback.onBefore(); } }); } } ``` -------------------------------- ### Example App Update API Response Payload Source: https://github.com/wvector/appupdate/blob/master/json/json1.txt This JSON object represents a typical response from the app update API, indicating whether an update is available, the new version number, the URL to download the APK, a log of changes, the file size, MD5 hash for integrity, and update constraints. ```JSON { "update": "Yes", "new_version": "1.1", "apk_file_url": "https://raw.githubusercontent.com/WVector/AppUpdateDemo/master/apk/sample-debug.apk", "update_log": "1,添加删除信用卡接口。\r\n2,添加vip认证。\r\n3,区分自定义消费,一个小时不限制。\r\n4,添加放弃任务接口,小时内不生成。\r\n5,消费任务手动生成。", "target_size": "5M", "new_md5":"b97bea014531123f94c3ba7b7afbaad2", "constraint": true } ``` -------------------------------- ### Implement Silent App Update Source: https://github.com/wvector/appupdate/blob/master/kotlin.md Shows how to configure a silent app update using the default protocol. This example restricts updates to Wi-Fi networks only, allowing the app to download updates in the background without user interaction. ```Kotlin updateApp(mUpdateUrl, UpdateAppHttpUtil()) { setOnlyWifi() }.silenceUpdate() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.