From 3d1250f2f83608647c75f0ad713a2a309739c01e Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 7 May 2020 19:34:40 -0400 Subject: [PATCH] Do some download deletion in coroutines instead of completable --- .../tachiyomi/ui/library/LibraryPresenter.kt | 10 ++----- .../tachiyomi/ui/reader/ReaderPresenter.kt | 28 ++++++++----------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 410dbb859..d22247e68 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.combineLatest import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed +import eu.kanade.tachiyomi.util.lang.launchIO import java.io.IOException import java.io.InputStream import java.util.ArrayList @@ -316,12 +317,9 @@ class LibraryPresenter( val mangaToDelete = mangas.distinctBy { it.id } mangaToDelete.forEach { it.favorite = false } - Observable.fromCallable { db.insertMangas(mangaToDelete).executeAsBlocking() } - .onErrorResumeNext { Observable.empty() } - .subscribeOn(Schedulers.io()) - .subscribe() + launchIO { + db.insertMangas(mangaToDelete).executeAsBlocking() - Observable.fromCallable { mangaToDelete.forEach { manga -> coverCache.deleteFromCache(manga.thumbnail_url) if (deleteChapters) { @@ -332,8 +330,6 @@ class LibraryPresenter( } } } - .subscribeOn(Schedulers.io()) - .subscribe() } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 7dc42d8e6..8bd0f4e8a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.util.lang.byteSize +import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.takeBytes import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.system.ImageUtil @@ -651,20 +652,16 @@ class ReaderPresenter( val removeAfterReadSlots = preferences.removeAfterReadSlots() if (removeAfterReadSlots == -1) return - Completable - .fromCallable { - // Position of the read chapter - val position = chapterList.indexOf(chapter) + launchIO { + // Position of the read chapter + val position = chapterList.indexOf(chapter) - // Retrieve chapter to delete according to preference - val chapterToDelete = chapterList.getOrNull(position - removeAfterReadSlots) - if (chapterToDelete != null) { - downloadManager.enqueueDeleteChapters(listOf(chapterToDelete.chapter), manga) - } + // Retrieve chapter to delete according to preference + val chapterToDelete = chapterList.getOrNull(position - removeAfterReadSlots) + if (chapterToDelete != null) { + downloadManager.enqueueDeleteChapters(listOf(chapterToDelete.chapter), manga) } - .onErrorComplete() - .subscribeOn(Schedulers.io()) - .subscribe() + } } /** @@ -672,10 +669,9 @@ class ReaderPresenter( * are ignored. */ private fun deletePendingChapters() { - Completable.fromCallable { downloadManager.deletePendingChapters() } - .onErrorComplete() - .subscribeOn(Schedulers.io()) - .subscribe() + launchIO { + downloadManager.deletePendingChapters() + } } companion object {