mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 08:51:48 +01:00
cleanup done
This commit is contained in:
parent
1bee855766
commit
289b076864
@ -70,7 +70,7 @@ fun LibraryScreen(
|
|||||||
onChangeCurrentPage = { presenter.activeCategory = it },
|
onChangeCurrentPage = { presenter.activeCategory = it },
|
||||||
onMangaClicked = onMangaClicked,
|
onMangaClicked = onMangaClicked,
|
||||||
onToggleSelection = { presenter.toggleSelection(it) },
|
onToggleSelection = { presenter.toggleSelection(it) },
|
||||||
onToggleMultiSelection = { presenter.toggleMultiSelection(it) },
|
onToggleSelectBetween = { presenter.toggleSelectBetween(it) },
|
||||||
onRefresh = onClickRefresh,
|
onRefresh = onClickRefresh,
|
||||||
onGlobalSearchClicked = onGlobalSearchClicked,
|
onGlobalSearchClicked = onGlobalSearchClicked,
|
||||||
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
|
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
|
||||||
|
@ -45,7 +45,7 @@ fun LibraryContent(
|
|||||||
onChangeCurrentPage: (Int) -> Unit,
|
onChangeCurrentPage: (Int) -> Unit,
|
||||||
onMangaClicked: (Long) -> Unit,
|
onMangaClicked: (Long) -> Unit,
|
||||||
onToggleSelection: (LibraryManga) -> Unit,
|
onToggleSelection: (LibraryManga) -> Unit,
|
||||||
onToggleMultiSelection: (LibraryManga) -> Unit,
|
onToggleSelectBetween: (LibraryManga) -> Unit,
|
||||||
onRefresh: (Category?) -> Boolean,
|
onRefresh: (Category?) -> Boolean,
|
||||||
onGlobalSearchClicked: () -> Unit,
|
onGlobalSearchClicked: () -> Unit,
|
||||||
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
|
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
|
||||||
@ -86,7 +86,7 @@ fun LibraryContent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val onLongClickManga = { manga: LibraryManga ->
|
val onLongClickManga = { manga: LibraryManga ->
|
||||||
onToggleMultiSelection(manga)
|
onToggleSelectBetween(manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
SwipeRefresh(
|
SwipeRefresh(
|
||||||
|
@ -663,41 +663,41 @@ class LibraryPresenter(
|
|||||||
state.selection = emptyList()
|
state.selection = emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
|
||||||
state.selection = mutableList
|
|
||||||
} else {
|
|
||||||
mutableList.add(manga)
|
mutableList.add(manga)
|
||||||
|
}
|
||||||
state.selection = mutableList
|
state.selection = mutableList
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun toggleMultiSelection(manga: LibraryManga) {
|
/**
|
||||||
|
* Selects all mangas between and including the given manga and the last pressed manga from the
|
||||||
|
* same category as the given manga
|
||||||
|
*/
|
||||||
|
fun toggleSelectBetween(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.fastAny{ it.category == manga.category }) {
|
||||||
state.selection = mutableList
|
|
||||||
} else if (mutableList.fastAny{ it.category == manga.category }) {
|
|
||||||
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(mutableList.findLast { it.category == manga.category })
|
|
||||||
val curMangaIndex = items.indexOf(manga)
|
val curMangaIndex = items.indexOf(manga)
|
||||||
|
|
||||||
val newList = when (lastMangaIndex >= curMangaIndex + 1) {
|
val newList = 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)
|
||||||
}
|
}
|
||||||
|
mutableList.apply { addAll(newList.filterNot { it in selection }.map { it }) }
|
||||||
state.selection = state.selection.toMutableList().apply {
|
|
||||||
addAll(newList.filterNot { it in selection }.map { it })
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mutableList.add(manga)
|
mutableList.add(manga)
|
||||||
state.selection = mutableList
|
|
||||||
}
|
}
|
||||||
|
state.selection = mutableList
|
||||||
}
|
}
|
||||||
|
|
||||||
fun selectAll(index: Int) {
|
fun selectAll(index: Int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user