2017-08-25 00:31:08 +02:00
|
|
|
package exh.util
|
|
|
|
|
|
|
|
|
|
import eu.kanade.tachiyomi.source.model.MangasPage
|
2019-08-07 16:21:18 +02:00
|
|
|
import eu.kanade.tachiyomi.source.online.UrlImportableSource
|
2017-08-25 00:31:08 +02:00
|
|
|
import exh.GalleryAddEvent
|
|
|
|
|
import exh.GalleryAdder
|
|
|
|
|
import rx.Observable
|
|
|
|
|
|
|
|
|
|
private val galleryAdder by lazy {
|
|
|
|
|
GalleryAdder()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A version of fetchSearchManga that supports URL importing
|
|
|
|
|
*/
|
2019-08-07 16:21:18 +02:00
|
|
|
fun UrlImportableSource.urlImportFetchSearchManga(query: String, fail: () -> Observable<MangasPage>) =
|
2017-08-25 00:31:08 +02:00
|
|
|
when {
|
|
|
|
|
query.startsWith("http://") || query.startsWith("https://") -> {
|
|
|
|
|
Observable.fromCallable {
|
2019-08-07 16:21:18 +02:00
|
|
|
val res = galleryAdder.addGallery(query, false, this)
|
2020-04-04 22:30:05 +02:00
|
|
|
MangasPage((if (res is GalleryAddEvent.Success)
|
2017-08-25 00:31:08 +02:00
|
|
|
listOf(res.manga)
|
|
|
|
|
else
|
|
|
|
|
emptyList()), false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else -> fail()
|
|
|
|
|
}
|