Mark common categories when moving them. Closes #135

This commit is contained in:
len 2016-04-18 19:17:05 +02:00
parent 78314077bb
commit 81bce8ef76
2 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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.