From f98b4f4e39514a48aab34ef4afee675bbd5bd6ac Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 24 Sep 2022 22:59:11 +0700 Subject: [PATCH] DownloadController: Fix first active download status not updating (#8069) --- .../data/download/model/DownloadQueue.kt | 4 +++- .../ui/download/DownloadController.kt | 22 ++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt index 6725b31083..06c3587ebd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt @@ -75,7 +75,9 @@ class DownloadQueue( Observable.from(this).filter { download -> download.status == Download.State.DOWNLOADING } @Deprecated("Use getStatusAsFlow instead") - fun getStatusObservable(): Observable = statusSubject.onBackpressureBuffer() + fun getStatusObservable(): Observable = statusSubject + .startWith(getActiveDownloads()) + .onBackpressureBuffer() fun getStatusAsFlow(): Flow = getStatusObservable().asFlow() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index 3329095966..026c3127e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -90,19 +90,6 @@ class DownloadController : override fun createPresenter() = DownloadPresenter() - override fun onViewCreated(view: View) { - super.onViewCreated(view) - - viewScope.launchUI { - presenter.getDownloadStatusFlow() - .collect(this@DownloadController::onStatusChange) - } - viewScope.launchUI { - presenter.getDownloadProgressFlow() - .collect(this@DownloadController::onUpdateDownloadedPages) - } - } - @Composable override fun ComposeContent() { val context = LocalContext.current @@ -291,6 +278,15 @@ class DownloadController : ViewCompat.setNestedScrollingEnabled(controllerBinding.root, true) + viewScope.launchUI { + presenter.getDownloadStatusFlow() + .collect(this@DownloadController::onStatusChange) + } + viewScope.launchUI { + presenter.getDownloadProgressFlow() + .collect(this@DownloadController::onUpdateDownloadedPages) + } + controllerBinding.root }, update = {