Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: update UI when download status changes #113

Merged
merged 3 commits into from
Jul 15, 2022

Conversation

mchowning
Copy link
Contributor

@mchowning mchowning commented Jul 14, 2022

Description

Fixes #112

When a download is started by adding something to the up next queue (because of the auto download setting), if you switch from an unmetered to a metered connection, the download status still shows that the download is in progress even though the download has actually been paused.

This is occurring because the download is listening for episode changes and putting those episodes into a map keyed on the download task id. That map is not updated however, unless there is a new/removed/changed uuid. As a result, that episode instance's episodeStatus remains in "waiting for wifi" even once the download starts. Then when the download stops, the app checks if the episodeStatus needs updating to "waiting for wifi", but because it checks against the outdated episode instance contained in the map, it doesn't think the episodeStatus needs to be updated even though the episodeStatus of the episode in the db should be updated.

This PR addresses that issue by instead retrieving the "current" episode from the database to see if the episodeStatus needs to be updated. In addition, I have changed the id -> episode to instead be an id -> uuid map to help avoid us from making this mistake again in the future.

Test Steps

  1. Turn on the Auto Download setting for "Episodes added to Up Next"
  2. Turn on the Auto Download setting for "
  3. Connect to an unmetered connection (you can toggle whether a wireless network is metered or not in the network's advanced settings)
  4. Add an episode to the Up Next queue
  5. Observe that the UI shows the download is in progress
  6. Switch to a metered connection (or switch your current connection to be metered in the wifi settings)
  7. Observe that the UI shows the download is queued (without this fix it would still show that the download was in progress).

Checklist

  • Should this change be included in the release notes? If yes, please add a line in RELEASE-NOTES.md
  • Have you tested in landscape?
  • Have you tested accessibility with TalkBack?
  • Have you tested in different themes?
  • Does the change work with a large display font?
  • Are all the strings localized?
  • Could you have written any new tests?
  • Did you include Compose previews with any components?

@@ -81,7 +81,7 @@ class DownloadManagerImpl @Inject constructor(
override val progressUpdates: MutableMap<String, DownloadProgressUpdate> = mutableMapOf()
override val progressUpdateRelay: Subject<DownloadProgressUpdate> = ReplaySubject.createWithSize(20)

private var workManagerListener: LiveData<Pair<List<WorkInfo>, Map<String?, Playable>>>? = null
private var workManagerListener: LiveData<Pair<List<WorkInfo>, Map<String?, String>>>? = null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was very tempted to wrap one or both of these Strings with an inline class in order to make it clear what is what. I can be a little type-happy at times though, so I held off. It might be interesting to use some value classes for things like UUIDs throughout the app though. 🤔

@mchowning mchowning marked this pull request as ready for review July 14, 2022 20:04
geekygecko
geekygecko previously approved these changes Jul 15, 2022
Copy link
Member

@geekygecko geekygecko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work fixing this!

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for getting the episode out of the database again after the updateDownloadTaskId?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is not. I just totally overlooked that we already had the episode here as it. 🤦 Thanks for catching that! 🙇 I've addressed this in 6684ff9.

@mchowning mchowning merged commit f56315a into main Jul 15, 2022
@mchowning mchowning deleted the fix/update-ui-when-switch-to-metered branch July 15, 2022 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switching from unmetered to metered connection pauses download without updating UI
2 participants