Manual fix for multi-selection
This commit is contained in:
parent
0752790690
commit
f8caecb546
@ -845,64 +845,67 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val items = produceState(initialValue = unfiltered, unfiltered, searchQuery) {
|
val items = produceState(initialValue = unfiltered, unfiltered, searchQuery) {
|
||||||
val query = searchQuery
|
|
||||||
value = withIOContext {
|
value = withIOContext {
|
||||||
if (unfiltered.isNotEmpty() && !query.isNullOrBlank()) {
|
filterLibrary(unfiltered, searchQuery)
|
||||||
// Prepare filter object
|
|
||||||
val parsedQuery = searchEngine.parseQuery(query)
|
|
||||||
val mangaWithMetaIds = getIdsOfFavoriteMangaWithMetadata.await()
|
|
||||||
val tracks = if (loggedServices.isNotEmpty()) {
|
|
||||||
getTracks.await(unfiltered.map { it.libraryManga.manga.id }.distinct())
|
|
||||||
} else {
|
|
||||||
emptyMap()
|
|
||||||
}
|
|
||||||
val sources = unfiltered
|
|
||||||
.distinctBy { it.libraryManga.manga.source }
|
|
||||||
.mapNotNull { sourceManager.get(it.libraryManga.manga.source) }
|
|
||||||
.associateBy { it.id }
|
|
||||||
unfiltered.asFlow().cancellable().filter { item ->
|
|
||||||
val mangaId = item.libraryManga.manga.id
|
|
||||||
val sourceId = item.libraryManga.manga.source
|
|
||||||
if (isMetadataSource(sourceId)) {
|
|
||||||
if (mangaWithMetaIds.binarySearch(mangaId) < 0) {
|
|
||||||
// No meta? Filter using title
|
|
||||||
filterManga(
|
|
||||||
queries = parsedQuery,
|
|
||||||
libraryManga = item.libraryManga,
|
|
||||||
tracks = tracks[mangaId],
|
|
||||||
source = sources[sourceId],
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val tags = getSearchTags.await(mangaId)
|
|
||||||
val titles = getSearchTitles.await(mangaId)
|
|
||||||
filterManga(
|
|
||||||
queries = parsedQuery,
|
|
||||||
libraryManga = item.libraryManga,
|
|
||||||
tracks = tracks[mangaId],
|
|
||||||
source = sources[sourceId],
|
|
||||||
checkGenre = false,
|
|
||||||
searchTags = tags,
|
|
||||||
searchTitles = titles,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
filterManga(
|
|
||||||
queries = parsedQuery,
|
|
||||||
libraryManga = item.libraryManga,
|
|
||||||
tracks = tracks[mangaId],
|
|
||||||
source = sources[sourceId],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.toList()
|
|
||||||
} else {
|
|
||||||
unfiltered
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.value
|
return items.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun filterLibrary(unfiltered: List<LibraryItem>, query: String?): List<LibraryItem> {
|
||||||
|
return if (unfiltered.isNotEmpty() && !query.isNullOrBlank()) {
|
||||||
|
// Prepare filter object
|
||||||
|
val parsedQuery = searchEngine.parseQuery(query)
|
||||||
|
val mangaWithMetaIds = getIdsOfFavoriteMangaWithMetadata.await()
|
||||||
|
val tracks = if (loggedServices.isNotEmpty()) {
|
||||||
|
getTracks.await(unfiltered.map { it.libraryManga.manga.id }.distinct())
|
||||||
|
} else {
|
||||||
|
emptyMap()
|
||||||
|
}
|
||||||
|
val sources = unfiltered
|
||||||
|
.distinctBy { it.libraryManga.manga.source }
|
||||||
|
.mapNotNull { sourceManager.get(it.libraryManga.manga.source) }
|
||||||
|
.associateBy { it.id }
|
||||||
|
unfiltered.asFlow().cancellable().filter { item ->
|
||||||
|
val mangaId = item.libraryManga.manga.id
|
||||||
|
val sourceId = item.libraryManga.manga.source
|
||||||
|
if (isMetadataSource(sourceId)) {
|
||||||
|
if (mangaWithMetaIds.binarySearch(mangaId) < 0) {
|
||||||
|
// No meta? Filter using title
|
||||||
|
filterManga(
|
||||||
|
queries = parsedQuery,
|
||||||
|
libraryManga = item.libraryManga,
|
||||||
|
tracks = tracks[mangaId],
|
||||||
|
source = sources[sourceId],
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val tags = getSearchTags.await(mangaId)
|
||||||
|
val titles = getSearchTitles.await(mangaId)
|
||||||
|
filterManga(
|
||||||
|
queries = parsedQuery,
|
||||||
|
libraryManga = item.libraryManga,
|
||||||
|
tracks = tracks[mangaId],
|
||||||
|
source = sources[sourceId],
|
||||||
|
checkGenre = false,
|
||||||
|
searchTags = tags,
|
||||||
|
searchTitles = titles,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filterManga(
|
||||||
|
queries = parsedQuery,
|
||||||
|
libraryManga = item.libraryManga,
|
||||||
|
tracks = tracks[mangaId],
|
||||||
|
source = sources[sourceId],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}.toList()
|
||||||
|
} else {
|
||||||
|
unfiltered
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun filterManga(
|
private fun filterManga(
|
||||||
queries: List<QueryComponent>,
|
queries: List<QueryComponent>,
|
||||||
libraryManga: LibraryManga,
|
libraryManga: LibraryManga,
|
||||||
@ -1025,49 +1028,55 @@ class LibraryPresenter(
|
|||||||
* same category as the given manga
|
* same category as the given manga
|
||||||
*/
|
*/
|
||||||
fun toggleRangeSelection(manga: LibraryManga) {
|
fun toggleRangeSelection(manga: LibraryManga) {
|
||||||
state.selection = selection.toMutableList().apply {
|
presenterScope.launchIO {
|
||||||
val lastSelected = lastOrNull()
|
state.selection = selection.toMutableList().apply {
|
||||||
if (lastSelected?.category != manga.category) {
|
val lastSelected = lastOrNull()
|
||||||
add(manga)
|
if (lastSelected?.category != manga.category) {
|
||||||
return@apply
|
add(manga)
|
||||||
|
return@apply
|
||||||
|
}
|
||||||
|
val items = loadedManga[manga.category].orEmpty().run {
|
||||||
|
filterLibrary(this, searchQuery)
|
||||||
|
}.fastMap { it.libraryManga }
|
||||||
|
val lastMangaIndex = items.indexOf(lastSelected)
|
||||||
|
val curMangaIndex = items.indexOf(manga)
|
||||||
|
val selectedIds = fastMap { it.id }
|
||||||
|
val newSelections = when (lastMangaIndex >= curMangaIndex + 1) {
|
||||||
|
true -> items.subList(curMangaIndex, lastMangaIndex)
|
||||||
|
false -> items.subList(lastMangaIndex, curMangaIndex + 1)
|
||||||
|
}.filterNot { it.id in selectedIds }
|
||||||
|
addAll(newSelections)
|
||||||
}
|
}
|
||||||
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 }
|
|
||||||
val newSelections = when (lastMangaIndex >= curMangaIndex + 1) {
|
|
||||||
true -> items.subList(curMangaIndex, lastMangaIndex)
|
|
||||||
false -> items.subList(lastMangaIndex, curMangaIndex + 1)
|
|
||||||
}.filterNot { it.id in selectedIds }
|
|
||||||
addAll(newSelections)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun selectAll(index: Int) {
|
fun selectAll(index: Int) {
|
||||||
state.selection = state.selection.toMutableList().apply {
|
presenterScope.launchIO {
|
||||||
val categoryId = categories.getOrNull(index)?.id ?: -1
|
state.selection = state.selection.toMutableList().apply {
|
||||||
val items = loadedManga[categoryId].orEmpty().apply {
|
val categoryId = categories.getOrNull(index)?.id ?: -1
|
||||||
if (searchQuery.isNullOrBlank()) toList() else filter { it.filter(searchQuery!!) }
|
val items = loadedManga[categoryId].orEmpty().run {
|
||||||
}.fastMap { it.libraryManga }
|
filterLibrary(this, searchQuery)
|
||||||
val selectedIds = fastMap { it.id }
|
}.fastMap { it.libraryManga }
|
||||||
val newSelections = items.filterNot { it.id in selectedIds }
|
val selectedIds = fastMap { it.id }
|
||||||
addAll(newSelections)
|
val newSelections = items.filterNot { it.id in selectedIds }
|
||||||
|
addAll(newSelections)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun invertSelection(index: Int) {
|
fun invertSelection(index: Int) {
|
||||||
state.selection = selection.toMutableList().apply {
|
presenterScope.launchIO {
|
||||||
val categoryId = categories[index].id
|
state.selection = selection.toMutableList().apply {
|
||||||
val items = loadedManga[categoryId].orEmpty().apply {
|
val categoryId = categories[index].id
|
||||||
if (searchQuery.isNullOrBlank()) toList() else filter { it.filter(searchQuery!!) }
|
val items = loadedManga[categoryId].orEmpty().run {
|
||||||
}.fastMap { it.libraryManga }
|
filterLibrary(this, searchQuery)
|
||||||
val selectedIds = fastMap { it.id }
|
}.fastMap { it.libraryManga }
|
||||||
val (toRemove, toAdd) = items.partition { it.id in selectedIds }
|
val selectedIds = fastMap { it.id }
|
||||||
val toRemoveIds = toRemove.fastMap { it.id }
|
val (toRemove, toAdd) = items.partition { it.id in selectedIds }
|
||||||
removeAll { it.id in toRemoveIds }
|
val toRemoveIds = toRemove.fastMap { it.id }
|
||||||
addAll(toAdd)
|
removeAll { it.id in toRemoveIds }
|
||||||
|
addAll(toAdd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user