Skip to content

Commit

Permalink
rename filter and filterlist classes for anime,
Browse files Browse the repository at this point in the history
update libversion for anime extensions to 10
  • Loading branch information
jmir1 committed May 27, 2021
1 parent 6461ea4 commit f835b31
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.animesource

import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
import eu.kanade.tachiyomi.animesource.model.FilterList
import rx.Observable

interface AnimeCatalogueSource : AnimeSource {
Expand Down Expand Up @@ -30,7 +30,7 @@ interface AnimeCatalogueSource : AnimeSource {
* @param query the search query.
* @param filters the list of filters to apply.
*/
fun fetchSearchAnime(page: Int, query: String, filters: FilterList): Observable<AnimesPage>
fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage>

/**
* Returns an observable containing a page with a list of latest anime updates.
Expand All @@ -42,5 +42,5 @@ interface AnimeCatalogueSource : AnimeSource {
/**
* Returns the list of filters for the source.
*/
fun getFilterList(): FilterList
fun getFilterList(): AnimeFilterList
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.content.Context
import com.github.junrar.Archive
import com.google.gson.JsonParser
import eu.kanade.tachiyomi.R
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.Filter
import eu.kanade.tachiyomi.animesource.model.FilterList
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.util.episode.EpisodeRecognition
Expand Down Expand Up @@ -66,7 +66,7 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource {

override fun fetchPopularAnime(page: Int) = fetchSearchAnime(page, "", POPULAR_FILTERS)

override fun fetchSearchAnime(page: Int, query: String, filters: FilterList): Observable<AnimesPage> {
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
val baseDirs = getBaseDirectories(context)

val time = if (filters === LATEST_FILTERS) System.currentTimeMillis() - LATEST_THRESHOLD else 0L
Expand Down Expand Up @@ -310,10 +310,10 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource {

override fun getFilterList() = POPULAR_FILTERS

private val POPULAR_FILTERS = FilterList(OrderBy(context))
private val LATEST_FILTERS = FilterList(OrderBy(context).apply { state = Filter.Sort.Selection(1, false) })
private val POPULAR_FILTERS = AnimeFilterList(OrderBy(context))
private val LATEST_FILTERS = AnimeFilterList(OrderBy(context).apply { state = AnimeFilter.Sort.Selection(1, false) })

private class OrderBy(context: Context) : Filter.Sort(
private class OrderBy(context: Context) : AnimeFilter.Sort(
context.getString(R.string.local_filter_order_by),
arrayOf(context.getString(R.string.title), context.getString(R.string.date)),
Selection(0, true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package eu.kanade.tachiyomi.animesource.model

sealed class Filter<T>(val name: String, var state: T) {
open class Header(name: String) : Filter<Any>(name, 0)
open class Separator(name: String = "") : Filter<Any>(name, 0)
abstract class Select<V>(name: String, val values: Array<V>, state: Int = 0) : Filter<Int>(name, state)
abstract class Text(name: String, state: String = "") : Filter<String>(name, state)
abstract class CheckBox(name: String, state: Boolean = false) : Filter<Boolean>(name, state)
abstract class TriState(name: String, state: Int = STATE_IGNORE) : Filter<Int>(name, state) {
sealed class AnimeFilter<T>(val name: String, var state: T) {
open class Header(name: String) : AnimeFilter<Any>(name, 0)
open class Separator(name: String = "") : AnimeFilter<Any>(name, 0)
abstract class Select<V>(name: String, val values: Array<V>, state: Int = 0) : AnimeFilter<Int>(name, state)
abstract class Text(name: String, state: String = "") : AnimeFilter<String>(name, state)
abstract class CheckBox(name: String, state: Boolean = false) : AnimeFilter<Boolean>(name, state)
abstract class TriState(name: String, state: Int = STATE_IGNORE) : AnimeFilter<Int>(name, state) {
fun isIgnored() = state == STATE_IGNORE
fun isIncluded() = state == STATE_INCLUDE
fun isExcluded() = state == STATE_EXCLUDE
Expand All @@ -18,16 +18,16 @@ sealed class Filter<T>(val name: String, var state: T) {
}
}

abstract class Group<V>(name: String, state: List<V>) : Filter<List<V>>(name, state)
abstract class Group<V>(name: String, state: List<V>) : AnimeFilter<List<V>>(name, state)

abstract class Sort(name: String, val values: Array<String>, state: Selection? = null) :
Filter<Sort.Selection?>(name, state) {
AnimeFilter<Sort.Selection?>(name, state) {
data class Selection(val index: Int, val ascending: Boolean)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Filter<*>) return false
if (other !is AnimeFilter<*>) return false

return name == other.name && state == other.state
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package eu.kanade.tachiyomi.animesource.model

data class AnimeFilterList(val list: List<AnimeFilter<*>>) : List<AnimeFilter<*>> by list {

constructor(vararg fs: AnimeFilter<*>) : this(if (fs.isNotEmpty()) fs.asList() else emptyList())
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.animesource.online

import android.net.Uri
import eu.kanade.tachiyomi.animesource.AnimeCatalogueSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
import eu.kanade.tachiyomi.animesource.model.FilterList
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.animesource.model.Video
Expand Down Expand Up @@ -117,7 +117,7 @@ abstract class AnimeHttpSource : AnimeCatalogueSource {
* @param query the search query.
* @param filters the list of filters to apply.
*/
override fun fetchSearchAnime(page: Int, query: String, filters: FilterList): Observable<AnimesPage> {
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
return client.newCall(searchAnimeRequest(page, query, filters))
.asObservableSuccess()
.map { response ->
Expand All @@ -132,7 +132,7 @@ abstract class AnimeHttpSource : AnimeCatalogueSource {
* @param query the search query.
* @param filters the list of filters to apply.
*/
protected abstract fun searchAnimeRequest(page: Int, query: String, filters: FilterList): Request
protected abstract fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request

/**
* Parses the response from the site and returns a [AnimesPage] object.
Expand Down Expand Up @@ -374,7 +374,7 @@ abstract class AnimeHttpSource : AnimeCatalogueSource {
/**
* Returns the list of filters for the source.
*/
override fun getFilterList() = FilterList()
override fun getFilterList() = AnimeFilterList()

companion object {
const val DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.63"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class AnimeExtensionGithubApi {
return json
.filter { element ->
val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
val libVersion = versionName.substringBeforeLast('.').toDouble()
val libVersion = versionName.substringBeforeLast('.').toInt()
libVersion >= AnimeExtensionLoader.LIB_VERSION_MIN && libVersion <= AnimeExtensionLoader.LIB_VERSION_MAX
}
.map { element ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ internal object AnimeExtensionLoader {
private const val METADATA_SOURCE_CLASS = "tachiyomi.animeextension.class"
private const val METADATA_SOURCE_FACTORY = "tachiyomi.animeextension.factory"
private const val METADATA_NSFW = "tachiyomi.animeextension.nsfw"
const val LIB_VERSION_MIN = 1.2
const val LIB_VERSION_MAX = 1.3
const val LIB_VERSION_MIN = 10
const val LIB_VERSION_MAX = 10

private const val PACKAGE_FLAGS = PackageManager.GET_CONFIGURATIONS or PackageManager.GET_SIGNATURES

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package eu.kanade.tachiyomi.ui.browse.animesource.browse

import eu.kanade.tachiyomi.animesource.AnimeCatalogueSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
import eu.kanade.tachiyomi.animesource.model.FilterList
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

open class AnimeSourcePager(val source: AnimeCatalogueSource, val query: String, val filters: FilterList) : AnimePager() {
open class AnimeSourcePager(val source: AnimeCatalogueSource, val query: String, val filters: AnimeFilterList) : AnimePager() {

override fun requestNext(): Observable<AnimesPage> {
val page = currentPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.AnimeCatalogueSource
import eu.kanade.tachiyomi.animesource.LocalAnimeSource
import eu.kanade.tachiyomi.animesource.model.FilterList
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource
import eu.kanade.tachiyomi.data.database.models.Anime
import eu.kanade.tachiyomi.data.database.models.Category
Expand Down Expand Up @@ -147,10 +147,10 @@ open class BrowseAnimeSourceController(bundle: Bundle) :
val allDefault = presenter.sourceFilters == presenter.source.getFilterList()
showProgressBar()
adapter?.clear()
presenter.setSourceFilter(if (allDefault) FilterList() else presenter.sourceFilters)
presenter.setSourceFilter(if (allDefault) AnimeFilterList() else presenter.sourceFilters)
},
onResetClicked = {
presenter.appliedFilters = FilterList()
presenter.appliedFilters = AnimeFilterList()
val newFilters = presenter.source.getFilterList()
presenter.sourceFilters = newFilters
filterSheet?.setFilters(presenter.filterItems)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.os.Bundle
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.animesource.AnimeCatalogueSource
import eu.kanade.tachiyomi.animesource.AnimeSourceManager
import eu.kanade.tachiyomi.animesource.model.Filter
import eu.kanade.tachiyomi.animesource.model.FilterList
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.toSAnime
import eu.kanade.tachiyomi.data.cache.AnimeCoverCache
Expand Down Expand Up @@ -73,7 +73,7 @@ open class BrowseAnimeSourcePresenter(
/**
* Modifiable list of filters.
*/
var sourceFilters = FilterList()
var sourceFilters = AnimeFilterList()
set(value) {
field = value
filterItems = value.toItems()
Expand All @@ -84,7 +84,7 @@ open class BrowseAnimeSourcePresenter(
/**
* List of filters used by the [Pager]. If empty alongside [query], the popular query is used.
*/
var appliedFilters = FilterList()
var appliedFilters = AnimeFilterList()

/**
* Pager containing a list of anime results.
Expand Down Expand Up @@ -137,7 +137,7 @@ open class BrowseAnimeSourcePresenter(
* @param query the query.
* @param filters the current state of the filters (for search mode).
*/
fun restartPager(query: String = this.query, filters: FilterList = this.appliedFilters) {
fun restartPager(query: String = this.query, filters: AnimeFilterList = this.appliedFilters) {
this.query = query
this.appliedFilters = filters

Expand Down Expand Up @@ -301,39 +301,39 @@ open class BrowseAnimeSourcePresenter(
*
* @param filters a list of active filters.
*/
fun setSourceFilter(filters: FilterList) {
fun setSourceFilter(filters: AnimeFilterList) {
restartPager(filters = filters)
}

open fun createPager(query: String, filters: FilterList): AnimePager {
open fun createPager(query: String, filters: AnimeFilterList): AnimePager {
return AnimeSourcePager(source, query, filters)
}

private fun FilterList.toItems(): List<IFlexible<*>> {
private fun AnimeFilterList.toItems(): List<IFlexible<*>> {
return mapNotNull { filter ->
when (filter) {
is Filter.Header -> HeaderItem(filter)
is Filter.Separator -> SeparatorItem(filter)
is Filter.CheckBox -> CheckboxItem(filter)
is Filter.TriState -> TriStateItem(filter)
is Filter.Text -> TextItem(filter)
is Filter.Select<*> -> SelectItem(filter)
is Filter.Group<*> -> {
is AnimeFilter.Header -> HeaderItem(filter)
is AnimeFilter.Separator -> SeparatorItem(filter)
is AnimeFilter.CheckBox -> CheckboxItem(filter)
is AnimeFilter.TriState -> TriStateItem(filter)
is AnimeFilter.Text -> TextItem(filter)
is AnimeFilter.Select<*> -> SelectItem(filter)
is AnimeFilter.Group<*> -> {
val group = GroupItem(filter)
val subItems = filter.state.mapNotNull {
when (it) {
is Filter.CheckBox -> CheckboxSectionItem(it)
is Filter.TriState -> TriStateSectionItem(it)
is Filter.Text -> TextSectionItem(it)
is Filter.Select<*> -> SelectSectionItem(it)
is AnimeFilter.CheckBox -> CheckboxSectionItem(it)
is AnimeFilter.TriState -> TriStateSectionItem(it)
is AnimeFilter.Text -> TextSectionItem(it)
is AnimeFilter.Select<*> -> SelectSectionItem(it)
else -> null
}
}
subItems.forEach { it.header = group }
group.subItems = subItems
group
}
is Filter.Sort -> {
is AnimeFilter.Sort -> {
val group = SortGroup(filter)
val subItems = filter.values.map {
SortItem(it, group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.model.Filter
import eu.kanade.tachiyomi.animesource.model.AnimeFilter

open class CheckboxItem(val filter: Filter.CheckBox) : AbstractFlexibleItem<CheckboxItem.Holder>() {
open class CheckboxItem(val filter: AnimeFilter.CheckBox) : AbstractFlexibleItem<CheckboxItem.Holder>() {

override fun getLayoutRes(): Int {
return R.layout.navigation_view_checkbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.flexibleadapter.items.ISectionable
import eu.davidea.viewholders.ExpandableViewHolder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.model.Filter
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.util.view.setVectorCompat

class GroupItem(val filter: Filter.Group<*>) : AbstractExpandableHeaderItem<GroupItem.Holder, ISectionable<*, *>>() {
class GroupItem(val filter: AnimeFilter.Group<*>) : AbstractExpandableHeaderItem<GroupItem.Holder, ISectionable<*, *>>() {

init {
isExpanded = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractHeaderItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.animesource.model.Filter
import eu.kanade.tachiyomi.animesource.model.AnimeFilter

class HeaderItem(val filter: Filter.Header) : AbstractHeaderItem<HeaderItem.Holder>() {
class HeaderItem(val filter: AnimeFilter.Header) : AbstractHeaderItem<HeaderItem.Holder>() {

@SuppressLint("PrivateResource")
override fun getLayoutRes(): Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package eu.kanade.tachiyomi.ui.browse.animesource.filter

import eu.davidea.flexibleadapter.items.ISectionable
import eu.kanade.tachiyomi.animesource.model.Filter
import eu.kanade.tachiyomi.animesource.model.AnimeFilter

class TriStateSectionItem(filter: Filter.TriState) : TriStateItem(filter), ISectionable<TriStateItem.Holder, GroupItem> {
class TriStateSectionItem(filter: AnimeFilter.TriState) : TriStateItem(filter), ISectionable<TriStateItem.Holder, GroupItem> {

private var head: GroupItem? = null

Expand All @@ -27,7 +27,7 @@ class TriStateSectionItem(filter: Filter.TriState) : TriStateItem(filter), ISect
}
}

class TextSectionItem(filter: Filter.Text) : TextItem(filter), ISectionable<TextItem.Holder, GroupItem> {
class TextSectionItem(filter: AnimeFilter.Text) : TextItem(filter), ISectionable<TextItem.Holder, GroupItem> {

private var head: GroupItem? = null

Expand All @@ -51,7 +51,7 @@ class TextSectionItem(filter: Filter.Text) : TextItem(filter), ISectionable<Text
}
}

class CheckboxSectionItem(filter: Filter.CheckBox) : CheckboxItem(filter), ISectionable<CheckboxItem.Holder, GroupItem> {
class CheckboxSectionItem(filter: AnimeFilter.CheckBox) : CheckboxItem(filter), ISectionable<CheckboxItem.Holder, GroupItem> {

private var head: GroupItem? = null

Expand All @@ -75,7 +75,7 @@ class CheckboxSectionItem(filter: Filter.CheckBox) : CheckboxItem(filter), ISect
}
}

class SelectSectionItem(filter: Filter.Select<*>) : SelectItem(filter), ISectionable<SelectItem.Holder, GroupItem> {
class SelectSectionItem(filter: AnimeFilter.Select<*>) : SelectItem(filter), ISectionable<SelectItem.Holder, GroupItem> {

private var head: GroupItem? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.model.Filter
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.widget.listener.IgnoreFirstSpinnerListener

open class SelectItem(val filter: Filter.Select<*>) : AbstractFlexibleItem<SelectItem.Holder>() {
open class SelectItem(val filter: AnimeFilter.Select<*>) : AbstractFlexibleItem<SelectItem.Holder>() {

override fun getLayoutRes(): Int {
return R.layout.navigation_view_spinner
Expand Down
Loading

0 comments on commit f835b31

Please sign in to comment.