Cleanup some delegation code

This commit is contained in:
Jobobby04 2020-08-12 18:46:05 -04:00
parent 7557369d1f
commit 0d033c7080
3 changed files with 19 additions and 17 deletions

View File

@ -28,9 +28,7 @@ class Hitomi(delegate: HttpSource, val context: Context) :
LewdSource<HitomiSearchMetadata, Document>,
UrlImportableSource {
override val metaClass = HitomiSearchMetadata::class
override val lang = if (delegate.lang == "other") "all" else delegate.lang
override val id: Long
get() = if (delegate.lang == "other") otherId else delegate.id
override val lang = if (id == otherId) "all" else delegate.lang
// Support direct URL importing
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(
"hitomi.la"

View File

@ -25,14 +25,12 @@ import exh.util.urlImportFetchSearchManga
import okhttp3.Response
import rx.Observable
open class NHentai(delegate: HttpSource, val context: Context) :
class NHentai(delegate: HttpSource, val context: Context) :
DelegatedHttpSource(delegate),
LewdSource<NHentaiSearchMetadata, Response>,
UrlImportableSource {
override val metaClass = NHentaiSearchMetadata::class
override val lang = if (delegate.lang == "other") "all" else delegate.lang
override val id: Long
get() = if (delegate.lang == "other") otherId else delegate.id
override val lang = if (id == otherId) "all" else delegate.lang
// Support direct URL importing
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(
"nhentai.net"

View File

@ -99,12 +99,6 @@ abstract class DelegatedHttpSource(val delegate: HttpSource) : HttpSource() {
*/
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.
*/
@ -254,8 +248,8 @@ abstract class DelegatedHttpSource(val delegate: HttpSource) : HttpSource() {
*/
override fun getFilterList() = delegate.getFilterList()
private fun ensureDelegateCompatible() {
if ((versionId != delegate.versionId || lang != delegate.lang) && id != delegate.id) {
protected open fun ensureDelegateCompatible() {
if (versionId != delegate.versionId || lang != delegate.lang) {
throw IncompatibleDelegateException("Delegate source is not compatible (versionId: $versionId <=> ${delegate.versionId}, lang: $lang <=> ${delegate.lang})!")
}
}