MangaLink: Add Filters (#8673)

This commit is contained in:
Ahmed gamal 2021-08-20 16:41:38 +02:00 committed by GitHub
parent a7dc6f3ba4
commit d09c4a0abb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 3 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'MangaLink'
pkgNameSuffix = 'ar.mangalink'
extClass = '.MangaLink'
extVersionCode = 2
extVersionCode = 3
libVersion = '1.2'
}

View File

@ -1,11 +1,13 @@
package eu.kanade.tachiyomi.extension.ar.mangalink
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.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import org.jsoup.nodes.Document
@ -58,7 +60,17 @@ class MangaLink : ParsedHttpSource() {
// Search
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
return GET("$baseUrl/mangas?page=$page&query=$query", headers)
val url = "$baseUrl/mangas?page=$page&query=$query".toHttpUrlOrNull()!!.newBuilder()
filters.forEach { filter ->
when (filter) {
is TypeFilter -> {
filter.state
.filter { it.state != Filter.TriState.STATE_IGNORE }
.forEach { url.addQueryParameter("story[]", it.id) }
}
}
}
return GET(url.build().toString(), headers)
}
override fun searchMangaSelector() = popularMangaSelector()
@ -101,5 +113,25 @@ class MangaLink : ParsedHttpSource() {
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")
override fun getFilterList() = FilterList()
// Filters
override fun getFilterList() = FilterList(
Filter.Header("Type exclusion not available for this source"),
Filter.Separator(),
TypeFilter(getTypeList()),
)
class Type(name: String, val id: String = name) : Filter.TriState(name)
class TypeFilter(types: List<Type>) : Filter.Group<Type>("Type", types)
open fun getTypeList(): List<Type> = listOf(
Type("<--->", ""),
Type("مانجا(يابانية)", "1"),
Type("مانهوا(كورية)", "2"),
Type("مانها(صينية)", "3"),
Type("ويب تون", "4"),
Type("كوميك", "5"),
Type("غير معروف", "6"),
)
}