Add category filters for Updates tab (#3589)

* Add category filters for Updates tab

Works just like Library Updates.

Provides a tab in the Updates tab filter dialog to allow for including
& excluding of updates belonging to a title from a given category.

Excludes overpower Includes, as with Library Updates.

A little helpful text informs users about this.

* Changelog

* [skip ci] Remove unused string

Leftover from before I realized the Default category will always be
available for in-/exclusion.

* Make :includeEmpty/:excludeEmpty true Boolean params

* "include" -> "included"

Consistency with #3607.

* Remove DISTINCT from getRecentUpdatesWithFilters

Apparently not needed anymore (though it was required at some point).

* [skip ci] Fix Changelog
This commit is contained in:
MajorTanya
2026-08-02 12:59:58 +02:00
committed by GitHub
parent 6d69903a56
commit 1d8a2b05dd
10 changed files with 152 additions and 8 deletions
@@ -4,14 +4,32 @@ import androidx.lifecycle.ViewModel
import tachiyomi.core.common.preference.Preference
import tachiyomi.core.common.preference.TriState
import tachiyomi.core.common.preference.getAndSet
import tachiyomi.domain.category.interactor.GetCategories
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.updates.service.UpdatesPreferences
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class UpdatesSettingsViewModel(
val updatesPreferences: UpdatesPreferences = Injekt.get(),
val getCategories: GetCategories = Injekt.get(),
) : ViewModel() {
val includedCategories = updatesPreferences.filterIncludedCategories
val excludedCategories = updatesPreferences.filterExcludedCategories
fun cycleCategory(category: Category) {
when (category.id) {
in includedCategories.get() -> {
includedCategories.getAndSet { it - category.id }
excludedCategories.getAndSet { it + category.id }
}
in excludedCategories.get() -> excludedCategories.getAndSet { it - category.id }
else -> includedCategories.getAndSet { it + category.id }
}
}
fun toggleFilter(preference: (UpdatesPreferences) -> Preference<TriState>) {
preference(updatesPreferences).getAndSet {
it.next()
@@ -93,6 +93,8 @@ class UpdatesViewModel(
started = it.filterStarted.toBooleanOrNull(),
bookmarked = it.filterBookmarked.toBooleanOrNull(),
hideExcludedScanlators = it.filterExcludedScanlators,
includedCategories = it.filterIncludedCategories,
excludedCategories = it.filterExcludedCategories,
).distinctUntilChanged()
},
downloadCache.changes,
@@ -423,13 +425,18 @@ class UpdatesViewModel(
updatesPreferences.filterStarted.changes(),
updatesPreferences.filterBookmarked.changes(),
updatesPreferences.filterExcludedScanlators.changes(),
) { downloaded, unread, started, bookmarked, excludedScanlators ->
updatesPreferences.filterIncludedCategories.changes(),
updatesPreferences.filterExcludedCategories.changes(),
) {
@Suppress("UNCHECKED_CAST")
ItemPreferences(
filterDownloaded = downloaded,
filterUnread = unread,
filterStarted = started,
filterBookmarked = bookmarked,
filterExcludedScanlators = excludedScanlators,
filterDownloaded = it[0] as TriState,
filterUnread = it[1] as TriState,
filterStarted = it[2] as TriState,
filterBookmarked = it[3] as TriState,
filterExcludedScanlators = it[4] as Boolean,
filterIncludedCategories = it[5] as List<Long>,
filterExcludedCategories = it[6] as List<Long>,
)
}
}
@@ -445,6 +452,8 @@ class UpdatesViewModel(
val filterStarted: TriState,
val filterBookmarked: TriState,
val filterExcludedScanlators: Boolean,
val filterIncludedCategories: List<Long>,
val filterExcludedCategories: List<Long>,
)
@Immutable