From 0fdb19c07d0c05431558a15d13b2cb9f22de8a89 Mon Sep 17 00:00:00 2001 From: jobobby04 Date: Thu, 4 Jun 2020 22:38:42 -0400 Subject: [PATCH] Global Search click title to search in Source (#3265) * Global Search click to search in source * Add requested changes --- .../browse/source/browse/BrowseSourceController.kt | 9 +++++++-- .../ui/browse/source/browse/BrowseSourcePresenter.kt | 3 ++- .../source/globalsearch/GlobalSearchAdapter.kt | 7 +++++++ .../source/globalsearch/GlobalSearchController.kt | 12 +++++++++++- .../browse/source/globalsearch/GlobalSearchHolder.kt | 6 ++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index f9034bed1b..640a890912 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -67,9 +67,13 @@ open class BrowseSourceController(bundle: Bundle) : FlexibleAdapter.EndlessScrollListener, ChangeMangaCategoriesDialog.Listener { - constructor(source: CatalogueSource) : this( + constructor(source: CatalogueSource, searchQuery: String? = null) : this( Bundle().apply { putLong(SOURCE_ID_KEY, source.id) + + if (searchQuery != null) { + putString(SEARCH_QUERY_KEY, searchQuery) + } } ) @@ -114,7 +118,7 @@ open class BrowseSourceController(bundle: Bundle) : } override fun createPresenter(): BrowseSourcePresenter { - return BrowseSourcePresenter(args.getLong(SOURCE_ID_KEY)) + return BrowseSourcePresenter(args.getLong(SOURCE_ID_KEY), args.getString(SEARCH_QUERY_KEY)) } override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { @@ -604,5 +608,6 @@ open class BrowseSourceController(bundle: Bundle) : protected companion object { const val SOURCE_ID_KEY = "sourceId" + const val SEARCH_QUERY_KEY = "searchQuery" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index cce518d2d3..43268682ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -44,6 +44,7 @@ import uy.kohesive.injekt.api.get */ open class BrowseSourcePresenter( private val sourceId: Long, + private val searchQuery: String? = null, private val sourceManager: SourceManager = Injekt.get(), private val db: DatabaseHelper = Injekt.get(), private val prefs: PreferencesHelper = Injekt.get(), @@ -58,7 +59,7 @@ open class BrowseSourcePresenter( /** * Query from the view. */ - var query = "" + var query = searchQuery ?: "" private set /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchAdapter.kt index 6d29abcfb6..d9739a8136 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchAdapter.kt @@ -5,6 +5,7 @@ import android.os.Parcelable import android.util.SparseArray import androidx.recyclerview.widget.RecyclerView import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.kanade.tachiyomi.source.CatalogueSource /** * Adapter that holds the search cards. @@ -14,6 +15,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter class GlobalSearchAdapter(val controller: GlobalSearchController) : FlexibleAdapter(null, controller, true) { + val titleClickListener: OnTitleClickListener = controller + /** * Bundle where the view state of the holders is saved. */ @@ -68,6 +71,10 @@ class GlobalSearchAdapter(val controller: GlobalSearchController) : } } + interface OnTitleClickListener { + fun onTitleClick(source: CatalogueSource) + } + private companion object { const val HOLDER_BUNDLE_KEY = "holder_bundle" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt index 68656da18c..276ca32701 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.databinding.GlobalSearchControllerBinding import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.manga.MangaController import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.launchIn @@ -31,7 +32,8 @@ open class GlobalSearchController( protected val initialQuery: String? = null, protected val extensionFilter: String? = null ) : NucleusController(), - GlobalSearchCardAdapter.OnMangaClickListener { + GlobalSearchCardAdapter.OnMangaClickListener, + GlobalSearchAdapter.OnTitleClickListener { /** * Adapter containing search results grouped by lang. @@ -190,4 +192,12 @@ open class GlobalSearchController( fun onMangaInitialized(source: CatalogueSource, manga: Manga) { getHolder(source)?.setImage(manga) } + + /** + * Opens a catalogue with the given search. + */ + override fun onTitleClick(source: CatalogueSource) { + presenter.preferences.lastUsedCatalogueSource().set(source.id) + router.pushController(BrowseSourceController(source, presenter.query).withFadeTransaction()) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchHolder.kt index f1cb5a74cd..7669c3245a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchHolder.kt @@ -31,6 +31,12 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) : // Set layout horizontal. recycler.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.HORIZONTAL, false) recycler.adapter = mangaAdapter + + title.setOnClickListener { + adapter.getItem(bindingAdapterPosition)?.let { + adapter.titleClickListener.onTitleClick(it.source) + } + } } /**