mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 03:59:19 +01:00
Use coroutines instead of rx for some MangaPresenter operations
This commit is contained in:
parent
dcb6bfb18d
commit
bf32bf28da
@ -21,8 +21,10 @@ import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem
|
|||||||
import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper
|
import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper
|
||||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||||
import eu.kanade.tachiyomi.util.isLocal
|
import eu.kanade.tachiyomi.util.isLocal
|
||||||
|
import eu.kanade.tachiyomi.util.lang.await
|
||||||
import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed
|
import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
import eu.kanade.tachiyomi.util.prepUpdateCover
|
import eu.kanade.tachiyomi.util.prepUpdateCover
|
||||||
import eu.kanade.tachiyomi.util.removeCovers
|
import eu.kanade.tachiyomi.util.removeCovers
|
||||||
import eu.kanade.tachiyomi.util.shouldDownloadNewChapters
|
import eu.kanade.tachiyomi.util.shouldDownloadNewChapters
|
||||||
@ -461,7 +463,7 @@ class MangaPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
launchIO {
|
launchIO {
|
||||||
db.updateChaptersProgress(chapters).executeAsBlocking()
|
db.updateChaptersProgress(chapters).await()
|
||||||
|
|
||||||
if (preferences.removeAfterMarkedAsRead()) {
|
if (preferences.removeAfterMarkedAsRead()) {
|
||||||
deleteChapters(chapters)
|
deleteChapters(chapters)
|
||||||
@ -482,14 +484,13 @@ class MangaPresenter(
|
|||||||
* @param selectedChapters the list of chapters to bookmark.
|
* @param selectedChapters the list of chapters to bookmark.
|
||||||
*/
|
*/
|
||||||
fun bookmarkChapters(selectedChapters: List<ChapterItem>, bookmarked: Boolean) {
|
fun bookmarkChapters(selectedChapters: List<ChapterItem>, bookmarked: Boolean) {
|
||||||
Observable.from(selectedChapters)
|
launchIO {
|
||||||
.doOnNext { chapter ->
|
selectedChapters
|
||||||
chapter.bookmark = bookmarked
|
.forEach {
|
||||||
|
it.bookmark = bookmarked
|
||||||
|
db.updateChapterProgress(it).await()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.toList()
|
|
||||||
.flatMap { db.updateChaptersProgress(it).asRxObservable() }
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.subscribe()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -497,36 +498,32 @@ class MangaPresenter(
|
|||||||
* @param chapters the list of chapters to delete.
|
* @param chapters the list of chapters to delete.
|
||||||
*/
|
*/
|
||||||
fun deleteChapters(chapters: List<ChapterItem>) {
|
fun deleteChapters(chapters: List<ChapterItem>) {
|
||||||
Observable.just(chapters)
|
launchIO {
|
||||||
.doOnNext { deleteChaptersInternal(chapters) }
|
try {
|
||||||
.doOnNext { if (onlyDownloaded() != State.IGNORE) refreshChapters() }
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribeFirst(
|
|
||||||
{ view, _ ->
|
|
||||||
view.onChaptersDeleted(chapters)
|
|
||||||
},
|
|
||||||
MangaController::onChaptersDeletedError
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun downloadNewChapters(chapters: List<Chapter>) {
|
|
||||||
if (chapters.isEmpty() || !manga.shouldDownloadNewChapters(db, preferences)) return
|
|
||||||
|
|
||||||
downloadChapters(chapters)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a list of chapters from disk. This method is called in a background thread.
|
|
||||||
* @param chapters the chapters to delete.
|
|
||||||
*/
|
|
||||||
private fun deleteChaptersInternal(chapters: List<ChapterItem>) {
|
|
||||||
downloadManager.deleteChapters(chapters, manga, source).forEach {
|
downloadManager.deleteChapters(chapters, manga, source).forEach {
|
||||||
if (it is ChapterItem) {
|
if (it is ChapterItem) {
|
||||||
it.status = Download.State.NOT_DOWNLOADED
|
it.status = Download.State.NOT_DOWNLOADED
|
||||||
it.download = null
|
it.download = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onlyDownloaded() != State.IGNORE) {
|
||||||
|
refreshChapters()
|
||||||
|
}
|
||||||
|
|
||||||
|
launchUI {
|
||||||
|
view?.onChaptersDeleted(chapters)
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
view?.onChaptersDeletedError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun downloadNewChapters(chapters: List<Chapter>) {
|
||||||
|
if (chapters.isEmpty() || !manga.shouldDownloadNewChapters(db, preferences)) return
|
||||||
|
|
||||||
|
downloadChapters(chapters)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user