From 6872455922b276c25f0c01de3df17b6c402811aa Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 4 Apr 2020 12:10:00 -0400 Subject: [PATCH] Perform catalogue search when genre tag is tapped --- .../browse/BrowseCatalogueController.kt | 2 +- .../ui/manga/info/MangaInfoController.kt | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index 9b8c6ee041..73ec411743 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -313,7 +313,7 @@ open class BrowseCatalogueController(bundle: Bundle) : * * @param newQuery the new query. */ - private fun searchWithQuery(newQuery: String) { + fun searchWithQuery(newQuery: String) { // If text didn't change, do nothing if (presenter.query == newQuery) return diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index d14dba4132..bf133980f3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -43,6 +43,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCatalogueController import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.library.LibraryController @@ -223,7 +224,7 @@ class MangaInfoController : NucleusController(), text = mangaSource setOnClickListener { val sourceManager = Injekt.get() - performLocalSearch(sourceManager.getOrStub(source.id).name) + performSearch(sourceManager.getOrStub(source.id).name) } } else { text = view.context.getString(R.string.unknown) @@ -237,7 +238,7 @@ class MangaInfoController : NucleusController(), manga.genre?.split(", ")?.forEach { genre -> val chip = Chip(view.context).apply { text = genre - setOnClickListener { performLocalSearch(genre) } + setOnClickListener { performSearch(genre) } } manga_genres_tags.addView(chip) @@ -565,16 +566,27 @@ class MangaInfoController : NucleusController(), } /** - * Perform a local search using the provided query. + * Perform a search using the provided query. * - * @param query the search query to pass to the library controller + * @param query the search query to the parent controller */ - private fun performLocalSearch(query: String) { + private fun performSearch(query: String) { val router = parentController?.router ?: return - val firstController = router.backstack.first()?.controller() - if (firstController is LibraryController && router.backstack.size == 2) { - router.handleBack() - firstController.search(query) + + if (router.backstackSize < 2) { + return + } + + val previousController = router.backstack[router.backstackSize - 2].controller() + when (previousController) { + is LibraryController -> { + router.handleBack() + previousController.search(query) + } + is BrowseCatalogueController -> { + router.handleBack() + previousController.searchWithQuery(query) + } } }