Cleanup some delegation code
This commit is contained in:
parent
7557369d1f
commit
0d033c7080
@ -28,9 +28,7 @@ class Hitomi(delegate: HttpSource, val context: Context) :
|
|||||||
LewdSource<HitomiSearchMetadata, Document>,
|
LewdSource<HitomiSearchMetadata, Document>,
|
||||||
UrlImportableSource {
|
UrlImportableSource {
|
||||||
override val metaClass = HitomiSearchMetadata::class
|
override val metaClass = HitomiSearchMetadata::class
|
||||||
override val lang = if (delegate.lang == "other") "all" else delegate.lang
|
override val lang = if (id == otherId) "all" else delegate.lang
|
||||||
override val id: Long
|
|
||||||
get() = if (delegate.lang == "other") otherId else delegate.id
|
|
||||||
|
|
||||||
// Support direct URL importing
|
// Support direct URL importing
|
||||||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> =
|
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> =
|
||||||
@ -114,7 +112,13 @@ class Hitomi(delegate: HttpSource, val context: Context) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = "${delegate.name} (${lang.toUpperCase()})"
|
override fun toString() = "$name (${lang.toUpperCase()})"
|
||||||
|
|
||||||
|
override fun ensureDelegateCompatible() {
|
||||||
|
if (versionId != delegate.versionId) {
|
||||||
|
throw IncompatibleDelegateException("Delegate source is not compatible (versionId: $versionId <=> ${delegate.versionId})!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override val matchingHosts = listOf(
|
override val matchingHosts = listOf(
|
||||||
"hitomi.la"
|
"hitomi.la"
|
||||||
|
@ -25,14 +25,12 @@ import exh.util.urlImportFetchSearchManga
|
|||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
|
||||||
open class NHentai(delegate: HttpSource, val context: Context) :
|
class NHentai(delegate: HttpSource, val context: Context) :
|
||||||
DelegatedHttpSource(delegate),
|
DelegatedHttpSource(delegate),
|
||||||
LewdSource<NHentaiSearchMetadata, Response>,
|
LewdSource<NHentaiSearchMetadata, Response>,
|
||||||
UrlImportableSource {
|
UrlImportableSource {
|
||||||
override val metaClass = NHentaiSearchMetadata::class
|
override val metaClass = NHentaiSearchMetadata::class
|
||||||
override val lang = if (delegate.lang == "other") "all" else delegate.lang
|
override val lang = if (id == otherId) "all" else delegate.lang
|
||||||
override val id: Long
|
|
||||||
get() = if (delegate.lang == "other") otherId else delegate.id
|
|
||||||
|
|
||||||
// Support direct URL importing
|
// Support direct URL importing
|
||||||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> =
|
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> =
|
||||||
@ -100,7 +98,13 @@ open class NHentai(delegate: HttpSource, val context: Context) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = "${delegate.name} (${lang.toUpperCase()})"
|
override fun toString() = "$name (${lang.toUpperCase()})"
|
||||||
|
|
||||||
|
override fun ensureDelegateCompatible() {
|
||||||
|
if (versionId != delegate.versionId) {
|
||||||
|
throw IncompatibleDelegateException("Delegate source is not compatible (versionId: $versionId <=> ${delegate.versionId})!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override val matchingHosts = listOf(
|
override val matchingHosts = listOf(
|
||||||
"nhentai.net"
|
"nhentai.net"
|
||||||
|
@ -99,12 +99,6 @@ abstract class DelegatedHttpSource(val delegate: HttpSource) : HttpSource() {
|
|||||||
*/
|
*/
|
||||||
override val baseUrl get() = delegate.baseUrl
|
override val baseUrl get() = delegate.baseUrl
|
||||||
|
|
||||||
/**
|
|
||||||
* Version id used to generate the source id. If the site completely changes and urls are
|
|
||||||
* incompatible, you may increase this value and it'll be considered as a new source.
|
|
||||||
*/
|
|
||||||
override val versionId get() = delegate.versionId
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the source has support for latest updates.
|
* Whether the source has support for latest updates.
|
||||||
*/
|
*/
|
||||||
@ -254,8 +248,8 @@ abstract class DelegatedHttpSource(val delegate: HttpSource) : HttpSource() {
|
|||||||
*/
|
*/
|
||||||
override fun getFilterList() = delegate.getFilterList()
|
override fun getFilterList() = delegate.getFilterList()
|
||||||
|
|
||||||
private fun ensureDelegateCompatible() {
|
protected open fun ensureDelegateCompatible() {
|
||||||
if ((versionId != delegate.versionId || lang != delegate.lang) && id != delegate.id) {
|
if (versionId != delegate.versionId || lang != delegate.lang) {
|
||||||
throw IncompatibleDelegateException("Delegate source is not compatible (versionId: $versionId <=> ${delegate.versionId}, lang: $lang <=> ${delegate.lang})!")
|
throw IncompatibleDelegateException("Delegate source is not compatible (versionId: $versionId <=> ${delegate.versionId}, lang: $lang <=> ${delegate.lang})!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user