From 84d1454f6e551b9199b4760832c42c9e02f40043 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 24 Nov 2019 22:06:50 -0800 Subject: [PATCH] Clicking tag now does a local search --- .../tachiyomi/ui/library/LibraryController.kt | 4 ++++ .../ui/manga/chapter/ChaptersController.kt | 5 +++++ .../ui/manga/info/MangaInfoController.kt | 19 +++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) 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 cd3af33433..567530ea87 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 @@ -386,6 +386,10 @@ class LibraryController( searchItem.fixExpand() } + fun search(query:String) { + this.query = query + } + override fun onPrepareOptionsMenu(menu: Menu) { val navView = navView ?: return diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 6783f964fd..7232cdda9d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -373,6 +373,11 @@ class ChaptersController() : NucleusController(), actionMode = null } + override fun onDetach(view: View) { + destroyActionModeIfNeeded() + super.onDetach(view) + } + override fun onMenuItemClick(position: Int, item: MenuItem) { val chapter = adapter?.getItem(position) ?: return val chapters = listOf(chapter) 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 7f744e23fe..77847e80dd 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 @@ -44,6 +44,7 @@ import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog +import eu.kanade.tachiyomi.ui.library.LibraryController import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.doOnApplyWindowInsets @@ -143,7 +144,7 @@ class MangaInfoController : NucleusController(), .toString(), R.string.description) } - //manga_genres_tags.setOnTagClickListener { tag -> performGlobalSearch(tag) } + manga_genres_tags.setOnTagClickListener { tag -> performLocalSearch(tag) } manga_cover.longClicks().subscribeUntilDestroy { copyToClipboard(view.context.getString(R.string.title), presenter.manga.title, R.string.manga_info_full_title_label) @@ -616,11 +617,25 @@ class MangaInfoController : NucleusController(), * * @param query the search query to pass to the search controller */ - fun performGlobalSearch(query: String) { + private fun performGlobalSearch(query: String) { val router = parentController?.router ?: return router.pushController(CatalogueSearchController(query).withFadeTransaction()) } + /** + * Perform a local search using the provided query. + * + * @param query the search query to pass to the library controller + */ + private fun performLocalSearch(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) + } + } + /** * Create shortcut using ShortcutManager. *