diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 3b9384094..4c76da443 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -209,11 +209,6 @@ class MangaScreenModel( private val filteredChapters: List? get() = successState?.processedChapters - // KMK --> - private val relatedMangas: List - get() = successState?.relatedMangas ?: emptyList() - // KMK <-- - val chapterSwipeStartAction = libraryPreferences.swipeToEndAction().get() val chapterSwipeEndAction = libraryPreferences.swipeToStartAction().get() @@ -1107,14 +1102,16 @@ class MangaScreenModel( try { withIOContext { if (state.source !is MergedSource) { - val relatedMangas = if (Injekt.get().relatedMangas().get()) + val relatedMangas = if (Injekt.get().relatedMangas().get()) { withIOContext { state.source.getRelatedMangaList(state.manga.toSManga()) .map { networkToLocalManga.await(it.toDomainManga(state.source.id)) } } - else null + } else { + null + } updateSuccessState { it.copy(relatedMangas = relatedMangas) } } else { throw UnsupportedOperationException("Fetching related titles for merged entry is not supported") diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt index a0b454b7f..fc6a31ded 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt @@ -52,14 +52,12 @@ interface Source { /** * Get all the available related mangas for a manga. * - * @since extensions-lib 1.6 + * @since komikku/extensions-lib 1.6 * @param manga the current manga to get related mangas. * @return the related mangas for the current manga. */ - @Suppress("DEPRECATION") - suspend fun getRelatedMangaList(manga: SManga): List { - return fetchRelatedMangaList(manga).awaitSingle() - } + suspend fun getRelatedMangaList(manga: SManga): List = + throw IllegalStateException("Not used") // KMK <-- /** @@ -89,22 +87,6 @@ interface Source { fun fetchChapterList(manga: SManga): Observable> = throw IllegalStateException("Not used") - // KMK --> - /** - * Get all the available related mangas for a manga. - * - * @since extensions-lib 1.6 - * @param manga the current manga to get related mangas. - * @return the related mangas for the current manga. - */ - @Deprecated( - "Use the non-RxJava API instead", - ReplaceWith("getRelatedMangaList"), - ) - fun fetchRelatedMangaList(manga: SManga): Observable> = - throw IllegalStateException("Not used") - // KMK <-- - @Deprecated( "Use the non-RxJava API instead", ReplaceWith("getPageList"), 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 7f209bdc3..3412ce50c 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 @@ -286,7 +286,7 @@ abstract class HttpSource : CatalogueSource { * Whether parsing related mangas in manga page or extension provide custom related mangas request (true) * or using search keyword to search for related mangas (false - default) * @default false - * @since extensions-lib 1.6 + * @since komikku/extensions-lib 1.6 */ protected open val supportsRelatedMangas: Boolean get() = false protected open val disableRelatedMangas: Boolean get() = false @@ -295,23 +295,31 @@ abstract class HttpSource : CatalogueSource { * Get all the available related mangas for a manga. * 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. */ - @Suppress("DEPRECATION") override suspend fun getRelatedMangaList(manga: SManga): List { return when { - supportsRelatedMangas -> fetchRelatedMangaList(manga).awaitSingle() + supportsRelatedMangas -> { + client.newCall(relatedMangaListRequest(manga)) + .execute() + .let { response -> + relatedMangaListParse(response) + } + } disableRelatedMangas -> emptyList() - else -> fetchRelatedMangaListBySearch(manga) + else -> getRelatedMangaListBySearch(manga) } } /** * Fetch related mangas by searching for each keywords from manga's title + * + * @since komikku/extensions-lib 1.6 */ - protected open suspend fun fetchRelatedMangaListBySearch(manga: SManga): List { + protected open suspend fun getRelatedMangaListBySearch(manga: SManga): List { fun String.stripKeyword(): List { val regexWhitespace = Regex("\\s+") val regexSpecialCharacters = Regex("[\\[(!~@#$%^&*|,?:\"<>)\\]]") @@ -338,19 +346,16 @@ abstract class HttpSource : CatalogueSource { } return words.map { keyword -> + // Make multiple search in parallel scope.async { try { - client.newCall(searchMangaRequest(0, keyword, FilterList())) - .execute() - .let { response -> - searchMangaParse(response).mangas - .filter { - it.url != manga.url && - it.title.lowercase().contains(keyword) - } + getSearchManga(0, keyword, FilterList()) + .mangas.filter { + it.url != manga.url && + it.title.lowercase().contains(keyword) } } catch (e: Exception) { - logcat(LogPriority.ERROR, e) { "Related titles: $e" } + logcat(LogPriority.ERROR, e) { "getRelatedMangaListBySearch: $e" } emptyList() } } @@ -358,24 +363,12 @@ abstract class HttpSource : CatalogueSource { .minBy { if (it.isEmpty()) Int.MAX_VALUE else it.size } } - /** - * Fetch related mangas found in manga's page which is provided by sites. - * If using this, must also: 'override val supportsRelatedMangas = true' - */ - @Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getRelatedMangaList")) - override fun fetchRelatedMangaList(manga: SManga): Observable> { - return client.newCall(relatedMangaListRequest(manga)) - .asObservableSuccess() - .map { response -> - relatedMangaListParse(response) - } - } - /** * Returns the request for get related manga list. Override only if it's needed to override * the url, send different headers or request method like POST. * If using this, must also: 'override val supportsRelatedMangas = true' * + * @since komikku/extensions-lib 1.6 * @param manga the manga to look for related mangas. */ protected open fun relatedMangaListRequest(manga: SManga): Request { @@ -386,6 +379,7 @@ abstract class HttpSource : CatalogueSource { * Parses the response from the site and returns a list of related mangas. * If using this, must also: 'override val supportsRelatedMangas = true' * + * @since komikku/extensions-lib 1.6 * @param response the response from the site. */ protected open fun relatedMangaListParse(response: Response): List = popularMangaParse(response).mangas diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt index b87e60f58..19e624d3b 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt @@ -150,6 +150,7 @@ abstract class ParsedHttpSource : HttpSource() { * Parses the response from the site and returns a list of related mangas. * If using this, must also: 'override val supportsRelatedMangas = true' * + * @since komikku/extensions-lib 1.6 * @param response the response from the site. */ override fun relatedMangaListParse(response: Response): List { @@ -160,6 +161,8 @@ abstract class ParsedHttpSource : HttpSource() { /** * Returns the Jsoup selector that returns a list of [Element] corresponding to each related mangas. * If using this, must also: 'override val supportsRelatedMangas = true' + * + * @since komikku/extensions-lib 1.6 */ protected open fun relatedMangaListSelector(): String = popularMangaSelector() @@ -167,6 +170,7 @@ abstract class ParsedHttpSource : HttpSource() { * Returns a manga from the given element. * If using this, must also: 'override val supportsRelatedMangas = true' * + * @since komikku/extensions-lib 1.6 * @param element an element obtained from [relatedMangaListSelector]. */ protected open fun relatedMangaFromElement(element: Element): SManga = popularMangaFromElement(element)