From 01a496768a4dba065638f0d7c281725469cb713e Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 14 Sep 2024 12:41:24 +0300 Subject: [PATCH] MangaListFilter v2 --- .../parsers/model/MangaListFilterV2.kt | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/main/kotlin/org/koitharu/kotatsu/parsers/model/MangaListFilterV2.kt diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/MangaListFilterV2.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/MangaListFilterV2.kt new file mode 100644 index 00000000..5562a960 --- /dev/null +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/MangaListFilterV2.kt @@ -0,0 +1,122 @@ +package org.koitharu.kotatsu.parsers.model + +import java.util.* + +@Suppress("DataClassPrivateConstructor") +data class MangaListFilterV2 private constructor( + @JvmField val sortOrder: SortOrder?, + @JvmField val tags: Set, + @JvmField val tagsExclude: Set, + @JvmField val locale: Locale?, + @JvmField val localeMangas: Locale?, + @JvmField val states: Set, + @JvmField val contentRating: Set, + @JvmField val query: String?, + @JvmField val year: Int, + @JvmField val yearFrom: Int, + @JvmField val yearTo: Int, +) { + + fun isEmpty(): Boolean = tags.isEmpty() && + tagsExclude.isEmpty() && + locale == null && + localeMangas == null && + states.isEmpty() && + contentRating.isEmpty() && + query == null && + year == 0 && + yearFrom == 0 && + yearTo == 0 + + fun newBuilder() = Builder() + .sortOrder(sortOrder) + .tags(tags) + .tagsExclude(tagsExclude) + .locale(locale) + .localeMangas(localeMangas) + .states(states) + .contentRatings(contentRating) + .searchQuery(query) + .year(year) + .yearFrom(yearFrom) + .yearTo(yearTo) + + class Builder { + + private var _sortOrder: SortOrder? = null + private var _tags: Set? = null + private var _tagsExclude: Set? = null + private var _locale: Locale? = null + private var _localeMangas: Locale? = null + private var _states: Set? = null + private var _contentRating: Set? = null + private var _query: String? = null + private var _year: Int = 0 + private var _yearFrom: Int = 0 + private var _yearTo: Int = 0 + + fun sortOrder(order: SortOrder?) = apply { + _sortOrder = order + } + + fun tags(tags: Set?) = apply { + _tags = tags + } + + fun tagsExclude(tags: Set?) = apply { + _tagsExclude = tags + } + + fun locale(locale: Locale?) = apply { + _locale = locale + } + + fun localeMangas(localeMangas: Locale?) = apply { + _localeMangas = localeMangas + } + + fun states(states: Set?) = apply { + _states = states + } + + fun contentRatings(rating: Set?) = apply { + _contentRating = rating + } + + fun searchQuery(query: String?) = apply { + _query = query + } + + fun year(year: Int) = apply { + _year = year + } + + fun yearFrom(yearFrom: Int) = apply { + _yearFrom = yearFrom + } + + fun yearTo(yearTo: Int) = apply { + _yearTo = yearTo + } + + fun build() = MangaListFilterV2( + sortOrder = _sortOrder, + tags = _tags.orEmpty(), + tagsExclude = _tagsExclude.orEmpty(), + locale = _locale, + localeMangas = _localeMangas, + states = _states.orEmpty(), + contentRating = _contentRating.orEmpty(), + query = _query, + year = _year, + yearFrom = _yearFrom, + yearTo = _yearTo, + ) + } + + companion object { + + @JvmStatic + val EMPTY = Builder().build() + } +}