mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 03:07:25 +01:00
Fix selection in library (#8233)
This commit is contained in:
parent
9c4051a5ba
commit
ea092fa175
@ -11,9 +11,9 @@ data class LibraryManga(
|
|||||||
val chapterFetchedAt: Long,
|
val chapterFetchedAt: Long,
|
||||||
val lastRead: Long,
|
val lastRead: Long,
|
||||||
) {
|
) {
|
||||||
val totalChapters
|
val id: Long = manga.id
|
||||||
get() = readCount + unreadCount
|
|
||||||
|
|
||||||
val hasStarted
|
val totalChapters = readCount + unreadCount
|
||||||
get() = readCount > 0
|
|
||||||
|
val hasStarted = readCount > 0
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.compose.ui.util.fastAny
|
||||||
import eu.kanade.domain.library.model.LibraryManga
|
import eu.kanade.domain.library.model.LibraryManga
|
||||||
import eu.kanade.domain.manga.model.MangaCover
|
import eu.kanade.domain.manga.model.MangaCover
|
||||||
import eu.kanade.tachiyomi.ui.library.LibraryItem
|
import eu.kanade.tachiyomi.ui.library.LibraryItem
|
||||||
@ -49,7 +50,7 @@ fun LibraryComfortableGrid(
|
|||||||
showUnreadBadge = showUnreadBadges,
|
showUnreadBadge = showUnreadBadges,
|
||||||
showLocalBadge = showLocalBadges,
|
showLocalBadge = showLocalBadges,
|
||||||
showLanguageBadge = showLanguageBadges,
|
showLanguageBadge = showLanguageBadges,
|
||||||
isSelected = libraryItem.libraryManga in selection,
|
isSelected = selection.fastAny { it.id == libraryItem.libraryManga.id },
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
onLongClick = onLongClick,
|
onLongClick = onLongClick,
|
||||||
)
|
)
|
||||||
|
@ -23,6 +23,7 @@ import androidx.compose.ui.graphics.Shadow
|
|||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.compose.ui.util.fastAny
|
||||||
import eu.kanade.domain.library.model.LibraryManga
|
import eu.kanade.domain.library.model.LibraryManga
|
||||||
import eu.kanade.tachiyomi.ui.library.LibraryItem
|
import eu.kanade.tachiyomi.ui.library.LibraryItem
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ fun LibraryCompactGrid(
|
|||||||
showUnreadBadge = showUnreadBadges,
|
showUnreadBadge = showUnreadBadges,
|
||||||
showLocalBadge = showLocalBadges,
|
showLocalBadge = showLocalBadges,
|
||||||
showLanguageBadge = showLanguageBadges,
|
showLanguageBadge = showLanguageBadges,
|
||||||
isSelected = libraryItem.libraryManga in selection,
|
isSelected = selection.fastAny { it.id == libraryItem.libraryManga.id },
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
onLongClick = onLongClick,
|
onLongClick = onLongClick,
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.lazy.grid.items
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.util.fastAny
|
||||||
import eu.kanade.domain.library.model.LibraryManga
|
import eu.kanade.domain.library.model.LibraryManga
|
||||||
import eu.kanade.tachiyomi.ui.library.LibraryItem
|
import eu.kanade.tachiyomi.ui.library.LibraryItem
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ fun LibraryCoverOnlyGrid(
|
|||||||
showUnreadBadge = showUnreadBadges,
|
showUnreadBadge = showUnreadBadges,
|
||||||
showLocalBadge = showLocalBadges,
|
showLocalBadge = showLocalBadges,
|
||||||
showLanguageBadge = showLanguageBadges,
|
showLanguageBadge = showLanguageBadges,
|
||||||
isSelected = libraryItem.libraryManga in selection,
|
isSelected = selection.fastAny { it.id == libraryItem.libraryManga.id },
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
onLongClick = onLongClick,
|
onLongClick = onLongClick,
|
||||||
)
|
)
|
||||||
|
@ -18,6 +18,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.util.fastAny
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import eu.kanade.domain.library.model.LibraryManga
|
import eu.kanade.domain.library.model.LibraryManga
|
||||||
import eu.kanade.domain.manga.model.MangaCover
|
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.FastScrollLazyColumn
|
||||||
import eu.kanade.presentation.components.MangaCover.Square
|
import eu.kanade.presentation.components.MangaCover.Square
|
||||||
import eu.kanade.presentation.util.horizontalPadding
|
import eu.kanade.presentation.util.horizontalPadding
|
||||||
import eu.kanade.presentation.util.plus
|
|
||||||
import eu.kanade.presentation.util.selectedBackground
|
import eu.kanade.presentation.util.selectedBackground
|
||||||
import eu.kanade.presentation.util.verticalPadding
|
import eu.kanade.presentation.util.verticalPadding
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
@ -70,7 +70,7 @@ fun LibraryList(
|
|||||||
showUnreadBadge = showUnreadBadges,
|
showUnreadBadge = showUnreadBadges,
|
||||||
showLocalBadge = showLocalBadges,
|
showLocalBadge = showLocalBadges,
|
||||||
showLanguageBadge = showLanguageBadges,
|
showLanguageBadge = showLanguageBadges,
|
||||||
isSelected = libraryItem.libraryManga in selection,
|
isSelected = selection.fastAny { it.id == libraryItem.libraryManga.id },
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
onLongClick = onLongClick,
|
onLongClick = onLongClick,
|
||||||
)
|
)
|
||||||
|
@ -588,19 +588,14 @@ class LibraryPresenter(
|
|||||||
state.selection = emptyList()
|
state.selection = emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeSelected(mutableList: MutableList<LibraryManga>, manga: LibraryManga): Boolean {
|
|
||||||
if (selection.fastAny { it.manga.id == manga.manga.id }) {
|
|
||||||
return mutableList.remove(manga)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toggleSelection(manga: LibraryManga) {
|
fun toggleSelection(manga: LibraryManga) {
|
||||||
val mutableList = state.selection.toMutableList()
|
state.selection = selection.toMutableList().apply {
|
||||||
if (!removeSelected(mutableList, manga)) {
|
if (fastAny { it.id == manga.id }) {
|
||||||
mutableList.add(manga)
|
removeAll { it.id == manga.id }
|
||||||
|
} else {
|
||||||
|
add(manga)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
state.selection = mutableList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -608,22 +603,22 @@ class LibraryPresenter(
|
|||||||
* same category as the given manga
|
* same category as the given manga
|
||||||
*/
|
*/
|
||||||
fun toggleRangeSelection(manga: LibraryManga) {
|
fun toggleRangeSelection(manga: LibraryManga) {
|
||||||
val mutableList = state.selection.toMutableList()
|
state.selection = selection.toMutableList().apply {
|
||||||
if (!removeSelected(mutableList, manga) && mutableList.fastAny
|
val lastSelected = lastOrNull()
|
||||||
{ it.category == manga.category }
|
if (lastSelected == null || lastSelected.category != manga.category) {
|
||||||
) {
|
add(manga)
|
||||||
|
return@apply
|
||||||
|
}
|
||||||
val items = (loadedManga[manga.category] ?: emptyList()).map { it.libraryManga }
|
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 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)
|
true -> items.subList(curMangaIndex, lastMangaIndex)
|
||||||
false -> items.subList(lastMangaIndex, curMangaIndex + 1)
|
false -> items.subList(lastMangaIndex, curMangaIndex + 1)
|
||||||
|
}.filterNot { it.id in selectedIds }
|
||||||
|
addAll(newSelections)
|
||||||
}
|
}
|
||||||
mutableList.addAll(newList.filterNot { it in selection })
|
|
||||||
} else {
|
|
||||||
mutableList.add(manga)
|
|
||||||
}
|
|
||||||
state.selection = mutableList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun selectAll(index: Int) {
|
fun selectAll(index: Int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user