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
This commit is contained in:
Hunter Nickel 2021-06-12 07:48:11 -06:00 committed by GitHub
parent 9b967177c5
commit 8deca3b63a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 9 deletions

View File

@ -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<T>(bundle: Bundle? = null) :
DialogController(bundle) where T : Controller, T : ChangeMangaCategoriesDialog.Listener {
@ -32,16 +34,30 @@ class ChangeMangaCategoriesDialog<T>(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 {

View File

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

View File

@ -729,6 +729,7 @@
<string name="information_no_recent_manga">Nothing read recently</string>
<string name="information_empty_library">Your library is empty. Add series to your library from Browse.</string>
<string name="information_empty_category">You have no categories. Tap the plus button to create one for organizing your library.</string>
<string name="information_empty_category_dialog">You don\'t have any categories yet.</string>
<string name="information_cloudflare_bypass_failure">Failed to bypass Cloudflare</string>
<!-- Do not translate "WebView" -->
<string name="information_webview_required">WebView is required for Tachiyomi</string>