Keep a playlist's downloads in sync with the server - #1105
Open
herrerad85 wants to merge 1 commit into
Open
herrerad85 wants to merge 1 commit into
herrerad85 wants to merge 1 commit into
Conversation
Part of eddyizm#273, the half that works while the app is open. A playlist marked Keep synced in its overflow menu downloads any track not yet downloaded or queued when the flag is turned on, every time its page opens, and once on every app open for every kept playlist. The page asks the server for the songs again on every open of a kept playlist, because the view model keeps the last list across reopens of the same playlist and a stale list would miss exactly the tracks the flag exists to catch. Tracks that leave the playlist stay downloaded, and a download row that already names a playlist keeps it, because the download table has one playlist column per track and removing on that basis would delete a track another playlist or an album still owns. Download all on the playlist page now goes through the same check. Before this it handed every track to the download service, and media3 puts a completed download back in the queued state when it is added again, so a playlist of already downloaded tracks ran through the service a second time and its rows were rewritten. The flag lives in a new synced_playlist table, database version 23, keyed by playlist and server URL because playlist ids repeat across servers, and cleaned up where pinned_playlist is, on a server error 70 and when a refresh finds the playlist gone. A track asked for in this process counts as present, the download tracker only learned about one once it completed, so without that every open during a long download queued the whole playlist again. A service start the system refuses from the background is logged and skipped instead of crashing. The app open sync does not accept the cached copy of a playlist, a stale cache would miss exactly the tracks it exists to catch, so offline it does nothing. Not covered here and left for a follow up, checking while the app is closed, which needs a scheduled worker.
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #273.
What this does
A playlist's overflow menu gets a checkable "Keep synced" item. Turning it on downloads every track not already downloaded or queued, and the check runs again on every page open and once at app start. With a download folder set, the check runs against the folder instead. A kept playlist's page asks the server on every open instead of its cached list.
Download all uses the same check, so already downloaded tracks no longer go back through the queue. A download start the system refuses from the background now logs and skips instead of crashing, for every download.
Keep synced is per playlist and per server, since two servers can hand out the same playlist id, and cleared when the playlist is deleted or the server no longer has it. This moves the database to version 23.
Tracks that leave the playlist stay downloaded, since a track remembers only one playlist and removing it could take one another playlist or album still needs. Nothing runs while the app is closed. Editing a server's address turns Keep synced off.
Tested
On an emulator and an android 16 device. Toggle on, a track added on the server then the page reopened, another added then the app reopened, wifi only holding a track back, no extra fetch on rotation, and the database moving from 22 to 23 over existing data. Keep synced was tested against three servers, and toggle on, reopen and app reopen ran with a download folder set.