From 511f6677927906ea4d6118f46520252ba55a3bd2 Mon Sep 17 00:00:00 2001 From: Ahmed gamal <12355.ahmedgamal.com@gmail.com> Date: Thu, 19 Aug 2021 11:58:14 +0200 Subject: [PATCH] Asgard Team: Add Type Filters (#8646) --- src/ar/asgardteam/build.gradle | 2 +- .../extension/ar/asgardteam/AsgardTeam.kt | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/ar/asgardteam/build.gradle b/src/ar/asgardteam/build.gradle index 08364e855..81c0e3672 100644 --- a/src/ar/asgardteam/build.gradle +++ b/src/ar/asgardteam/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Asgard Team' pkgNameSuffix = 'ar.asgardteam' extClass = '.AsgardTeam' - extVersionCode = 10 + extVersionCode = 11 libVersion = '1.2' } diff --git a/src/ar/asgardteam/src/eu/kanade/tachiyomi/extension/ar/asgardteam/AsgardTeam.kt b/src/ar/asgardteam/src/eu/kanade/tachiyomi/extension/ar/asgardteam/AsgardTeam.kt index 04ab753bb..e4a0576fe 100644 --- a/src/ar/asgardteam/src/eu/kanade/tachiyomi/extension/ar/asgardteam/AsgardTeam.kt +++ b/src/ar/asgardteam/src/eu/kanade/tachiyomi/extension/ar/asgardteam/AsgardTeam.kt @@ -1,12 +1,14 @@ package eu.kanade.tachiyomi.extension.ar.asgardteam import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import okhttp3.Headers +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document @@ -70,7 +72,17 @@ class AsgardTeam : ParsedHttpSource() { // Search override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - return GET("$baseUrl/search/?s=$query&page=$page", headers) + return if (query.isNotBlank()) { + GET("$baseUrl/search/?s=$query&page=$page", headers) + } else { + val url = "$baseUrl/manga-list/?page=$page".toHttpUrlOrNull()!!.newBuilder() + filters.forEach { filter -> + when (filter) { + is TypeFilter -> url.addQueryParameter("type", filter.toUriPart()) + } + } + GET(url.build().toString(), headers) + } } override fun searchMangaSelector() = popularMangaSelector() @@ -129,5 +141,24 @@ class AsgardTeam : ParsedHttpSource() { override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used") - override fun getFilterList() = FilterList() + // Filters (TODO: Add Genre Filters Later) + + override fun getFilterList() = FilterList( + Filter.Header("NOTE: Ignored if using text search!"), + TypeFilter(getTypeFilter()), + ) + + private class TypeFilter(vals: Array>) : UriPartFilter("Type", vals) + + open fun getTypeFilter(): Array> = arrayOf( + Pair("", "