From f28dfa6af4909625817dd840c875d98c5e867cec Mon Sep 17 00:00:00 2001 From: Mike <51273546+SnakeDoc83@users.noreply.github.com> Date: Mon, 3 Aug 2020 00:03:33 -0400 Subject: [PATCH] MyReadingManga - refactor search (#3991) --- src/all/myreadingmanga/build.gradle | 2 +- .../all/myreadingmanga/MyReadingManga.kt | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/all/myreadingmanga/build.gradle b/src/all/myreadingmanga/build.gradle index 62d2a817f..3c2415152 100644 --- a/src/all/myreadingmanga/build.gradle +++ b/src/all/myreadingmanga/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'MyReadingManga' pkgNameSuffix = 'all.myreadingmanga' extClass = '.MyReadingMangaFactory' - extVersionCode = 37 + extVersionCode = 38 libVersion = '1.2' } diff --git a/src/all/myreadingmanga/src/eu/kanade/tachiyomi/extension/all/myreadingmanga/MyReadingManga.kt b/src/all/myreadingmanga/src/eu/kanade/tachiyomi/extension/all/myreadingmanga/MyReadingManga.kt index bcbe34c59..eaf9263eb 100644 --- a/src/all/myreadingmanga/src/eu/kanade/tachiyomi/extension/all/myreadingmanga/MyReadingManga.kt +++ b/src/all/myreadingmanga/src/eu/kanade/tachiyomi/extension/all/myreadingmanga/MyReadingManga.kt @@ -65,19 +65,19 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin // Search override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - var fqIndex = 0 + val filterList = if (filters.isEmpty()) getFilterList() else filters + // whether enforce language is true will change the index of the loop below + val indexModifier = filterList.filterIsInstance().first().indexModifier() + val uri = Uri.parse("$baseUrl/search/").buildUpon() .appendQueryParameter("wpsolr_q", query) - @Suppress("NullableBooleanElvis") - if ((filters.find { it is EnforceLanguageFilter } as? Filter.CheckBox)?.state ?: true) - uri.appendQueryParameter("wpsolr_fq[$fqIndex]", "lang_str:$siteLang") - .appendQueryParameter("wpsolr_page", page.toString()) - filters.forEach { - if (it is UriFilter) { - fqIndex++ - it.addToUri(uri, "wpsolr_fq[$fqIndex]") + filterList.forEachIndexed { i, filter -> + if (filter is UriFilter) { + filter.addToUri(uri, "wpsolr_fq[${i - indexModifier}]") } } + uri.appendQueryParameter("wpsolr_page", page.toString()) + return GET(uri.toString(), headers) } @@ -253,7 +253,7 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin // Generates the filter lists for app override fun getFilterList(): FilterList { return FilterList( - EnforceLanguageFilter(), + EnforceLanguageFilter(siteLang), GenreFilter(returnFilter(getCache(cachedPagesUrls["genres"]!!), ".tagcloud a[href*=/genre/]")), TagFilter(returnFilter(getCache(cachedPagesUrls["tags"]!!), ".tagcloud a[href*=/tag/]")), CatFilter(returnFilter(getCache(cachedPagesUrls["categories"]!!), ".links a")), @@ -262,7 +262,12 @@ open class MyReadingManga(override val lang: String, private val siteLang: Strin ) } - private class EnforceLanguageFilter : Filter.CheckBox("Enforce language", true) + private class EnforceLanguageFilter(val siteLang: String) : Filter.CheckBox("Enforce language", true), UriFilter { + fun indexModifier() = if (state) 0 else 1 + override fun addToUri(uri: Uri.Builder, uriParam: String) { + if (state) uri.appendQueryParameter(uriParam, "lang_str:$siteLang") + } + } private class GenreFilter(GENRES: Array) : UriSelectFilter("Genre", "genre_str", arrayOf("Any", *GENRES)) private class TagFilter(POPTAG: Array) : UriSelectFilter("Popular Tags", "tags", arrayOf("Any", *POPTAG))