Skip to content

Commit da7f142

Browse files
committed
Allow extensions to use both custom related titles & App's related titles by search
1 parent ef4979a commit da7f142

File tree

1 file changed

+33
-7
lines changed
  • source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online

1 file changed

+33
-7
lines changed

source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt

+33-7
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,20 @@ abstract class HttpSource : CatalogueSource {
288288
* @since komikku/extensions-lib 1.6
289289
*/
290290
protected open val supportsRelatedMangas: Boolean get() = false
291+
292+
/**
293+
* Extensions provide custom [relatedMangaListRequest] and [relatedMangaListParse]
294+
* while also want to use App's [getRelatedMangaListBySearch] together.
295+
* @default false
296+
* @since komikku/extensions-lib 1.6
297+
*/
298+
protected open val supportsRelatedMangasAndSearch: Boolean get() = false
299+
300+
/**
301+
* Disable showing any related titles
302+
* @default false
303+
* @since komikku/extensions-lib 1.6
304+
*/
291305
protected open val disableRelatedMangas: Boolean get() = false
292306

293307
/**
@@ -301,18 +315,30 @@ abstract class HttpSource : CatalogueSource {
301315
*/
302316
override suspend fun getRelatedMangaList(manga: SManga): List<SManga> {
303317
return when {
304-
supportsRelatedMangas -> {
305-
client.newCall(relatedMangaListRequest(manga))
306-
.execute()
307-
.let { response ->
308-
relatedMangaListParse(response)
309-
}
310-
}
318+
supportsRelatedMangasAndSearch -> fetchRelatedMangaList(manga) + getRelatedMangaListBySearch(manga)
319+
supportsRelatedMangas -> fetchRelatedMangaList(manga)
311320
disableRelatedMangas -> emptyList()
312321
else -> getRelatedMangaListBySearch(manga)
313322
}
314323
}
315324

325+
/**
326+
* Fetch related mangas for a manga from source/site.
327+
* Normally it's not needed to override this method.
328+
*
329+
* @since komikku/extensions-lib 1.6
330+
* @param manga the current manga to get related mangas.
331+
* @return the related mangas for the current manga.
332+
* @throws UnsupportedOperationException if a source doesn't support related mangas.
333+
*/
334+
protected open suspend fun fetchRelatedMangaList(manga: SManga): List<SManga> {
335+
return client.newCall(relatedMangaListRequest(manga))
336+
.execute()
337+
.let { response ->
338+
relatedMangaListParse(response)
339+
}
340+
}
341+
316342
/**
317343
* Fetch related mangas by searching for each keywords from manga's title
318344
*

0 commit comments

Comments
 (0)