From f30622424a12c7897798ab6eef8e62ba80d9e955 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 18 Jan 2020 20:33:43 -0500 Subject: [PATCH] Add select all menu option for library category Based on https://github.com/Jays2Kings/tachiyomiJ2K/commit/ae5ad2a9a6fa3a4f2139712564a0b561ed00b37a --- .../tachiyomi/ui/library/LibraryCategoryView.kt | 9 +++++++++ .../kanade/tachiyomi/ui/library/LibraryController.kt | 12 ++++++++++++ app/src/main/res/menu/library_selection.xml | 7 ++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 5293d8c18d..0467da3e71 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -124,6 +124,15 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att subscriptions += controller.selectionRelay .subscribe { onSelectionChanged(it) } + + subscriptions += controller.selectAllRelay + .filter { it == category.id } + .subscribe { + adapter.currentItems.forEach { item -> + controller.setSelection(item.manga, true) + } + controller.invalidateActionMode() + } } fun onRecycle() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index e7aa967f4f..dbe8cd2b66 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -94,6 +94,11 @@ class LibraryController( */ val libraryMangaRelay: BehaviorRelay = BehaviorRelay.create() + /** + * Relay to notify the library's viewpager to select all manga + */ + val selectAllRelay: PublishRelay = PublishRelay.create() + /** * Number of manga per row in grid mode. */ @@ -409,6 +414,7 @@ class LibraryController( } R.id.action_move_to_category -> showChangeMangaCategoriesDialog() R.id.action_delete -> showDeleteMangaDialog() + R.id.action_select_all -> selectAllCategoryManga() else -> return false } return true @@ -496,6 +502,12 @@ class LibraryController( } } + private fun selectAllCategoryManga() { + adapter?.categories?.getOrNull(library_pager.currentItem)?.id?.let { + selectAllRelay.call(it) + } + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == REQUEST_IMAGE_OPEN) { if (data == null || resultCode != Activity.RESULT_OK) return diff --git a/app/src/main/res/menu/library_selection.xml b/app/src/main/res/menu/library_selection.xml index 357acfe48c..0cced57b5d 100644 --- a/app/src/main/res/menu/library_selection.xml +++ b/app/src/main/res/menu/library_selection.xml @@ -18,4 +18,9 @@ android:icon="@drawable/ic_delete_white_24dp" app:showAsAction="ifRoom"/> - \ No newline at end of file + + +