From da7f14235232e9e1d0d74d873c97f7913625c81a Mon Sep 17 00:00:00 2001 From: "Cuong M. Tran" Date: Wed, 1 May 2024 04:09:29 +0700 Subject: [PATCH] Allow extensions to use both custom related titles & App's related titles by search --- .../tachiyomi/source/online/HttpSource.kt | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt index 08c77b5860..4bc8834c27 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -288,6 +288,20 @@ abstract class HttpSource : CatalogueSource { * @since komikku/extensions-lib 1.6 */ protected open val supportsRelatedMangas: Boolean get() = false + + /** + * Extensions provide custom [relatedMangaListRequest] and [relatedMangaListParse] + * while also want to use App's [getRelatedMangaListBySearch] together. + * @default false + * @since komikku/extensions-lib 1.6 + */ + protected open val supportsRelatedMangasAndSearch: Boolean get() = false + + /** + * Disable showing any related titles + * @default false + * @since komikku/extensions-lib 1.6 + */ protected open val disableRelatedMangas: Boolean get() = false /** @@ -301,18 +315,30 @@ abstract class HttpSource : CatalogueSource { */ override suspend fun getRelatedMangaList(manga: SManga): List { return when { - supportsRelatedMangas -> { - client.newCall(relatedMangaListRequest(manga)) - .execute() - .let { response -> - relatedMangaListParse(response) - } - } + supportsRelatedMangasAndSearch -> fetchRelatedMangaList(manga) + getRelatedMangaListBySearch(manga) + supportsRelatedMangas -> fetchRelatedMangaList(manga) disableRelatedMangas -> emptyList() else -> getRelatedMangaListBySearch(manga) } } + /** + * Fetch related mangas for a manga from source/site. + * Normally it's not needed to override this method. + * + * @since komikku/extensions-lib 1.6 + * @param manga the current manga to get related mangas. + * @return the related mangas for the current manga. + * @throws UnsupportedOperationException if a source doesn't support related mangas. + */ + protected open suspend fun fetchRelatedMangaList(manga: SManga): List { + return client.newCall(relatedMangaListRequest(manga)) + .execute() + .let { response -> + relatedMangaListParse(response) + } + } + /** * Fetch related mangas by searching for each keywords from manga's title *