From 3061f198e9dc381e6294e05447b9798dcea885e4 Mon Sep 17 00:00:00 2001 From: Quang Kieu Date: Fri, 11 Nov 2022 15:01:48 -0500 Subject: [PATCH] Temporally Fix #8287 (#8493) --- .../tachiyomi/ui/library/LibraryPresenter.kt | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index a70cc9ee7c..7ab62f1a69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -547,14 +547,7 @@ class LibraryPresenter( loadedManga[categoryId] ?: emptyList() } return remember(unfiltered, searchQuery) { - val query = searchQuery - if (query.isNullOrBlank().not()) { - unfiltered.filter { - it.filter(query!!) - } - } else { - unfiltered - } + if (searchQuery.isNullOrBlank()) unfiltered else unfiltered.filter { it.filter(searchQuery!!) } } } @@ -583,7 +576,9 @@ class LibraryPresenter( add(manga) return@apply } - val items = loadedManga[manga.category].orEmpty().fastMap { it.libraryManga } + val items = loadedManga[manga.category].orEmpty().apply { + if (searchQuery.isNullOrBlank()) toList() else filter { it.filter(searchQuery!!) } + }.fastMap { it.libraryManga } val lastMangaIndex = items.indexOf(lastSelected) val curMangaIndex = items.indexOf(manga) val selectedIds = fastMap { it.id } @@ -597,8 +592,10 @@ class LibraryPresenter( fun selectAll(index: Int) { state.selection = state.selection.toMutableList().apply { - val categoryId = categories[index].id - val items = loadedManga[categoryId].orEmpty().fastMap { it.libraryManga } + val categoryId = categories.getOrNull(index)?.id ?: -1 + val items = loadedManga[categoryId].orEmpty().apply { + if (searchQuery.isNullOrBlank()) toList() else filter { it.filter(searchQuery!!) } + }.fastMap { it.libraryManga } val selectedIds = fastMap { it.id } val newSelections = items.filterNot { it.id in selectedIds } addAll(newSelections) @@ -608,7 +605,9 @@ class LibraryPresenter( fun invertSelection(index: Int) { state.selection = selection.toMutableList().apply { val categoryId = categories[index].id - val items = loadedManga[categoryId].orEmpty().fastMap { it.libraryManga } + val items = loadedManga[categoryId].orEmpty().apply { + if (searchQuery.isNullOrBlank()) toList() else filter { it.filter(searchQuery!!) } + }.fastMap { it.libraryManga } val selectedIds = fastMap { it.id } val (toRemove, toAdd) = items.partition { it.id in selectedIds } val toRemoveIds = toRemove.fastMap { it.id }