Convert java threads to kotlin coroutines

This commit is contained in:
Jobobby04
2020-10-29 15:29:43 -04:00
parent 46998d81f4
commit 3b5249c8bc
10 changed files with 117 additions and 77 deletions
+17 -11
View File
@@ -5,6 +5,7 @@ import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.online.UrlImportableSource
import exh.GalleryAddEvent
import exh.GalleryAdder
import kotlinx.coroutines.flow.flow
import rx.Observable
private val galleryAdder by lazy {
@@ -17,19 +18,24 @@ private val galleryAdder by lazy {
fun UrlImportableSource.urlImportFetchSearchManga(context: Context, query: String, fail: () -> Observable<MangasPage>): Observable<MangasPage> =
when {
query.startsWith("http://") || query.startsWith("https://") -> {
Observable.fromCallable {
val res = galleryAdder.addGallery(context, query, false, this)
MangasPage(
(
if (res is GalleryAddEvent.Success) {
listOf(res.manga)
} else {
emptyList()
}
),
false
flow {
emit(
galleryAdder.addGallery(context, query, false, this@urlImportFetchSearchManga)
)
}
.asObservable()
.map { res ->
MangasPage(
(
if (res is GalleryAddEvent.Success) {
listOf(res.manga)
} else {
emptyList()
}
),
false
)
}
}
else -> fail()
}