From a2153761c208ca9dec90eb1bc77f414ded00a33e Mon Sep 17 00:00:00 2001 From: chenjuntao Date: Tue, 30 Jul 2024 14:21:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=89=E8=A3=85=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BC=98=E5=8C=96-2024/7/30-=E9=AA=8C?= =?UTF-8?q?=E6=94=B6=E9=97=AE=E9=A2=98=20https://jira.shanqu.cc/browse/GHZ?= =?UTF-8?q?SCY-6357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenjuntao --- .../java/com/gh/download/DownloadManager.java | 24 ++++++++++--------- .../java/com/gh/gamecenter/MainActivity.java | 3 --- .../hud/ResumeDownloadHudHandler.kt | 4 ++++ .../main/java/com/halo/assistant/HaloApp.java | 3 +++ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/gh/download/DownloadManager.java b/app/src/main/java/com/gh/download/DownloadManager.java index 5a3366313c..81eb5daf23 100644 --- a/app/src/main/java/com/gh/download/DownloadManager.java +++ b/app/src/main/java/com/gh/download/DownloadManager.java @@ -996,19 +996,21 @@ public class DownloadManager implements DownloadStatusListener { * 3.检查是否显示下载通知栏 */ public void initDownloadService() { - final Set urlSet = NDataChanger.INSTANCE.getDownloadingTaskUrlSet(); - for (DownloadEntity downloadEntity : getAllDownloadEntity()) { - if (!urlSet.contains(downloadEntity.getUrl()) - && (downloadEntity.getStatus().equals(DownloadStatus.downloading) - || downloadEntity.getStatus().equals(DownloadStatus.waiting))) { - downloadEntity.setStatus(DownloadStatus.subscribe); - mDownloadDao.newOrUpdate(downloadEntity); - NDataChanger.INSTANCE.notifyDataChanged(downloadEntity); + packageExecutor.execute(() -> { + final Set urlSet = NDataChanger.INSTANCE.getDownloadingTaskUrlSet(); + for (DownloadEntity downloadEntity : getAllDownloadEntity()) { + if (!urlSet.contains(downloadEntity.getUrl()) + && (downloadEntity.getStatus().equals(DownloadStatus.downloading) + || downloadEntity.getStatus().equals(DownloadStatus.waiting))) { + downloadEntity.setStatus(DownloadStatus.subscribe); + mDownloadDao.newOrUpdate(downloadEntity); + NDataChanger.INSTANCE.notifyDataChanged(downloadEntity); + } } - } - startDownloadService(); - checkAndRetryDownload(true); + startDownloadService(); + checkAndRetryDownload(true); + }); } /** diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 2afaa1c9f5..29c7e02c55 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -255,9 +255,6 @@ public class MainActivity extends BaseActivity { } } - // 必须放在这里,否则会导致获取 baseActivity 不是本应用包名 - DownloadManager.getInstance().initDownloadService(); - ReservationRepository.refreshReservations(); // 跳转至其它页面 diff --git a/app/src/main/java/com/gh/gamecenter/hud/ResumeDownloadHudHandler.kt b/app/src/main/java/com/gh/gamecenter/hud/ResumeDownloadHudHandler.kt index 01c1733339..b20540b739 100644 --- a/app/src/main/java/com/gh/gamecenter/hud/ResumeDownloadHudHandler.kt +++ b/app/src/main/java/com/gh/gamecenter/hud/ResumeDownloadHudHandler.kt @@ -20,6 +20,10 @@ class ResumeDownloadHudHandler(priority: Int) : PriorityChainHandler(priority) { val isOnWiFiNetwork: Boolean = NetworkUtils.isWifiConnected(HaloApp.getInstance()) val downloadingEntitySnapshotList = DownloadManager.getInstance().allDownloadEntitySnapshots.filter { it.status == DownloadStatus.downloading + || it.status == DownloadStatus.pause + || it.status == DownloadStatus.subscribe + || it.status == DownloadStatus.timeout + || it.status == DownloadStatus.neterror } if (!isOnWiFiNetwork || downloadingEntitySnapshotList.isEmpty()) { diff --git a/app/src/main/java/com/halo/assistant/HaloApp.java b/app/src/main/java/com/halo/assistant/HaloApp.java index dc340584f1..5efb2837e9 100644 --- a/app/src/main/java/com/halo/assistant/HaloApp.java +++ b/app/src/main/java/com/halo/assistant/HaloApp.java @@ -364,6 +364,9 @@ public class HaloApp extends MultiDexApplication { // 必须放在外面,否则不能及时刷新用户数据 UserRepository.getInstance().getLoginUserInfo(); + // 初始化下载服务,恢复下载任务 + DownloadManager.getInstance().initDownloadService(); + GlobalPriorityChainHelper.INSTANCE.preStart(isNewForThisVersion); MainWrapperRepository.Companion.getInstance().getDataUnion();