diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/Hitomi.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/Hitomi.kt index e28778b86..1ca540365 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/Hitomi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/Hitomi.kt @@ -28,9 +28,7 @@ class Hitomi(delegate: HttpSource, val context: Context) : LewdSource, 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 = @@ -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" diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt index a47b74c38..8aa43aea2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/NHentai.kt @@ -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, 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 = @@ -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" diff --git a/app/src/main/java/exh/source/DelegatedHttpSource.kt b/app/src/main/java/exh/source/DelegatedHttpSource.kt index 43818428d..b11d7bd2b 100644 --- a/app/src/main/java/exh/source/DelegatedHttpSource.kt +++ b/app/src/main/java/exh/source/DelegatedHttpSource.kt @@ -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})!") } }