Convert java threads to kotlin coroutines
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user