tachiyomi/app
Two-Ai 3ae1e37c40
Replace RxJava in Downloader (#9256)
* Rename removeFromQueueByPredicate to removeFromQueueIf

Follow-up to PR comment in #9511

* Make Download hashCode stable

Mutating pages would previously change the Download hashCode, which
breaks HashMap lookups.

* Convert Donwloader subscription to coroutine

Replace downloadsRelay with activeDownloadsFlow. Instead of managing
a PublishRelay independent from the queue, derive a Flow of active
downloads directly from the queue StateFlow. (This will allow
updating the queue without pausing the downloader, to be done in a
follow-up PR.)

When a download completes successfully, the downloads is removed from
queueState. This updates activeDownloadsFlow and causes the
downloaderJob start the download job for the next active download.

When a download fails, the download is left in the queue, so
queueState is not modified. To make activeDownloadsFlow update
without a change to queueState, use transformLatest and use the
Download statusFlows to suspend until a download reaches the ERROR
state.

To avoid stopping and starting downloads every time
activeDownloadsFlow emits a new value, maintain a map of current
download Jobs and only start/stop jobs in the difference between
downloadJobs and activeDownloads. To make sure all child download
jobs are cancelled when the top-level downloader job is cancelled,
use supervisorScope.

* Remove obsolete main thread references in Downloader

Thread safety of the queue state used to be guaranteed by running all
queue mutation on the main thread, but this has not been true for
some time. Since the queue state is now backed by a StateFlow,
queueState can be safely updated by any thread.
2023-05-24 18:02:27 -04:00
..
src Replace RxJava in Downloader (#9256) 2023-05-24 18:02:27 -04:00
.gitignore Move google-services.json 2020-04-29 17:56:05 -04:00
build.gradle.kts Replace Cascade with our own somewhat janky implementation 2023-05-21 11:02:56 -04:00
proguard-android-optimize.txt Upgrade to AGP 8.0.0 (#9351) 2023-04-16 18:02:24 -04:00
proguard-rules.pro Revert attempts to read archives to cache first 2023-05-07 12:03:58 -04:00
shortcuts.xml Remove more unused strings 2021-05-30 11:10:16 -04:00