From 381c1fb8f2742708d6cf2b4ae17090644adf1147 Mon Sep 17 00:00:00 2001 From: Carlos Date: Sat, 29 Sep 2018 10:30:35 -0400 Subject: [PATCH] mangadex add sorting (#524) --- src/all/mangadex/build.gradle | 4 +-- .../extension/all/mangadex/Mangadex.kt | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index 86898a5b2..ce289c5c5 100644 --- a/src/all/mangadex/build.gradle +++ b/src/all/mangadex/build.gradle @@ -5,8 +5,8 @@ ext { appName = 'Tachiyomi: MangaDex' pkgNameSuffix = 'all.mangadex' extClass = '.MangadexFactory' - extVersionCode = 39 - extVersionSuffix = 39 + extVersionCode = 40 + extVersionSuffix = 40 libVersion = '1.2' } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt index 769df1342..ef18c0132 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt @@ -151,7 +151,6 @@ open class Mangadex(override val lang: String, private val internalLang: String, // Do traditional search val url = HttpUrl.parse("$baseUrl/?page=search")!!.newBuilder() - .addQueryParameter("s", "0") .addQueryParameter("p", page.toString()) .addQueryParameter("title", query.replace(WHITESPACE_REGEX, " ")) @@ -178,6 +177,15 @@ open class Mangadex(override val lang: String, private val internalLang: String, } } } + is SortFilter -> { + if (filter.state != null) { + if (filter.state!!.ascending) { + url.addQueryParameter("s", sortables[filter.state!!.index].second.toString()) + } else { + url.addQueryParameter("s", sortables[filter.state!!.index].third.toString()) + } + } + } } } @@ -417,12 +425,18 @@ open class Mangadex(override val lang: String, private val internalLang: String, private class GenreList(genres: List) : Filter.Group("Genres", genres) private class R18 : Filter.Select("R18+", arrayOf("Default", "Show all", "Show only", "Show none")) private class Demographic : Filter.Select("Demographic", arrayOf("All", "Shounen", "Shoujo", "Seinen", "Josei")) + + class SortFilter : Filter.Sort("Sort", + sortables.map { it.first }.toTypedArray(), + Filter.Sort.Selection(0, true)) + private class OriginalLanguage : Filter.Select("Original Language", SOURCE_LANG_LIST.map { it -> it.first }.toTypedArray()) override fun getFilterList() = FilterList( TextField("Author", "author"), TextField("Artist", "artist"), R18(), + SortFilter(), Demographic(), OriginalLanguage(), GenreList(getGenreList()) @@ -471,6 +485,7 @@ open class Mangadex(override val lang: String, private val internalLang: String, Genre("40", "Game"), Genre("41", "Isekai")) + companion object { private val WHITESPACE_REGEX = "\\s".toRegex() @@ -485,6 +500,14 @@ open class Mangadex(override val lang: String, private val internalLang: String, private const val API_MANGA = "/api/manga/" private const val API_CHAPTER = "/api/chapter/" + private val sortables = listOf( + Triple("Update date", 0, 1), + Triple("Alphabetically", 2, 3), + Triple("Number of comments", 4, 5), + Triple("Rating", 6, 7), + Triple("Views", 8, 9), + Triple("Follows", 10, 11)) + private val SOURCE_LANG_LIST = listOf( Pair("All", "0"), Pair("Japanese", "2"),