Comick: add tag exclude to extension settings (#8504)

* feat(all/comick): Add tag exclude to extension settings

* dont add empty tags
This commit is contained in:
Secozzi 2025-04-17 15:57:55 +02:00 committed by Draff
parent c9fc08676f
commit b709f76b96
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
4 changed files with 39 additions and 11 deletions

View File

@ -1,5 +1,7 @@
ignored_groups_title=Ignored Groups ignored_groups_title=Ignored Groups
ignored_groups_summary=Chapters from these groups won't be shown.\nOne group name per line (case-insensitive) ignored_groups_summary=Chapters from these groups won't be shown.\nOne group name per line (case-insensitive)
ignored_tags_title=Ignored Tags
ignored_tags_summary=Manga with these tags won't show up when browsing.\nOne tag per line (case-insensitive)
show_alternative_titles_title=Show Alternative Titles show_alternative_titles_title=Show Alternative Titles
show_alternative_titles_on=Adds alternative titles to the description show_alternative_titles_on=Adds alternative titles to the description
show_alternative_titles_off=Does not show alternative titles to the description show_alternative_titles_off=Does not show alternative titles to the description

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Comick' extName = 'Comick'
extClass = '.ComickFactory' extClass = '.ComickFactory'
extVersionCode = 55 extVersionCode = 56
isNsfw = true isNsfw = true
} }

View File

@ -79,6 +79,12 @@ abstract class Comick(
} }
}.also(screen::addPreference) }.also(screen::addPreference)
EditTextPreference(screen.context).apply {
key = IGNORED_TAGS_PREF
title = intl["ignored_tags_title"]
summary = intl["ignored_tags_summary"]
}.also(screen::addPreference)
SwitchPreferenceCompat(screen.context).apply { SwitchPreferenceCompat(screen.context).apply {
key = SHOW_ALTERNATIVE_TITLES_PREF key = SHOW_ALTERNATIVE_TITLES_PREF
title = intl["show_alternative_titles_title"] title = intl["show_alternative_titles_title"]
@ -184,6 +190,14 @@ abstract class Comick(
.orEmpty() .orEmpty()
.toSet() .toSet()
private val SharedPreferences.ignoredTags: String
get() = getString(IGNORED_TAGS_PREF, "")
?.split("\n")
?.map(String::trim)
?.filter(String::isNotEmpty)
.orEmpty()
.joinToString(",")
private val SharedPreferences.showAlternativeTitles: Boolean private val SharedPreferences.showAlternativeTitles: Boolean
get() = getBoolean(SHOW_ALTERNATIVE_TITLES_PREF, SHOW_ALTERNATIVE_TITLES_DEFAULT) get() = getBoolean(SHOW_ALTERNATIVE_TITLES_PREF, SHOW_ALTERNATIVE_TITLES_DEFAULT)
@ -243,8 +257,13 @@ abstract class Comick(
/** Popular Manga **/ /** Popular Manga **/
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
val url = "$apiUrl/v1.0/search?sort=follow&limit=$LIMIT&page=$page&tachiyomi=true" return searchMangaRequest(
return GET(url, headers) page = page,
query = "",
filters = FilterList(
SortFilter("follow"),
),
)
} }
override fun popularMangaParse(response: Response): MangasPage { override fun popularMangaParse(response: Response): MangasPage {
@ -257,8 +276,13 @@ abstract class Comick(
/** Latest Manga **/ /** Latest Manga **/
override fun latestUpdatesRequest(page: Int): Request { override fun latestUpdatesRequest(page: Int): Request {
val url = "$apiUrl/v1.0/search?sort=uploaded&limit=$LIMIT&page=$page&tachiyomi=true" return searchMangaRequest(
return GET(url, headers) page = page,
query = "",
filters = FilterList(
SortFilter("uploaded"),
),
)
} }
override fun latestUpdatesParse(response: Response) = popularMangaParse(response) override fun latestUpdatesParse(response: Response) = popularMangaParse(response)
@ -316,7 +340,7 @@ abstract class Comick(
} }
private fun addTagQueryParameters(builder: Builder, tags: String, parameterName: String) { private fun addTagQueryParameters(builder: Builder, tags: String, parameterName: String) {
tags.split(",").forEach { tags.split(",").filter(String::isNotEmpty).forEach {
builder.addQueryParameter( builder.addQueryParameter(
parameterName, parameterName,
it.trim().lowercase().replace(SPACE_AND_SLASH_REGEX, "-") it.trim().lowercase().replace(SPACE_AND_SLASH_REGEX, "-")
@ -412,6 +436,7 @@ abstract class Comick(
else -> {} else -> {}
} }
} }
addTagQueryParameters(this, preferences.ignoredTags, "excluded-tags")
addQueryParameter("tachiyomi", "true") addQueryParameter("tachiyomi", "true")
addQueryParameter("limit", "$LIMIT") addQueryParameter("limit", "$LIMIT")
addQueryParameter("page", "$page") addQueryParameter("page", "$page")
@ -587,6 +612,7 @@ abstract class Comick(
const val SLUG_SEARCH_PREFIX = "id:" const val SLUG_SEARCH_PREFIX = "id:"
private val SPACE_AND_SLASH_REGEX = Regex("[ /]") private val SPACE_AND_SLASH_REGEX = Regex("[ /]")
private const val IGNORED_GROUPS_PREF = "IgnoredGroups" private const val IGNORED_GROUPS_PREF = "IgnoredGroups"
private const val IGNORED_TAGS_PREF = "IgnoredTags"
private const val SHOW_ALTERNATIVE_TITLES_PREF = "ShowAlternativeTitles" private const val SHOW_ALTERNATIVE_TITLES_PREF = "ShowAlternativeTitles"
const val SHOW_ALTERNATIVE_TITLES_DEFAULT = false const val SHOW_ALTERNATIVE_TITLES_DEFAULT = false
private const val INCLUDE_MU_TAGS_PREF = "IncludeMangaUpdatesTags" private const val INCLUDE_MU_TAGS_PREF = "IncludeMangaUpdatesTags"

View File

@ -9,7 +9,7 @@ fun getFilters(): FilterList {
GenreFilter("Genre", getGenresList), GenreFilter("Genre", getGenresList),
DemographicFilter("Demographic", getDemographicList), DemographicFilter("Demographic", getDemographicList),
TypeFilter("Type", getTypeList), TypeFilter("Type", getTypeList),
SortFilter("Sort", getSortsList), SortFilter(),
StatusFilter("Status", getStatusList), StatusFilter("Status", getStatusList),
ContentRatingFilter("Content Rating", getContentRatingList), ContentRatingFilter("Content Rating", getContentRatingList),
CompletedFilter("Completely Scanlated?"), CompletedFilter("Completely Scanlated?"),
@ -50,8 +50,8 @@ internal class FromYearFilter(name: String) : TextFilter(name)
internal class ToYearFilter(name: String) : TextFilter(name) internal class ToYearFilter(name: String) : TextFilter(name)
internal class SortFilter(name: String, sortList: List<Pair<String, String>>, state: Int = 0) : internal class SortFilter(defaultValue: String? = null, state: Int = 0) :
SelectFilter(name, sortList, state) SelectFilter("Sort", getSortsList, state, defaultValue)
internal class StatusFilter(name: String, statusList: List<Pair<String, String>>, state: Int = 0) : internal class StatusFilter(name: String, statusList: List<Pair<String, String>>, state: Int = 0) :
SelectFilter(name, statusList, state) SelectFilter(name, statusList, state)
@ -66,8 +66,8 @@ internal open class TextFilter(name: String) : Filter.Text(name)
internal open class CheckBoxFilter(name: String, val value: String = "") : Filter.CheckBox(name) internal open class CheckBoxFilter(name: String, val value: String = "") : Filter.CheckBox(name)
internal open class SelectFilter(name: String, private val vals: List<Pair<String, String>>, state: Int = 0) : internal open class SelectFilter(name: String, private val vals: List<Pair<String, String>>, state: Int = 0, defaultValue: String? = null) :
Filter.Select<String>(name, vals.map { it.first }.toTypedArray(), state) { Filter.Select<String>(name, vals.map { it.first }.toTypedArray(), vals.indexOfFirst { it.second == defaultValue }.takeIf { it != -1 } ?: state) {
fun getValue() = vals[state].second fun getValue() = vals[state].second
} }