AnimeFenix improvements
This commit is contained in:
parent
7303068181
commit
d866966185
3 changed files with 165 additions and 135 deletions
|
@ -1,7 +1,7 @@
|
|||
ext {
|
||||
extName = 'Animefenix'
|
||||
extClass = '.Animefenix'
|
||||
extVersionCode = 39
|
||||
extVersionCode = 40
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
package eu.kanade.tachiyomi.animeextension.es.animefenix
|
||||
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||
import java.util.Calendar
|
||||
|
||||
object AnimeFenixFilters {
|
||||
open class QueryPartFilter(displayName: String, val vals: Array<Pair<String, String>>) : AnimeFilter.Select<String>(
|
||||
displayName,
|
||||
vals.map { it.first }.toTypedArray(),
|
||||
) {
|
||||
fun toQueryPart(name: String) = vals[state].second.takeIf { it.isNotEmpty() }?.let { "&$name=${vals[state].second}" } ?: run { "" }
|
||||
}
|
||||
|
||||
open class CheckBoxFilterList(name: String, values: List<CheckBox>) : AnimeFilter.Group<AnimeFilter.CheckBox>(name, values)
|
||||
|
||||
private class CheckBoxVal(name: String, state: Boolean = false) : AnimeFilter.CheckBox(name, state)
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.parseCheckbox(
|
||||
options: Array<Pair<String, String>>,
|
||||
name: String,
|
||||
): String {
|
||||
return (this.getFirst<R>() as CheckBoxFilterList).state
|
||||
.mapNotNull { checkbox ->
|
||||
if (checkbox.state) {
|
||||
options.find { it.first == checkbox.name }!!.second
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}.joinToString("&$name[]=").let {
|
||||
if (it.isBlank()) {
|
||||
""
|
||||
} else {
|
||||
"&$name[]=$it"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.asQueryPart(name: String): String {
|
||||
return (this.getFirst<R>() as QueryPartFilter).toQueryPart(name)
|
||||
}
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.getFirst(): R {
|
||||
return this.filterIsInstance<R>().first()
|
||||
}
|
||||
|
||||
private fun String.changePrefix() = this.takeIf { it.startsWith("&") }?.let { this.replaceFirst("&", "?") } ?: run { this }
|
||||
|
||||
data class FilterSearchParams(val filter: String = "") { fun getQuery() = filter.changePrefix() }
|
||||
|
||||
internal fun getSearchParameters(filters: AnimeFilterList): FilterSearchParams {
|
||||
if (filters.isEmpty()) return FilterSearchParams()
|
||||
return FilterSearchParams(
|
||||
filters.parseCheckbox<GenresFilter>(AnimeFenixFiltersData.GENRES, "genero") +
|
||||
filters.parseCheckbox<YearsFilter>(AnimeFenixFiltersData.YEARS, "year") +
|
||||
filters.parseCheckbox<TypesFilter>(AnimeFenixFiltersData.TYPES, "type") +
|
||||
filters.parseCheckbox<StateFilter>(AnimeFenixFiltersData.STATE, "estado") +
|
||||
filters.asQueryPart<SortFilter>("order"),
|
||||
)
|
||||
}
|
||||
|
||||
val FILTER_LIST get() = AnimeFilterList(
|
||||
AnimeFilter.Header("La busqueda por texto ignora el filtro"),
|
||||
GenresFilter(),
|
||||
YearsFilter(),
|
||||
TypesFilter(),
|
||||
StateFilter(),
|
||||
SortFilter(),
|
||||
)
|
||||
|
||||
class GenresFilter : CheckBoxFilterList("Género", AnimeFenixFiltersData.GENRES.map { CheckBoxVal(it.first, false) })
|
||||
|
||||
class YearsFilter : CheckBoxFilterList("Año", AnimeFenixFiltersData.YEARS.map { CheckBoxVal(it.first, false) })
|
||||
|
||||
class TypesFilter : CheckBoxFilterList("Tipo", AnimeFenixFiltersData.TYPES.map { CheckBoxVal(it.first, false) })
|
||||
|
||||
class StateFilter : CheckBoxFilterList("Estado", AnimeFenixFiltersData.STATE.map { CheckBoxVal(it.first, false) })
|
||||
|
||||
class SortFilter : QueryPartFilter("Orden", AnimeFenixFiltersData.SORT)
|
||||
|
||||
private object AnimeFenixFiltersData {
|
||||
val YEARS = (1990..Calendar.getInstance().get(Calendar.YEAR)).map { Pair("$it", "$it") }.reversed().toTypedArray()
|
||||
|
||||
val TYPES = arrayOf(
|
||||
Pair("TV", "tv"),
|
||||
Pair("Película", "movie"),
|
||||
Pair("Especial", "special"),
|
||||
Pair("OVA", "ova"),
|
||||
Pair("DONGHUA", "donghua"),
|
||||
)
|
||||
|
||||
val STATE = arrayOf(
|
||||
Pair("Emisión", "1"),
|
||||
Pair("Finalizado", "2"),
|
||||
Pair("Próximamente", "3"),
|
||||
Pair("En Cuarentena", "4"),
|
||||
)
|
||||
|
||||
val SORT = arrayOf(
|
||||
Pair("Por Defecto", "default"),
|
||||
Pair("Recientemente Actualizados", "updated"),
|
||||
Pair("Recientemente Agregados", "added"),
|
||||
Pair("Nombre A-Z", "title"),
|
||||
Pair("Calificación", "likes"),
|
||||
Pair("Más Vistos", "visits"),
|
||||
)
|
||||
|
||||
val GENRES = arrayOf(
|
||||
Pair("Acción", "accion"),
|
||||
Pair("Ángeles", "angeles"),
|
||||
Pair("Artes Marciales", "artes-marciales"),
|
||||
Pair("Aventura", "aventura"),
|
||||
Pair("Ciencia Ficción", "Ciencia Ficción"),
|
||||
Pair("Comedia", "comedia"),
|
||||
Pair("Cyberpunk", "cyberpunk"),
|
||||
Pair("Demonios", "demonios"),
|
||||
Pair("Deportes", "deportes"),
|
||||
Pair("Dragones", "dragones"),
|
||||
Pair("Drama", "drama"),
|
||||
Pair("Ecchi", "ecchi"),
|
||||
Pair("Escolares", "escolares"),
|
||||
Pair("Fantasía", "fantasia"),
|
||||
Pair("Gore", "gore"),
|
||||
Pair("Harem", "harem"),
|
||||
Pair("Histórico", "historico"),
|
||||
Pair("Horror", "horror"),
|
||||
Pair("Infantil", "infantil"),
|
||||
Pair("Isekai", "isekai"),
|
||||
Pair("Josei", "josei"),
|
||||
Pair("Juegos", "juegos"),
|
||||
Pair("Magia", "magia"),
|
||||
Pair("Mecha", "mecha"),
|
||||
Pair("Militar", "militar"),
|
||||
Pair("Misterio", "misterio"),
|
||||
Pair("Música", "Musica"),
|
||||
Pair("Ninjas", "ninjas"),
|
||||
Pair("Parodia", "parodia"),
|
||||
Pair("Policía", "policia"),
|
||||
Pair("Psicológico", "psicologico"),
|
||||
Pair("Recuerdos de la vida", "Recuerdos de la vida"),
|
||||
Pair("Romance", "romance"),
|
||||
Pair("Samurai", "samurai"),
|
||||
Pair("Sci-Fi", "sci-fi"),
|
||||
Pair("Seinen", "seinen"),
|
||||
Pair("Shoujo", "shoujo"),
|
||||
Pair("Shoujo Ai", "shoujo-ai"),
|
||||
Pair("Shounen", "shounen"),
|
||||
Pair("Slice of life", "slice-of-life"),
|
||||
Pair("Sobrenatural", "sobrenatural"),
|
||||
Pair("Space", "space"),
|
||||
Pair("Spokon", "spokon"),
|
||||
Pair("Steampunk", "steampunk"),
|
||||
Pair("Superpoder", "superpoder"),
|
||||
Pair("Thriller", "thriller"),
|
||||
Pair("Vampiro", "vampiro"),
|
||||
Pair("Yaoi", "yaoi"),
|
||||
Pair("Yuri", "yuri"),
|
||||
Pair("Zombies", "zombies"),
|
||||
)
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import android.content.SharedPreferences
|
|||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimesPage
|
||||
import eu.kanade.tachiyomi.animesource.model.SAnime
|
||||
|
@ -84,37 +83,10 @@ class Animefenix : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||
override fun latestUpdatesParse(response: Response) = popularAnimeParse(response)
|
||||
|
||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
|
||||
val yearFilter = filters.find { it is YearFilter } as YearFilter
|
||||
val stateFilter = filters.find { it is StateFilter } as StateFilter
|
||||
val typeFilter = filters.find { it is TypeFilter } as TypeFilter
|
||||
val orderByFilter = filters.find { it is OrderByFilter } as OrderByFilter
|
||||
|
||||
val genreFilter = (filters.find { it is TagFilter } as TagFilter).state.filter { it.state }
|
||||
|
||||
var filterUrl = "$baseUrl/animes?"
|
||||
if (query.isNotBlank()) {
|
||||
filterUrl += "&q=$query"
|
||||
} // search by name
|
||||
if (genreFilter.isNotEmpty()) {
|
||||
genreFilter.forEach {
|
||||
filterUrl += "&genero[]=${it.name}"
|
||||
}
|
||||
} // search by genre
|
||||
if (yearFilter.state.isNotBlank()) {
|
||||
filterUrl += "&year[]=${yearFilter.state}"
|
||||
} // search by year
|
||||
if (stateFilter.state != 0) {
|
||||
filterUrl += "&estado[]=${stateFilter.toUriPart()}"
|
||||
} // search by state
|
||||
if (typeFilter.state != 0) {
|
||||
filterUrl += "&type[]=${typeFilter.toUriPart()}"
|
||||
} // search by type
|
||||
filterUrl += "&order=${orderByFilter.toUriPart()}"
|
||||
filterUrl += "&page=$page" // add page
|
||||
val params = AnimeFenixFilters.getSearchParameters(filters)
|
||||
|
||||
return when {
|
||||
genreFilter.isEmpty() || yearFilter.state.isNotBlank() ||
|
||||
stateFilter.state != 0 || typeFilter.state != 0 || query.isNotBlank() -> GET(filterUrl, headers)
|
||||
params.filter.isNotBlank() -> GET("$baseUrl/animes${params.getQuery()}&page=$page", headers)
|
||||
else -> GET("$baseUrl/animes?order=likes&page=$page ")
|
||||
}
|
||||
}
|
||||
|
@ -273,110 +245,7 @@ class Animefenix : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun getFilterList(): AnimeFilterList = AnimeFilterList(
|
||||
TagFilter("Generos", checkboxesFrom(genreList)),
|
||||
StateFilter(),
|
||||
TypeFilter(),
|
||||
OrderByFilter(),
|
||||
YearFilter(),
|
||||
)
|
||||
|
||||
private val genreList = arrayOf(
|
||||
Pair("Acción", "acción"),
|
||||
Pair("Aventura", "aventura"),
|
||||
Pair("Angeles", "angeles"),
|
||||
Pair("Artes Marciales", "artes-marciales"),
|
||||
Pair("Ciencia Ficcion", "ciencia-ficcion"),
|
||||
Pair("Comedia", "comedia"),
|
||||
Pair("Cyberpunk", "cyberpunk"),
|
||||
Pair("Demonios", "demonios"),
|
||||
Pair("Deportes", "deportes"),
|
||||
Pair("Dragones", "dragones"),
|
||||
Pair("Drama", "drama"),
|
||||
Pair("Ecchi", "ecchi"),
|
||||
Pair("Escolares", "escolares"),
|
||||
Pair("Fantasía", "fantasía"),
|
||||
Pair("Gore", "gore"),
|
||||
Pair("Harem", "harem"),
|
||||
Pair("Historico", "historico"),
|
||||
Pair("Horror", "horror"),
|
||||
Pair("Infantil", "infantil"),
|
||||
Pair("Isekai", "isekai"),
|
||||
Pair("Josei", "josei"),
|
||||
Pair("Juegos", "juegos"),
|
||||
Pair("Magia", "magia"),
|
||||
Pair("Mecha", "mecha"),
|
||||
Pair("Militar", "militar"),
|
||||
Pair("Misterio", "misterio"),
|
||||
Pair("Música", "música"),
|
||||
Pair("Ninjas", "ninjas"),
|
||||
Pair("Parodias", "parodias"),
|
||||
Pair("Policia", "policia"),
|
||||
Pair("Psicológico", "psicológico"),
|
||||
Pair("Recuerdos de la vida", "recuerdos-de-la-vida"),
|
||||
Pair("Romance", "romance"),
|
||||
Pair("Samurai", "samurai"),
|
||||
Pair("Sci-Fi", "sci-fi"),
|
||||
Pair("Seinen", "seinen"),
|
||||
Pair("Shoujo", "shoujo"),
|
||||
Pair("Shonen", "shonen"),
|
||||
Pair("Slice of life", "slice-of-life"),
|
||||
Pair("Sobrenatural", "sobrenatural"),
|
||||
Pair("Space", "space"),
|
||||
Pair("Spokon", "spokon"),
|
||||
Pair("SteamPunk", "steampunk"),
|
||||
Pair("SuperPoder", "superpoder"),
|
||||
Pair("Vampiros", "vampiros"),
|
||||
Pair("Yaoi", "yaoi"),
|
||||
Pair("Yuri", "yuri"),
|
||||
)
|
||||
|
||||
private fun checkboxesFrom(tagArray: Array<Pair<String, String>>): List<TagCheckBox> = tagArray.map { TagCheckBox(it.second) }
|
||||
|
||||
class TagCheckBox(tag: String) : AnimeFilter.CheckBox(tag, false)
|
||||
|
||||
class TagFilter(name: String, checkBoxes: List<TagCheckBox>) : AnimeFilter.Group<TagCheckBox>(name, checkBoxes)
|
||||
|
||||
private class YearFilter : AnimeFilter.Text("Año")
|
||||
|
||||
private class StateFilter : UriPartFilter(
|
||||
"Estado",
|
||||
arrayOf(
|
||||
Pair("<Seleccionar>", ""),
|
||||
Pair("Emision", "1"),
|
||||
Pair("Finalizado", "2"),
|
||||
Pair("Proximamente", "3"),
|
||||
Pair("En Cuarentena", "4"),
|
||||
),
|
||||
)
|
||||
|
||||
private class TypeFilter : UriPartFilter(
|
||||
"Tipo",
|
||||
arrayOf(
|
||||
Pair("<Seleccionar>", ""),
|
||||
Pair("TV", "tv"),
|
||||
Pair("Pelicula", "movie"),
|
||||
Pair("Especial", "special"),
|
||||
Pair("OVA", "ova"),
|
||||
),
|
||||
)
|
||||
|
||||
private class OrderByFilter : UriPartFilter(
|
||||
"Ordenar Por",
|
||||
arrayOf(
|
||||
Pair("Por defecto", "default"),
|
||||
Pair("Recientemente Actualizados", "updated"),
|
||||
Pair("Recientemente Agregados", "added"),
|
||||
Pair("Nombre A-Z", "title"),
|
||||
Pair("Calificación", "likes"),
|
||||
Pair("Más vistos", "visits"),
|
||||
),
|
||||
)
|
||||
|
||||
private open class UriPartFilter(displayName: String, val vals: Array<Pair<String, String>>) :
|
||||
AnimeFilter.Select<String>(displayName, vals.map { it.first }.toTypedArray()) {
|
||||
fun toUriPart() = vals[state].second
|
||||
}
|
||||
override fun getFilterList(): AnimeFilterList = AnimeFenixFilters.FILTER_LIST
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
ListPreference(screen.context).apply {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue