mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Add select inverse action
This commit is contained in:
		| @@ -133,6 +133,15 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att | ||||
|                     } | ||||
|                     controller.invalidateActionMode() | ||||
|                 } | ||||
|  | ||||
|         subscriptions += controller.selectInverseRelay | ||||
|             .filter { it == category.id } | ||||
|             .subscribe { | ||||
|                 adapter.currentItems.forEach { item -> | ||||
|                     controller.toggleSelection(item.manga) | ||||
|                 } | ||||
|                 controller.invalidateActionMode() | ||||
|             } | ||||
|     } | ||||
|  | ||||
|     fun onRecycle() { | ||||
|   | ||||
| @@ -100,6 +100,11 @@ class LibraryController( | ||||
|      */ | ||||
|     val selectAllRelay: PublishRelay<Int> = PublishRelay.create() | ||||
|  | ||||
|     /** | ||||
|      * Relay to notify the library's viewpager to select the inverse | ||||
|      */ | ||||
|     val selectInverseRelay: PublishRelay<Int> = PublishRelay.create() | ||||
|  | ||||
|     /** | ||||
|      * Number of manga per row in grid mode. | ||||
|      */ | ||||
| @@ -407,6 +412,7 @@ class LibraryController( | ||||
|             R.id.action_move_to_category -> showChangeMangaCategoriesDialog() | ||||
|             R.id.action_delete -> showDeleteMangaDialog() | ||||
|             R.id.action_select_all -> selectAllCategoryManga() | ||||
|             R.id.action_select_inverse -> selectInverseCategoryManga() | ||||
|             else -> return false | ||||
|         } | ||||
|         return true | ||||
| @@ -445,6 +451,19 @@ class LibraryController( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Toggles the current selection state for a given manga. | ||||
|      * | ||||
|      * @param manga the manga whose selection to change. | ||||
|      */ | ||||
|     fun toggleSelection(manga: Manga) { | ||||
|         if (selectedMangas.add(manga)) { | ||||
|             selectionRelay.call(LibrarySelectionEvent.Selected(manga)) | ||||
|         } else if (selectedMangas.remove(manga)) { | ||||
|             selectionRelay.call(LibrarySelectionEvent.Unselected(manga)) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Move the selected manga to a list of categories. | ||||
|      */ | ||||
| @@ -501,6 +520,12 @@ class LibraryController( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun selectInverseCategoryManga() { | ||||
|         adapter?.categories?.getOrNull(library_pager.currentItem)?.id?.let { | ||||
|             selectInverseRelay.call(it) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||||
|         if (requestCode == REQUEST_IMAGE_OPEN) { | ||||
|             if (data == null || resultCode != Activity.RESULT_OK) return | ||||
|   | ||||
| @@ -399,6 +399,8 @@ class ChaptersController : NucleusController<ChaptersPresenter>(), | ||||
|  | ||||
|     override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { | ||||
|         when (item.itemId) { | ||||
|             R.id.action_select_all -> selectAll() | ||||
|             R.id.action_select_inverse -> selectInverse() | ||||
|             R.id.action_download -> downloadChapters(getSelectedChapters()) | ||||
|             R.id.action_delete -> showDeleteChaptersConfirmationDialog() | ||||
|             R.id.action_bookmark -> bookmarkChapters(getSelectedChapters(), true) | ||||
| @@ -406,7 +408,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(), | ||||
|             R.id.action_mark_as_read -> markAsRead(getSelectedChapters()) | ||||
|             R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters()) | ||||
|             R.id.action_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters()) | ||||
|             R.id.action_select_all -> selectAll() | ||||
|             else -> return false | ||||
|         } | ||||
|         return true | ||||
| @@ -436,6 +437,15 @@ class ChaptersController : NucleusController<ChaptersPresenter>(), | ||||
|         actionMode?.invalidate() | ||||
|     } | ||||
|  | ||||
|     private fun selectInverse() { | ||||
|         val adapter = adapter ?: return | ||||
|         for (i in 0..adapter.itemCount) { | ||||
|             adapter.toggleSelection(i) | ||||
|         } | ||||
|         actionMode?.invalidate() | ||||
|         adapter.notifyDataSetChanged() | ||||
|     } | ||||
|  | ||||
|     private fun markAsRead(chapters: List<ChapterItem>) { | ||||
|         presenter.markChaptersRead(chapters, true) | ||||
|         if (presenter.preferences.removeAfterMarkedAsRead()) { | ||||
|   | ||||
| @@ -338,6 +338,7 @@ class UpdatesController : NucleusController<UpdatesPresenter>(), | ||||
|     override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { | ||||
|         when (item.itemId) { | ||||
|             R.id.action_select_all -> selectAll() | ||||
|             R.id.action_select_inverse -> selectInverse() | ||||
|             R.id.action_download -> downloadChapters(getSelectedChapters()) | ||||
|             R.id.action_delete -> ConfirmDeleteChaptersDialog(this, getSelectedChapters()) | ||||
|                     .showDialog(router) | ||||
| @@ -364,4 +365,13 @@ class UpdatesController : NucleusController<UpdatesPresenter>(), | ||||
|         adapter.selectAll() | ||||
|         actionMode?.invalidate() | ||||
|     } | ||||
|  | ||||
|     private fun selectInverse() { | ||||
|         val adapter = adapter ?: return | ||||
|         for (i in 0..adapter.itemCount) { | ||||
|             adapter.toggleSelection(i) | ||||
|         } | ||||
|         actionMode?.invalidate() | ||||
|         adapter.notifyDataSetChanged() | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user