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 ea6f8c9b2..d3a145380 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 9e9a7add5..34b6d8798 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.