refactor(library): Simplify category handling and improve filtering logic (#1235)
This commit is contained in:
parent
296a314429
commit
d15fa402df
1 changed files with 14 additions and 10 deletions
|
|
@ -93,6 +93,7 @@ import tachiyomi.domain.UnsortedPreferences
|
||||||
import tachiyomi.domain.category.interactor.GetCategories
|
import tachiyomi.domain.category.interactor.GetCategories
|
||||||
import tachiyomi.domain.category.interactor.SetMangaCategories
|
import tachiyomi.domain.category.interactor.SetMangaCategories
|
||||||
import tachiyomi.domain.category.model.Category
|
import tachiyomi.domain.category.model.Category
|
||||||
|
import tachiyomi.domain.category.model.Category.Companion.UNCATEGORIZED_ID
|
||||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||||
import tachiyomi.domain.chapter.interactor.GetMergedChaptersByMangaId
|
import tachiyomi.domain.chapter.interactor.GetMergedChaptersByMangaId
|
||||||
import tachiyomi.domain.chapter.model.Chapter
|
import tachiyomi.domain.chapter.model.Chapter
|
||||||
|
|
@ -190,7 +191,6 @@ class LibraryScreenModel(
|
||||||
// KMK <--
|
// KMK <--
|
||||||
getLibraryItemPreferencesFlow(),
|
getLibraryItemPreferencesFlow(),
|
||||||
) { (searchQuery, categories, favorites), (tracksMap, trackingFilters), (includedCategories, excludedCategories), itemPreferences ->
|
) { (searchQuery, categories, favorites), (tracksMap, trackingFilters), (includedCategories, excludedCategories), itemPreferences ->
|
||||||
val showSystemCategory = favorites.fastAny { it.libraryManga.categories.contains(0) }
|
|
||||||
val filteredFavorites = favorites
|
val filteredFavorites = favorites
|
||||||
.applyFilters(
|
.applyFilters(
|
||||||
tracksMap,
|
tracksMap,
|
||||||
|
|
@ -217,7 +217,6 @@ class LibraryScreenModel(
|
||||||
|
|
||||||
LibraryData(
|
LibraryData(
|
||||||
isInitialized = true,
|
isInitialized = true,
|
||||||
showSystemCategory = showSystemCategory,
|
|
||||||
categories = categories,
|
categories = categories,
|
||||||
favorites = filteredFavorites,
|
favorites = filteredFavorites,
|
||||||
tracksMap = tracksMap,
|
tracksMap = tracksMap,
|
||||||
|
|
@ -265,7 +264,6 @@ class LibraryScreenModel(
|
||||||
data.favorites
|
data.favorites
|
||||||
.applyGrouping(
|
.applyGrouping(
|
||||||
data.categories,
|
data.categories,
|
||||||
data.showSystemCategory,
|
|
||||||
// KMK -->
|
// KMK -->
|
||||||
if (filterCategory && includedCategories.isNotEmpty()) {
|
if (filterCategory && includedCategories.isNotEmpty()) {
|
||||||
LibraryGroup.UNGROUPED
|
LibraryGroup.UNGROUPED
|
||||||
|
|
@ -285,7 +283,7 @@ class LibraryScreenModel(
|
||||||
)
|
)
|
||||||
// KMK -->
|
// KMK -->
|
||||||
.filter {
|
.filter {
|
||||||
// Hide empty categories if no active filter or search
|
// Hide empty categories unless the setting is enabled or there are no active filters/search
|
||||||
showEmptyCategoriesSearch || noActiveFilterOrSearch || it.value.isNotEmpty()
|
showEmptyCategoriesSearch || noActiveFilterOrSearch || it.value.isNotEmpty()
|
||||||
}
|
}
|
||||||
.let {
|
.let {
|
||||||
|
|
@ -561,7 +559,6 @@ class LibraryScreenModel(
|
||||||
|
|
||||||
private fun List<LibraryItem>.applyGrouping(
|
private fun List<LibraryItem>.applyGrouping(
|
||||||
categories: List<Category>,
|
categories: List<Category>,
|
||||||
showSystemCategory: Boolean,
|
|
||||||
// KMK -->
|
// KMK -->
|
||||||
groupType: Int,
|
groupType: Int,
|
||||||
showHiddenCategories: Boolean,
|
showHiddenCategories: Boolean,
|
||||||
|
|
@ -570,17 +567,25 @@ class LibraryScreenModel(
|
||||||
// KMK -->
|
// KMK -->
|
||||||
when (groupType) {
|
when (groupType) {
|
||||||
LibraryGroup.BY_DEFAULT -> {
|
LibraryGroup.BY_DEFAULT -> {
|
||||||
|
var showSystemCategory = false
|
||||||
// KMK <--
|
// KMK <--
|
||||||
val groupCache = mutableMapOf</* Category.id */ Long, MutableList</* LibraryItem */ Long>>()
|
val groupCache = mutableMapOf</* Category.id */ Long, MutableList</* LibraryItem */ Long>>()
|
||||||
forEach { item ->
|
forEach { item ->
|
||||||
item.libraryManga.categories.forEach { categoryId ->
|
item.libraryManga.categories.forEach { categoryId ->
|
||||||
|
// KMK -->
|
||||||
|
if (categoryId == UNCATEGORIZED_ID) {
|
||||||
|
showSystemCategory = true
|
||||||
|
}
|
||||||
|
// KMK <--
|
||||||
groupCache.getOrPut(categoryId) { mutableListOf() }.add(item.id)
|
groupCache.getOrPut(categoryId) { mutableListOf() }.add(item.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return categories.fastFilter { showSystemCategory || !it.isSystemCategory }
|
return categories.fastFilter {
|
||||||
// KMK -->
|
(showSystemCategory || !it.isSystemCategory) &&
|
||||||
.fastFilterNot { !showHiddenCategories && it.hidden }
|
// KMK -->
|
||||||
|
(showHiddenCategories || !it.hidden)
|
||||||
// KMK <--
|
// KMK <--
|
||||||
|
}
|
||||||
.associateWith {
|
.associateWith {
|
||||||
groupCache[it.id]?.toList()
|
groupCache[it.id]?.toList()
|
||||||
// KMK -->
|
// KMK -->
|
||||||
|
|
@ -1593,7 +1598,7 @@ class LibraryScreenModel(
|
||||||
suspend fun smartSearchMerge(selectedMangas: PersistentList<Manga>): Long? {
|
suspend fun smartSearchMerge(selectedMangas: PersistentList<Manga>): Long? {
|
||||||
val mergedManga = selectedMangas.firstOrNull { it.source == MERGED_SOURCE_ID }?.let { listOf(it) }
|
val mergedManga = selectedMangas.firstOrNull { it.source == MERGED_SOURCE_ID }?.let { listOf(it) }
|
||||||
?: emptyList()
|
?: emptyList()
|
||||||
val mergingMangas = selectedMangas.filterNot { it.source == MERGED_SOURCE_ID }
|
val mergingMangas = selectedMangas.fastFilterNot { it.source == MERGED_SOURCE_ID }
|
||||||
val toMergeMangas = mergedManga + mergingMangas
|
val toMergeMangas = mergedManga + mergingMangas
|
||||||
if (toMergeMangas.size <= 1) return null
|
if (toMergeMangas.size <= 1) return null
|
||||||
|
|
||||||
|
|
@ -1635,7 +1640,6 @@ class LibraryScreenModel(
|
||||||
@Immutable
|
@Immutable
|
||||||
data class LibraryData(
|
data class LibraryData(
|
||||||
val isInitialized: Boolean = false,
|
val isInitialized: Boolean = false,
|
||||||
val showSystemCategory: Boolean = false,
|
|
||||||
val categories: List<Category> = emptyList(),
|
val categories: List<Category> = emptyList(),
|
||||||
val favorites: List<LibraryItem> = emptyList(),
|
val favorites: List<LibraryItem> = emptyList(),
|
||||||
val tracksMap: Map</* Manga */ Long, List<Track>> = emptyMap(),
|
val tracksMap: Map</* Manga */ Long, List<Track>> = emptyMap(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue