From 8deca3b63a5a9348933fa8c5fcfaa13bb85311e4 Mon Sep 17 00:00:00 2001 From: Hunter Nickel Date: Sat, 12 Jun 2021 07:48:11 -0600 Subject: [PATCH] Added text to category changing dialog when shown with no categories (#5345) * Added text to ChangeMangaCategoriesDialog if invoked with empty category list * Change dialog text, add negative button, and change positive button to open CategoryController * Tiny bit of code cleanup and reorganizing --- .../ui/library/ChangeMangaCategoriesDialog.kt | 34 ++++++++++++++----- .../tachiyomi/ui/library/LibraryController.kt | 10 ++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt index 395a6e63e0..f0dad157be 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/ChangeMangaCategoriesDialog.kt @@ -9,6 +9,8 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.ui.base.controller.DialogController +import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.ui.category.CategoryController class ChangeMangaCategoriesDialog(bundle: Bundle? = null) : DialogController(bundle) where T : Controller, T : ChangeMangaCategoriesDialog.Listener { @@ -32,16 +34,30 @@ class ChangeMangaCategoriesDialog(bundle: Bundle? = null) : override fun onCreateDialog(savedViewState: Bundle?): Dialog { return MaterialDialog(activity!!) .title(R.string.action_move_category) - .listItemsMultiChoice( - items = categories.map { it.name }, - initialSelection = preselected.toIntArray(), - allowEmptySelection = true - ) { _, selections, _ -> - val newCategories = selections.map { categories[it] } - (targetController as? Listener)?.updateCategoriesForMangas(mangas, newCategories) - } - .positiveButton(android.R.string.ok) .negativeButton(android.R.string.cancel) + .apply { + if (categories.isNotEmpty()) { + listItemsMultiChoice( + items = categories.map { it.name }, + initialSelection = preselected.toIntArray(), + allowEmptySelection = true + ) { _, selections, _ -> + val newCategories = selections.map { categories[it] } + (targetController as? Listener)?.updateCategoriesForMangas(mangas, newCategories) + } + .positiveButton(android.R.string.ok) + } else { + message(R.string.information_empty_category_dialog) + .positiveButton(R.string.action_edit_categories) { + if (targetController is LibraryController) { + val libController = targetController as LibraryController + libController.clearSelection() + } + router.popCurrentController() + router.pushController(CategoryController().withFadeTransaction()) + } + } + } } interface Listener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index fe0d33185b..7ba8bb7b99 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -526,6 +526,16 @@ class LibraryController( } } + /** + * Clear all of the manga currently selected, and + * invalidate the action mode to revert the top toolbar + */ + fun clearSelection() { + selectedMangas.clear() + selectionRelay.call(LibrarySelectionEvent.Cleared()) + invalidateActionMode() + } + /** * Move the selected manga to a list of categories. */ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4b2f399c7b..8487d812a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -729,6 +729,7 @@ Nothing read recently Your library is empty. Add series to your library from Browse. You have no categories. Tap the plus button to create one for organizing your library. + You don\'t have any categories yet. Failed to bypass Cloudflare WebView is required for Tachiyomi