mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Mark common categories when moving them. Closes #135
This commit is contained in:
		| @@ -385,10 +385,15 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback | ||||
|      * @param mangas the manga list to move. | ||||
|      */ | ||||
|     private fun moveMangasToCategories(mangas: List<Manga>) { | ||||
|         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 | ||||
|   | ||||
| @@ -220,11 +220,13 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 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<String> { | ||||
|         return categories.map { it.name } | ||||
|     } | ||||
|     fun getCommonCategories(mangas: List<Manga>) = mangas.toSet() | ||||
|             .map { db.getCategoriesForManga(it).executeAsBlocking() } | ||||
|             .reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) } | ||||
|  | ||||
|     /** | ||||
|      * Remove the selected manga from the library. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user