ColaManhua (OhManhua): add Category and Char filters (#248)

* ColaManhua (OhManhua): add Category and Char filters

* Use UriPartFilter

* Change source name

* Refactor StatusFilter
This commit is contained in:
uy/sun 2024-01-15 02:42:17 +08:00 committed by Draff
parent 4feb5e77a5
commit f5f90f7a0e
2 changed files with 107 additions and 9 deletions

View File

@ -3,10 +3,10 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization' apply plugin: 'kotlinx-serialization'
ext { ext {
extName = 'ColaManhua (OhManhua)' extName = 'COLAMANGA'
pkgNameSuffix = 'zh.onemanhua' pkgNameSuffix = 'zh.onemanhua'
extClass = '.Onemanhua' extClass = '.Onemanhua'
extVersionCode = 12 extVersionCode = 13
} }
dependencies { dependencies {

View File

@ -49,7 +49,7 @@ class Onemanhua : ConfigurableSource, ParsedHttpSource() {
override val id = 8252565807829914103 // name used to be "One漫画" override val id = 8252565807829914103 // name used to be "One漫画"
override val lang = "zh" override val lang = "zh"
override val supportsLatest = true override val supportsLatest = true
override val name = "COLA漫画 (OH漫画)" override val name = "COLAMANGA"
override val baseUrl = "https://www.colamanga.com" override val baseUrl = "https://www.colamanga.com"
// Preference setting // Preference setting
@ -122,11 +122,99 @@ class Onemanhua : ConfigurableSource, ParsedHttpSource() {
override fun latestUpdatesFromElement(element: Element) = commonMangaFromElement(element) override fun latestUpdatesFromElement(element: Element) = commonMangaFromElement(element)
// Filter // Filter
private class StatusFilter : Filter.TriState("已完结") open class UriPartFilter(displayName: String, private val vals: Array<Pair<String, String>>) :
private class SortFilter : Filter.Select<String>("排序", arrayOf("更新日", "收录日", "日点击", "月点击"), 2) Filter.Select<String>(displayName, vals.map { it.first }.toTypedArray()) {
fun toUriPart() = vals[state].second
}
private class StatusFilter : UriPartFilter(
"状态",
arrayOf(
Pair("全部", ""),
Pair("连载中", "1"),
Pair("已完结", "2"),
),
)
private class SortFilter : UriPartFilter(
"排序",
arrayOf(
Pair("更新日", "update"),
Pair("日点击", "dailyCount"),
Pair("周点击", "weeklyCount"),
Pair("月点击", "monthlyCount"),
),
)
private class CategoryFilter : UriPartFilter(
"类型",
arrayOf(
Pair("全部", ""),
Pair("热血", "10023"),
Pair("玄幻", "10024"),
Pair("恋爱", "10126"),
Pair("冒险", "10210"),
Pair("古风", "10143"),
Pair("都市", "10124"),
Pair("穿越", "10129"),
Pair("奇幻", "10242"),
Pair("其他", "10560"),
Pair("少男", "10641"),
Pair("搞笑", "10122"),
Pair("战斗", "10309"),
Pair("冒险热血", "11224"),
Pair("重生", "10461"),
Pair("爆笑", "10201"),
Pair("逆袭", "10943"),
Pair("后宫", "10138"),
Pair("少年", "10321"),
Pair("少女", "10301"),
Pair("熱血", "12044"),
Pair("系统", "10722"),
Pair("动作", "10125"),
Pair("校园", "10131"),
Pair("冒險", "12123"),
Pair("修真", "10133"),
Pair("修仙", "10453"),
Pair("剧情", "10480"),
Pair("霸总", "10127"),
Pair("大女主", "10706"),
Pair("生活", "10142"),
),
)
private class CharFilter : UriPartFilter(
"字母",
arrayOf(
Pair("全部", ""),
Pair("A", "10182"),
Pair("B", "10081"),
Pair("C", "10134"),
Pair("D", "10001"),
Pair("E", "10238"),
Pair("F", "10161"),
Pair("G", "10225"),
Pair("H", "10137"),
Pair("I", "10284"),
Pair("J", "10141"),
Pair("K", "10283"),
Pair("L", "10132"),
Pair("M", "10136"),
Pair("N", "10130"),
Pair("O", "10282"),
Pair("P", "10262"),
Pair("Q", "10164"),
Pair("R", "10240"),
Pair("S", "10121"),
Pair("T", "10123"),
Pair("U", "11184"),
Pair("V", "11483"),
Pair("W", "10135"),
Pair("X", "10061"),
Pair("Y", "10082"),
Pair("Z", "10128"),
),
)
override fun getFilterList() = FilterList( override fun getFilterList() = FilterList(
SortFilter(), SortFilter(),
CategoryFilter(),
CharFilter(),
StatusFilter(), StatusFilter(),
) )
@ -141,12 +229,22 @@ class Onemanhua : ConfigurableSource, ParsedHttpSource() {
filters.forEach { filter -> filters.forEach { filter ->
when (filter) { when (filter) {
is StatusFilter -> { is StatusFilter -> {
if (!filter.isIgnored()) { if (filter.state != 0) {
url.addQueryParameter("status", arrayOf("0", "2", "1")[filter.state]) url.addQueryParameter("status", filter.toUriPart())
} }
} }
is SortFilter -> { is SortFilter -> {
url.addQueryParameter("orderBy", arrayOf("update", "create", "dailyCount", "weeklyCount", "monthlyCount")[filter.state]) url.addQueryParameter("orderBy", filter.toUriPart())
}
is CategoryFilter -> {
if (filter.state != 0) {
url.addQueryParameter("mainCategoryId", filter.toUriPart())
}
}
is CharFilter -> {
if (filter.state != 0) {
url.addQueryParameter("charCategoryId", filter.toUriPart())
}
} }
else -> {} else -> {}
} }