Mark common categories when moving them. Closes #135
This commit is contained in:
parent
78314077bb
commit
81bce8ef76
2 changed files with 13 additions and 6 deletions
|
@ -385,10 +385,15 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||||
* @param mangas the manga list to move.
|
* @param mangas the manga list to move.
|
||||||
*/
|
*/
|
||||||
private fun moveMangasToCategories(mangas: List<Manga>) {
|
private fun moveMangasToCategories(mangas: List<Manga>) {
|
||||||
|
val categories = presenter.categories
|
||||||
|
val commonCategoriesIndexes = presenter.getCommonCategories(mangas)
|
||||||
|
.map { categories.indexOf(it) }
|
||||||
|
.toTypedArray()
|
||||||
|
|
||||||
MaterialDialog.Builder(activity)
|
MaterialDialog.Builder(activity)
|
||||||
.title(R.string.action_move_category)
|
.title(R.string.action_move_category)
|
||||||
.items(presenter.getCategoryNames())
|
.items(categories.map { it.name })
|
||||||
.itemsCallbackMultiChoice(null) { dialog, positions, text ->
|
.itemsCallbackMultiChoice(commonCategoriesIndexes) { dialog, positions, text ->
|
||||||
presenter.moveMangasToCategories(positions, mangas)
|
presenter.moveMangasToCategories(positions, mangas)
|
||||||
destroyActionModeIfNeeded()
|
destroyActionModeIfNeeded()
|
||||||
true
|
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> {
|
fun getCommonCategories(mangas: List<Manga>) = mangas.toSet()
|
||||||
return categories.map { it.name }
|
.map { db.getCategoriesForManga(it).executeAsBlocking() }
|
||||||
}
|
.reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the selected manga from the library.
|
* Remove the selected manga from the library.
|
||||||
|
|
Reference in a new issue