mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 18:11:50 +01:00
Refactor bridged RxJava/coroutine calls in SearchPresenters
This commit is contained in:
parent
ac9bf1f3ff
commit
5cfda1b1bf
@ -15,10 +15,8 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchCardItem
|
||||
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchItem
|
||||
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
||||
import rx.Observable
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import java.util.Date
|
||||
|
||||
class SearchPresenter(
|
||||
@ -57,19 +55,14 @@ class SearchPresenter(
|
||||
|
||||
replacingMangaRelay.call(true)
|
||||
|
||||
Observable.defer {
|
||||
runAsObservable({
|
||||
source.getChapterList(manga.toMangaInfo())
|
||||
launchIO {
|
||||
val chapters = source.getChapterList(manga.toMangaInfo())
|
||||
.map { it.toSChapter() }
|
||||
})
|
||||
|
||||
migrateMangaInternal(source, chapters, prevManga, manga, replace)
|
||||
}.invokeOnCompletion {
|
||||
launchUI { replacingMangaRelay.call(false) }
|
||||
}
|
||||
.onErrorReturn { emptyList() }
|
||||
.doOnNext { migrateMangaInternal(source, it, prevManga, manga, replace) }
|
||||
.onErrorReturn { emptyList() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnUnsubscribe { replacingMangaRelay.call(false) }
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
private fun migrateMangaInternal(
|
||||
|
@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
|
||||
import eu.kanade.tachiyomi.util.lang.await
|
||||
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
@ -225,9 +226,10 @@ open class GlobalSearchPresenter(
|
||||
fetchImageSubscription?.unsubscribe()
|
||||
fetchImageSubscription = fetchImageSubject.observeOn(Schedulers.io())
|
||||
.flatMap { (first, source) ->
|
||||
Observable.from(first).filter { it.thumbnail_url == null && !it.initialized }
|
||||
Observable.from(first)
|
||||
.filter { it.thumbnail_url == null && !it.initialized }
|
||||
.map { Pair(it, source) }
|
||||
.concatMap { getMangaDetailsObservable(it.first, it.second) }
|
||||
.concatMap { runAsObservable({ getMangaDetails(it.first, it.second) }) }
|
||||
.map { Pair(source as CatalogueSource, it) }
|
||||
}
|
||||
.onBackpressureBuffer()
|
||||
@ -244,20 +246,17 @@ open class GlobalSearchPresenter(
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an observable of manga that initializes the given manga.
|
||||
* Initializes the given manga.
|
||||
*
|
||||
* @param manga the manga to initialize.
|
||||
* @return an observable of the manga to initialize
|
||||
* @return The initialized manga.
|
||||
*/
|
||||
private fun getMangaDetailsObservable(manga: Manga, source: Source): Observable<Manga> {
|
||||
return runAsObservable({
|
||||
private suspend fun getMangaDetails(manga: Manga, source: Source): Manga {
|
||||
val networkManga = source.getMangaDetails(manga.toMangaInfo())
|
||||
manga.copyFrom(networkManga.toSManga())
|
||||
manga.initialized = true
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
manga
|
||||
})
|
||||
.onErrorResumeNext { Observable.just(manga) }
|
||||
db.insertManga(manga).await()
|
||||
return manga
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user