From 81bce8ef7633373e3256a7c03eeadb2e1827aae2 Mon Sep 17 00:00:00 2001 From: len Date: Mon, 18 Apr 2016 19:17:05 +0200 Subject: [PATCH] Mark common categories when moving them. Closes #135 --- .../eu/kanade/tachiyomi/ui/library/LibraryFragment.kt | 9 +++++++-- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 10 ++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt index ea6f8c9b2b..d3a1453807 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt @@ -385,10 +385,15 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback * @param mangas the manga list to move. */ private fun moveMangasToCategories(mangas: List) { + val categories = presenter.categories + val commonCategoriesIndexes = presenter.getCommonCategories(mangas) + .map { categories.indexOf(it) } + .toTypedArray() + MaterialDialog.Builder(activity) .title(R.string.action_move_category) - .items(presenter.getCategoryNames()) - .itemsCallbackMultiChoice(null) { dialog, positions, text -> + .items(categories.map { it.name }) + .itemsCallbackMultiChoice(commonCategoriesIndexes) { dialog, positions, text -> presenter.moveMangasToCategories(positions, mangas) destroyActionModeIfNeeded() true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 9e9a7add53..34b6d8798f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -220,11 +220,13 @@ class LibraryPresenter : BasePresenter() { } /** - * Get the category names as a list. + * Returns the common categories for the given list of manga. + * + * @param mangas the list of manga. */ - fun getCategoryNames(): List { - return categories.map { it.name } - } + fun getCommonCategories(mangas: List) = mangas.toSet() + .map { db.getCategoriesForManga(it).executeAsBlocking() } + .reduce { set1: Iterable, set2 -> set1.intersect(set2) } /** * Remove the selected manga from the library.