diff --git a/app/src/main/java/eu/kanade/domain/library/model/LibraryManga.kt b/app/src/main/java/eu/kanade/domain/library/model/LibraryManga.kt index 74a41357b..9b0cf1103 100644 --- a/app/src/main/java/eu/kanade/domain/library/model/LibraryManga.kt +++ b/app/src/main/java/eu/kanade/domain/library/model/LibraryManga.kt @@ -11,9 +11,9 @@ data class LibraryManga( val chapterFetchedAt: Long, val lastRead: Long, ) { - val totalChapters - get() = readCount + unreadCount + val id: Long = manga.id - val hasStarted - get() = readCount > 0 + val totalChapters = readCount + unreadCount + + val hasStarted = readCount > 0 } diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt index 15bf4b365..1078397a6 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.compose.ui.util.fastAny import eu.kanade.domain.library.model.LibraryManga import eu.kanade.domain.manga.model.MangaCover import eu.kanade.tachiyomi.ui.library.LibraryItem @@ -49,7 +50,7 @@ fun LibraryComfortableGrid( showUnreadBadge = showUnreadBadges, showLocalBadge = showLocalBadges, showLanguageBadge = showLanguageBadges, - isSelected = libraryItem.libraryManga in selection, + isSelected = selection.fastAny { it.id == libraryItem.libraryManga.id }, onClick = onClick, onLongClick = onLongClick, ) diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt index 2e2add29a..8e747f2db 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt @@ -23,6 +23,7 @@ import androidx.compose.ui.graphics.Shadow import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.compose.ui.util.fastAny import eu.kanade.domain.library.model.LibraryManga import eu.kanade.tachiyomi.ui.library.LibraryItem @@ -58,7 +59,7 @@ fun LibraryCompactGrid( showUnreadBadge = showUnreadBadges, showLocalBadge = showLocalBadges, showLanguageBadge = showLanguageBadges, - isSelected = libraryItem.libraryManga in selection, + isSelected = selection.fastAny { it.id == libraryItem.libraryManga.id }, onClick = onClick, onLongClick = onLongClick, ) diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt index fb1fa5902..61e1e2f5b 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.lazy.grid.items import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.util.fastAny import eu.kanade.domain.library.model.LibraryManga import eu.kanade.tachiyomi.ui.library.LibraryItem @@ -41,7 +42,7 @@ fun LibraryCoverOnlyGrid( showUnreadBadge = showUnreadBadges, showLocalBadge = showLocalBadges, showLanguageBadge = showLanguageBadges, - isSelected = libraryItem.libraryManga in selection, + isSelected = selection.fastAny { it.id == libraryItem.libraryManga.id }, onClick = onClick, onLongClick = onLongClick, ) diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt index c56ad4bd8..a8f405773 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt @@ -18,6 +18,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import androidx.compose.ui.util.fastAny import androidx.compose.ui.zIndex import eu.kanade.domain.library.model.LibraryManga import eu.kanade.domain.manga.model.MangaCover @@ -25,7 +26,6 @@ import eu.kanade.presentation.components.BadgeGroup import eu.kanade.presentation.components.FastScrollLazyColumn import eu.kanade.presentation.components.MangaCover.Square import eu.kanade.presentation.util.horizontalPadding -import eu.kanade.presentation.util.plus import eu.kanade.presentation.util.selectedBackground import eu.kanade.presentation.util.verticalPadding import eu.kanade.tachiyomi.R @@ -70,7 +70,7 @@ fun LibraryList( showUnreadBadge = showUnreadBadges, showLocalBadge = showLocalBadges, showLanguageBadge = showLanguageBadges, - isSelected = libraryItem.libraryManga in selection, + isSelected = selection.fastAny { it.id == libraryItem.libraryManga.id }, onClick = onClick, onLongClick = onLongClick, ) 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 015d797a8..423611f7c 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 @@ -588,19 +588,14 @@ class LibraryPresenter( state.selection = emptyList() } - private fun removeSelected(mutableList: MutableList, manga: LibraryManga): Boolean { - if (selection.fastAny { it.manga.id == manga.manga.id }) { - return mutableList.remove(manga) - } - return false - } - fun toggleSelection(manga: LibraryManga) { - val mutableList = state.selection.toMutableList() - if (!removeSelected(mutableList, manga)) { - mutableList.add(manga) + state.selection = selection.toMutableList().apply { + if (fastAny { it.id == manga.id }) { + removeAll { it.id == manga.id } + } else { + add(manga) + } } - state.selection = mutableList } /** @@ -608,22 +603,22 @@ class LibraryPresenter( * same category as the given manga */ fun toggleRangeSelection(manga: LibraryManga) { - val mutableList = state.selection.toMutableList() - if (!removeSelected(mutableList, manga) && mutableList.fastAny - { it.category == manga.category } - ) { + state.selection = selection.toMutableList().apply { + val lastSelected = lastOrNull() + if (lastSelected == null || lastSelected.category != manga.category) { + add(manga) + return@apply + } val items = (loadedManga[manga.category] ?: emptyList()).map { it.libraryManga } - val lastMangaIndex = items.indexOf(mutableList.findLast { it.category == manga.category }) + val lastMangaIndex = items.indexOf(lastSelected) val curMangaIndex = items.indexOf(manga) - val newList = when (lastMangaIndex >= curMangaIndex + 1) { + val selectedIds = map { it.id } + val newSelections = when (lastMangaIndex >= curMangaIndex + 1) { true -> items.subList(curMangaIndex, lastMangaIndex) false -> items.subList(lastMangaIndex, curMangaIndex + 1) - } - mutableList.addAll(newList.filterNot { it in selection }) - } else { - mutableList.add(manga) + }.filterNot { it.id in selectedIds } + addAll(newSelections) } - state.selection = mutableList } fun selectAll(index: Int) {