Skip to content

Commit

Permalink
为对外提供的自定义使用的api增加是否正在下载的判断限制
Browse files Browse the repository at this point in the history
  • Loading branch information
xuexiangjys committed Mar 26, 2023
1 parent 53f3622 commit e5218fa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/update_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"VersionName": "1.0.2",
"UploadTime": "2018-07-10 17:28:41",
"ModifyContent": "\r\n1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。\n1、优化api接口。\n2、添加使用demo演示。\n3、新增自定义更新服务API接口。\n4、优化更新提示界面。",
"DownloadUrl": "https://down.qq.com/qqweb/QQ_1/android_apk/Android_8.5.0.5025_537066738.apk",
"DownloadUrl": "https://downv6.qq.com/qqweb/QQ_1/android_apk/Android_8.9.35.10440_537153294_64.apk",
"ApkSize": 2048,
"ApkMd5": "560017dc94e8f9b65f4ca997c7feb326"
}
17 changes: 15 additions & 2 deletions xupdate-lib/src/main/java/com/xuexiang/xupdate/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.xuexiang.xupdate.entity.UpdateError.ERROR.CHECK_NO_NETWORK;
import static com.xuexiang.xupdate.entity.UpdateError.ERROR.CHECK_NO_WIFI;
import static com.xuexiang.xupdate.entity.UpdateError.ERROR.CHECK_UPDATING;
import static com.xuexiang.xupdate.entity.UpdateError.ERROR.PROMPT_ACTIVITY_DESTROY;

import android.content.Context;
Expand Down Expand Up @@ -432,23 +433,35 @@ public void recycle() {
*
* @param downloadUrl 下载地址
* @param downloadListener 下载监听
* @return 是否执行成功
*/
public void download(String downloadUrl, @Nullable OnFileDownloadListener downloadListener) {
public boolean download(String downloadUrl, @Nullable OnFileDownloadListener downloadListener) {
if (_XUpdate.isAppUpdating("")) {
_XUpdate.onUpdateError(CHECK_UPDATING);
return false;
}
startDownload(refreshParams(new UpdateEntity().setDownloadUrl(downloadUrl)), downloadListener);
return true;
}

/**
* 直接更新,不使用版本更新检查器
*
* @param updateEntity 版本更新信息
* @return 是否执行成功
*/
public void update(UpdateEntity updateEntity) {
public boolean update(UpdateEntity updateEntity) {
if (_XUpdate.isAppUpdating("")) {
_XUpdate.onUpdateError(CHECK_UPDATING);
return false;
}
mUpdateEntity = refreshParams(updateEntity);
try {
UpdateUtils.processUpdateEntity(mUpdateEntity, "这里调用的是直接更新方法,因此没有json!", this);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}


Expand Down
10 changes: 10 additions & 0 deletions xupdate-lib/src/main/java/com/xuexiang/xupdate/_XUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.xuexiang.xupdate.proxy.IUpdateParser;
import com.xuexiang.xupdate.proxy.IUpdatePrompter;
import com.xuexiang.xupdate.proxy.impl.DefaultFileEncryptor;
import com.xuexiang.xupdate.service.DownloadService;
import com.xuexiang.xupdate.utils.ApkInstallUtils;

import java.io.File;
Expand Down Expand Up @@ -80,6 +81,15 @@ public final class _XUpdate {
*/
private static final long CHECK_TIMEOUT = 10 * 1000L;

/**
* 获取是否正在进行更新
*
* @param url 请求地址
*/
public static boolean isAppUpdating(String url) {
return DownloadService.isRunning() || _XUpdate.getCheckUrlStatus(url) || _XUpdate.isPrompterShow(url);
}

/**
* 设置版本检查的状态【防止重复检查】
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onBeforeCheck() {

@Override
public void checkVersion(boolean isGet, @NonNull final String url, @NonNull Map<String, Object> params, final @NonNull IUpdateProxy updateProxy) {
if (DownloadService.isRunning() || _XUpdate.getCheckUrlStatus(url) || _XUpdate.isPrompterShow(url)) {
if (_XUpdate.isAppUpdating(url)) {
updateProxy.onAfterCheck();
_XUpdate.onUpdateError(CHECK_UPDATING);
return;
Expand Down

0 comments on commit e5218fa

Please sign in to comment.