Skip to content

Commit

Permalink
Allow extensions to use both custom related titles & App's related ti…
Browse files Browse the repository at this point in the history
…tles by search
  • Loading branch information
cuong-tran committed Apr 30, 2024
1 parent ef4979a commit da7f142
Showing 1 changed file with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -301,18 +315,30 @@ abstract class HttpSource : CatalogueSource {
*/
override suspend fun getRelatedMangaList(manga: SManga): List<SManga> {
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<SManga> {
return client.newCall(relatedMangaListRequest(manga))
.execute()
.let { response ->
relatedMangaListParse(response)
}
}

/**
* Fetch related mangas by searching for each keywords from manga's title
*
Expand Down

0 comments on commit da7f142

Please sign in to comment.