Anchira: Add trending filter (#1522)
Anchira: Add trending filters Signed-off-by: Rama Bondan Prakoso <ramanarubp@gmail.com>
This commit is contained in:
parent
48ca6558ed
commit
420c7d9cd5
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'Anchira'
|
extName = 'Anchira'
|
||||||
extClass = '.Anchira'
|
extClass = '.Anchira'
|
||||||
extVersionCode = 8
|
extVersionCode = 9
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,10 +117,26 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||||
|
val filterList = if (filters.isEmpty()) getFilterList() else filters
|
||||||
|
val trendingFilter = filterList.findInstance<TrendingFilter>()
|
||||||
|
val sortTrendingFilter = filters.findInstance<SortTrendingFilter>()
|
||||||
var url = libraryUrl.toHttpUrl().newBuilder()
|
var url = libraryUrl.toHttpUrl().newBuilder()
|
||||||
|
|
||||||
url.addQueryParameter("page", page.toString())
|
url.addQueryParameter("page", page.toString())
|
||||||
|
|
||||||
|
if (trendingFilter?.state == true) {
|
||||||
|
val interval = when (sortTrendingFilter?.state) {
|
||||||
|
1 -> "3"
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interval.isNotBlank()) url.addQueryParameter("interval", interval)
|
||||||
|
|
||||||
|
url = url.toString().replace("library", "trending").toHttpUrl()
|
||||||
|
.newBuilder()
|
||||||
|
|
||||||
|
return GET(url.build(), headers)
|
||||||
|
} else {
|
||||||
if (query.isNotBlank()) {
|
if (query.isNotBlank()) {
|
||||||
url.addQueryParameter("s", query)
|
url.addQueryParameter("s", query)
|
||||||
}
|
}
|
||||||
|
@ -171,6 +187,7 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
|
|
||||||
return GET(url.build(), headers)
|
return GET(url.build(), headers)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun searchMangaParse(response: Response) = latestUpdatesParse(response)
|
override fun searchMangaParse(response: Response) = latestUpdatesParse(response)
|
||||||
|
|
||||||
|
@ -298,6 +315,10 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
CategoryGroup(),
|
CategoryGroup(),
|
||||||
SortFilter(),
|
SortFilter(),
|
||||||
FavoritesFilter(),
|
FavoritesFilter(),
|
||||||
|
Filter.Separator(),
|
||||||
|
Filter.Header("Others are ignored if trending only"),
|
||||||
|
TrendingFilter(),
|
||||||
|
SortTrendingFilter(),
|
||||||
)
|
)
|
||||||
|
|
||||||
private class CategoryFilter(name: String) : Filter.CheckBox(name, false)
|
private class CategoryFilter(name: String) : Filter.CheckBox(name, false)
|
||||||
|
@ -317,6 +338,18 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
Selection(2, false),
|
Selection(2, false),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private class TrendingFilter : Filter.CheckBox(
|
||||||
|
"Show only trending",
|
||||||
|
)
|
||||||
|
|
||||||
|
private class SortTrendingFilter : PartFilter(
|
||||||
|
"Sort By",
|
||||||
|
arrayOf("Trending: Weekly", "Trending: Monthly"),
|
||||||
|
)
|
||||||
|
|
||||||
|
private open class PartFilter(displayName: String, value: Array<String>) :
|
||||||
|
Filter.Select<String>(displayName, value)
|
||||||
|
|
||||||
private val SharedPreferences.imageQuality
|
private val SharedPreferences.imageQuality
|
||||||
get() = getString(IMAGE_QUALITY_PREF, "b")!!
|
get() = getString(IMAGE_QUALITY_PREF, "b")!!
|
||||||
|
|
||||||
|
@ -362,6 +395,8 @@ class Anchira : HttpSource(), ConfigurableSource {
|
||||||
.use { json.decodeFromStream<List<EntryKey>>(it.body.byteStream()) }
|
.use { json.decodeFromStream<List<EntryKey>>(it.body.byteStream()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inline fun <reified T> Iterable<*>.findInstance() = find { it is T } as? T
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SLUG_SEARCH_PREFIX = "id:"
|
const val SLUG_SEARCH_PREFIX = "id:"
|
||||||
private const val IMAGE_QUALITY_PREF = "image_quality"
|
private const val IMAGE_QUALITY_PREF = "image_quality"
|
||||||
|
|
Loading…
Reference in New Issue