mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-18 00:19:18 +01:00
Range selection in library (#8186)
* logic and a bit of cleanup
* cleanup done
* grammar fix
* fixing format
* Auto stash before checking out "HEAD"
* Revert "Auto stash before checking out "HEAD""
This reverts commit 202374a36f
.
* Update app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
Co-authored-by: arkon <arkon@users.noreply.github.com>
* cleanup
Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
parent
4e544005fe
commit
e1adb89ff8
@ -96,6 +96,7 @@ fun LibraryScreen(
|
|||||||
onChangeCurrentPage = { presenter.activeCategory = it },
|
onChangeCurrentPage = { presenter.activeCategory = it },
|
||||||
onMangaClicked = onMangaClicked,
|
onMangaClicked = onMangaClicked,
|
||||||
onToggleSelection = { presenter.toggleSelection(it) },
|
onToggleSelection = { presenter.toggleSelection(it) },
|
||||||
|
onToggleRangeSelection = { presenter.toggleRangeSelection(it) },
|
||||||
onRefresh = onClickRefresh,
|
onRefresh = onClickRefresh,
|
||||||
onGlobalSearchClicked = onGlobalSearchClicked,
|
onGlobalSearchClicked = onGlobalSearchClicked,
|
||||||
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
|
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
|
||||||
|
@ -40,6 +40,7 @@ fun LibraryContent(
|
|||||||
onChangeCurrentPage: (Int) -> Unit,
|
onChangeCurrentPage: (Int) -> Unit,
|
||||||
onMangaClicked: (Long) -> Unit,
|
onMangaClicked: (Long) -> Unit,
|
||||||
onToggleSelection: (LibraryManga) -> Unit,
|
onToggleSelection: (LibraryManga) -> Unit,
|
||||||
|
onToggleRangeSelection: (LibraryManga) -> Unit,
|
||||||
onRefresh: (Category?) -> Boolean,
|
onRefresh: (Category?) -> Boolean,
|
||||||
onGlobalSearchClicked: () -> Unit,
|
onGlobalSearchClicked: () -> Unit,
|
||||||
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
|
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
|
||||||
@ -80,7 +81,7 @@ fun LibraryContent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val onLongClickManga = { manga: LibraryManga ->
|
val onLongClickManga = { manga: LibraryManga ->
|
||||||
onToggleSelection(manga)
|
onToggleRangeSelection(manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
SwipeRefresh(
|
SwipeRefresh(
|
||||||
|
@ -662,10 +662,38 @@ 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()
|
val mutableList = state.selection.toMutableList()
|
||||||
if (selection.fastAny { it.manga.id == manga.manga.id }) {
|
if (!removeSelected(mutableList, manga)) {
|
||||||
mutableList.remove(manga)
|
mutableList.add(manga)
|
||||||
|
}
|
||||||
|
state.selection = mutableList
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects all mangas between and including the given manga and the last pressed manga from the
|
||||||
|
* 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 }
|
||||||
|
) {
|
||||||
|
val items = (loadedManga[manga.category] ?: emptyList()).map { it.libraryManga }
|
||||||
|
val lastMangaIndex = items.indexOf(mutableList.findLast { it.category == manga.category })
|
||||||
|
val curMangaIndex = items.indexOf(manga)
|
||||||
|
val newList = when (lastMangaIndex >= curMangaIndex + 1) {
|
||||||
|
true -> items.subList(curMangaIndex, lastMangaIndex)
|
||||||
|
false -> items.subList(lastMangaIndex, curMangaIndex + 1)
|
||||||
|
}
|
||||||
|
mutableList.addAll(newList.filterNot { it in selection })
|
||||||
} else {
|
} else {
|
||||||
mutableList.add(manga)
|
mutableList.add(manga)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user