fix: 修复非插件更新会丢失角标的问题

This commit is contained in:
juntao
2022-06-30 21:14:44 +08:00
parent 8e5ceb1e0e
commit 5a377913bb
5 changed files with 63 additions and 37 deletions

View File

@ -322,7 +322,7 @@ public class DownloadManager implements DownloadStatusListener {
downloadEntity.setEntrance(entrance);
downloadEntity.setLocation(location);
downloadEntity.setVersionName(apkEntity.getVersion());
ExtensionsKt.addMetaExtra(downloadEntity, Constants.APK_MD5, apkEntity.getMd5());
ExtensionsKt.addMetaExtra(downloadEntity, Constants.APK_MD5, "12345");
ExtensionsKt.addMetaExtra(downloadEntity, Constants.DOWNLOAD_ID, downloadId);
ExtensionsKt.addMetaExtra(downloadEntity, Constants.RAW_GAME_ICON, gameEntity.getRawIcon());
ExtensionsKt.addMetaExtra(downloadEntity, Constants.GAME_ICON_SUBSCRIPT, gameEntity.getIconSubscript());
@ -774,30 +774,39 @@ public class DownloadManager implements DownloadStatusListener {
}
entry.setStatus(DownloadStatus.cancel);
if (cancelSilently) {
cancelAndNotify(entry, true);
return;
}
// 将原来安装完成后在 downloadService 完成的功能放到这里,避免因为 ANR 造成闪退
AppExecutor.getUiExecutor().executeWithDelay(() -> {
mDownloadDao.removeErrorMessage(entry.getUrl());
DownloadTask task = DataChanger.INSTANCE.getDownloadingTasks().get(entry.getUrl());
if (task != null) {
task.cancel();
// 改任务队列的状态
DataChanger.INSTANCE.getDownloadingTasks().remove(entry.getUrl());
if (!cancelSilently) {
DataChanger.INSTANCE.notifyDataChanged(entry);
}
}
DataChanger.INSTANCE.getDownloadEntries().remove(entry.getUrl());
if (!cancelSilently) {
DataChanger.INSTANCE.notifyDataChanged(entry);
DownloadStatusManager.getInstance().onTaskCancelled(entry);
}
Utils.log(DownloadManager.class.getSimpleName(), "cancel");
cancelAndNotify(entry, false);
}, 0);
}
}
private void cancelAndNotify(DownloadEntity entry, Boolean cancelSilently) {
mDownloadDao.removeErrorMessage(entry.getUrl());
DownloadTask task = DataChanger.INSTANCE.getDownloadingTasks().get(entry.getUrl());
if (task != null) {
task.cancel();
// 改任务队列的状态
DataChanger.INSTANCE.getDownloadingTasks().remove(entry.getUrl());
if (!cancelSilently) {
DataChanger.INSTANCE.notifyDataChanged(entry);
}
}
DataChanger.INSTANCE.getDownloadEntries().remove(entry.getUrl());
if (!cancelSilently) {
DataChanger.INSTANCE.notifyDataChanged(entry);
DownloadStatusManager.getInstance().onTaskCancelled(entry);
}
Utils.log(DownloadManager.class.getSimpleName(), "cancel");
}
/**
* 暂停所有正在下载的任务
*/