Mark common categories when moving them. Closes #135
Cette révision appartient à :
Parent
78314077bb
révision
81bce8ef76
2 fichiers modifiés avec 13 ajouts et 6 suppressions
|
@ -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.
|
||||
|
|
Référencer dans un nouveau ticket