From 3b26dc66ca9e83f178cc002c5cce3bf287d110d2 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Thu, 14 Jul 2022 15:38:20 -0400 Subject: [PATCH 1/3] Have DownloadManagerImpl pull episode from db --- .../download/DownloadManagerImpl.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/download/DownloadManagerImpl.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/download/DownloadManagerImpl.kt index 5fe0e77182c..75af85e7aae 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/download/DownloadManagerImpl.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/download/DownloadManagerImpl.kt @@ -81,7 +81,7 @@ class DownloadManagerImpl @Inject constructor( override val progressUpdates: MutableMap = mutableMapOf() override val progressUpdateRelay: Subject = ReplaySubject.createWithSize(20) - private var workManagerListener: LiveData, Map>>? = null + private var workManagerListener: LiveData, Map>>? = null override fun setup(episodeManager: EpisodeManager, podcastManager: PodcastManager, playlistManager: PlaylistManager, playbackManager: PlaybackManager) { this.episodeManager = episodeManager @@ -108,7 +108,9 @@ class DownloadManagerImpl @Inject constructor( .distinctUntilChanged { t1, t2 -> // We only really need to make sure we have all the downloading episodes available, we don't care when their metadata changes t1.map { it.uuid }.toSet() == t2.map { it.uuid }.toSet() } - .map { it.associateBy { it.downloadTaskId } } // Convert to map for easy lookup + .map { list -> + list.associateBy({ it.downloadTaskId }, { it.uuid }) // Convert to map for easy lookup + } launch(downloadsCoroutineContext) { cleanUpStaleDownloads(workManager) @@ -117,18 +119,19 @@ class DownloadManagerImpl @Inject constructor( val episodeLiveData = LiveDataReactiveStreams.fromPublisher(episodeFlowable) workManagerListener = workManager.getWorkInfosByTagLiveData(DownloadManager.WORK_MANAGER_DOWNLOAD_TAG).combineLatest(episodeLiveData) - workManagerListener?.observeForever { (tasks, episodes) -> + workManagerListener?.observeForever { (tasks, episodeUuids) -> tasks.forEach { workInfo -> val taskId = workInfo.id.toString() - val episode = episodes[taskId] - val episodeUUID = episode?.uuid + val episodeUUID = episodeUuids[taskId] if (episodeUUID != null) { val info = DownloadingInfo(episodeUUID, workInfo.id) when (workInfo.state) { WorkInfo.State.ENQUEUED, WorkInfo.State.BLOCKED -> { launch(downloadsCoroutineContext) { pendingQueue[episodeUUID] = DownloadingInfo(episodeUUID, workInfo.id) - getRequirementsAndSetStatusAsync(episode) + episodeManager.findPlayableByUuid(episodeUUID)?.let { episode -> + getRequirementsAndSetStatusAsync(episode) + } synchronized(downloadingQueue) { if (downloadingQueue.contains(info)) { downloadingQueue.remove(info) @@ -159,7 +162,8 @@ class DownloadManagerImpl @Inject constructor( episodeManager.findPlayableByUuid(episodeUUID)?.let { episodeManager.updateDownloadTaskId(it, null) - if (!episode.isDownloaded && it.episodeStatus != EpisodeStatusEnum.NOT_DOWNLOADED) { + val episode = episodeManager.findPlayableByUuid(episodeUUID) + if (episode?.isDownloaded == false && it.episodeStatus != EpisodeStatusEnum.NOT_DOWNLOADED) { episodeManager.updateEpisodeStatus(it, EpisodeStatusEnum.NOT_DOWNLOADED) } } @@ -177,7 +181,7 @@ class DownloadManagerImpl @Inject constructor( } WorkInfo.State.SUCCEEDED -> { launch(downloadsCoroutineContext) { - Timber.d("Worker succeeded: ${episode.title}") + Timber.d("Worker succeeded: $episodeUUID") synchronized(downloadingQueue) { downloadingQueue.remove(info) } From 37f2844d97bf6d2dcb5c6cfb7a1bef81a7350173 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Thu, 14 Jul 2022 16:03:56 -0400 Subject: [PATCH 2/3] Update release notes --- RELEASE-NOTES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index f16607e8e66..1f9386a73fe 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -52,6 +52,8 @@ ([#83](https://github.com/Automattic/pocket-casts-android/pull/83)). * Fix back navigation for full screen player 'Rearrange Actions' page ([#76](https://github.com/Automattic/pocket-casts-android/pull/76)). + * Fix showing paused downloads as in progress + ([#113](https://github.com/Automattic/pocket-casts-android/pull/113)). ### 7.19.2 (2022-02-11) From 6684ff9fb6ad1a0a7f6e5f469258ff8c09226d03 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Fri, 15 Jul 2022 04:36:17 -0400 Subject: [PATCH 3/3] Remove extra unnecessary retrieval of episode from db --- .../pocketcasts/repositories/download/DownloadManagerImpl.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/download/DownloadManagerImpl.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/download/DownloadManagerImpl.kt index 75af85e7aae..0b1a2baf3bb 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/download/DownloadManagerImpl.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/download/DownloadManagerImpl.kt @@ -162,8 +162,7 @@ class DownloadManagerImpl @Inject constructor( episodeManager.findPlayableByUuid(episodeUUID)?.let { episodeManager.updateDownloadTaskId(it, null) - val episode = episodeManager.findPlayableByUuid(episodeUUID) - if (episode?.isDownloaded == false && it.episodeStatus != EpisodeStatusEnum.NOT_DOWNLOADED) { + if (!it.isDownloaded && it.episodeStatus != EpisodeStatusEnum.NOT_DOWNLOADED) { episodeManager.updateEpisodeStatus(it, EpisodeStatusEnum.NOT_DOWNLOADED) } }