Add select inverse action
This commit is contained in:
@@ -133,6 +133,15 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
}
|
||||
controller.invalidateActionMode()
|
||||
}
|
||||
|
||||
subscriptions += controller.selectInverseRelay
|
||||
.filter { it == category.id }
|
||||
.subscribe {
|
||||
adapter.currentItems.forEach { item ->
|
||||
controller.toggleSelection(item.manga)
|
||||
}
|
||||
controller.invalidateActionMode()
|
||||
}
|
||||
}
|
||||
|
||||
fun onRecycle() {
|
||||
|
||||
@@ -100,6 +100,11 @@ class LibraryController(
|
||||
*/
|
||||
val selectAllRelay: PublishRelay<Int> = PublishRelay.create()
|
||||
|
||||
/**
|
||||
* Relay to notify the library's viewpager to select the inverse
|
||||
*/
|
||||
val selectInverseRelay: PublishRelay<Int> = PublishRelay.create()
|
||||
|
||||
/**
|
||||
* Number of manga per row in grid mode.
|
||||
*/
|
||||
@@ -407,6 +412,7 @@ class LibraryController(
|
||||
R.id.action_move_to_category -> showChangeMangaCategoriesDialog()
|
||||
R.id.action_delete -> showDeleteMangaDialog()
|
||||
R.id.action_select_all -> selectAllCategoryManga()
|
||||
R.id.action_select_inverse -> selectInverseCategoryManga()
|
||||
else -> return false
|
||||
}
|
||||
return true
|
||||
@@ -445,6 +451,19 @@ class LibraryController(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the current selection state for a given manga.
|
||||
*
|
||||
* @param manga the manga whose selection to change.
|
||||
*/
|
||||
fun toggleSelection(manga: Manga) {
|
||||
if (selectedMangas.add(manga)) {
|
||||
selectionRelay.call(LibrarySelectionEvent.Selected(manga))
|
||||
} else if (selectedMangas.remove(manga)) {
|
||||
selectionRelay.call(LibrarySelectionEvent.Unselected(manga))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the selected manga to a list of categories.
|
||||
*/
|
||||
@@ -501,6 +520,12 @@ class LibraryController(
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectInverseCategoryManga() {
|
||||
adapter?.categories?.getOrNull(library_pager.currentItem)?.id?.let {
|
||||
selectInverseRelay.call(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == REQUEST_IMAGE_OPEN) {
|
||||
if (data == null || resultCode != Activity.RESULT_OK) return
|
||||
|
||||
Reference in New Issue
Block a user