From 311cef70fdae172bb8d90c122e180f4e383ebb95 Mon Sep 17 00:00:00 2001 From: Mike <51273546+SnakeDoc83@users.noreply.github.com> Date: Tue, 2 Jun 2020 04:47:59 -0400 Subject: [PATCH] Mangahere - fix genre search (#3380) --- src/en/mangahere/build.gradle | 2 +- .../extension/en/mangahere/Mangahere.kt | 64 +++++++++---------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/en/mangahere/build.gradle b/src/en/mangahere/build.gradle index 9bab93099..2aeb5c81f 100644 --- a/src/en/mangahere/build.gradle +++ b/src/en/mangahere/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Mangahere' pkgNameSuffix = 'en.mangahere' extClass = '.Mangahere' - extVersionCode = 14 + extVersionCode = 15 libVersion = '1.2' } diff --git a/src/en/mangahere/src/eu/kanade/tachiyomi/extension/en/mangahere/Mangahere.kt b/src/en/mangahere/src/eu/kanade/tachiyomi/extension/en/mangahere/Mangahere.kt index bcd81e4dc..94207f01d 100644 --- a/src/en/mangahere/src/eu/kanade/tachiyomi/extension/en/mangahere/Mangahere.kt +++ b/src/en/mangahere/src/eu/kanade/tachiyomi/extension/en/mangahere/Mangahere.kt @@ -83,44 +83,40 @@ class Mangahere : ParsedHttpSource() { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = HttpUrl.parse("$baseUrl/search")!!.newBuilder() - filters.forEach { - when (it) { - - is TypeList -> { - url.addEncodedQueryParameter("type", types[it.values[it.state]].toString()) - } - is CompletionList -> url.addEncodedQueryParameter("st", it.state.toString()) + filters.forEach { filter -> + when (filter) { + is TypeList -> url.addEncodedQueryParameter("type", types[filter.values[filter.state]].toString()) + is CompletionList -> url.addEncodedQueryParameter("st", filter.state.toString()) is GenreList -> { - - val genreFilter = filters.find { filter -> filter is GenreList } as GenreList? - val includeGenres = ArrayList() - val excludeGenres = ArrayList() - genreFilter?.state?.forEach { genre -> - if (genre.isIncluded()) - includeGenres.add(genre.id) - else if (genre.isExcluded()) - excludeGenres.add(genre.id) + val includeGenres = mutableSetOf() + val excludeGenres = mutableSetOf() + filter.state.forEach { genre -> + if (genre.isIncluded()) includeGenres.add(genre.id) + if (genre.isExcluded()) excludeGenres.add(genre.id) + } + url.apply { + addEncodedQueryParameter("genres", includeGenres.joinToString(",")) + addEncodedQueryParameter("nogenres", excludeGenres.joinToString(",")) } - - url.addEncodedQueryParameter("genres", includeGenres.joinToString(",")) - .addEncodedQueryParameter("nogenres", excludeGenres.joinToString(",")) } } } - url.addEncodedQueryParameter("page", page.toString()) - .addEncodedQueryParameter("title", query) - .addEncodedQueryParameter("sort", null) - .addEncodedQueryParameter("stype", 1.toString()) - .addEncodedQueryParameter("name", null) - .addEncodedQueryParameter("author_method", "cw") - .addEncodedQueryParameter("author", null) - .addEncodedQueryParameter("artist_method", "cw") - .addEncodedQueryParameter("artist", null) - .addEncodedQueryParameter("rating_method", "eq") - .addEncodedQueryParameter("rating", null) - .addEncodedQueryParameter("released_method", "eq") - .addEncodedQueryParameter("released", null) + url.apply { + addEncodedQueryParameter("page", page.toString()) + addEncodedQueryParameter("title", query) + addEncodedQueryParameter("sort", null) + addEncodedQueryParameter("stype", 1.toString()) + addEncodedQueryParameter("name", null) + addEncodedQueryParameter("author_method", "cw") + addEncodedQueryParameter("author", null) + addEncodedQueryParameter("artist_method", "cw") + addEncodedQueryParameter("artist", null) + addEncodedQueryParameter("rating_method", "eq") + addEncodedQueryParameter("rating", null) + addEncodedQueryParameter("released_method", "eq") + addEncodedQueryParameter("released", null) + } return GET(url.toString(), headers) } @@ -318,7 +314,7 @@ class Mangahere : ParsedHttpSource() { override fun getFilterList() = FilterList( TypeList(types.keys.toList().sorted().toTypedArray()), CompletionList(completions), - GenreList(genres) + GenreList(genres()) ) private val types = hashMapOf( @@ -330,7 +326,7 @@ class Mangahere : ParsedHttpSource() { private val completions = arrayOf("Either", "No", "Yes") - private val genres = arrayListOf( + private fun genres() = arrayListOf( Genre("Action", 1), Genre("Adventure", 2), Genre("Comedy", 3),