From 3ebea4c3057b4f49b1a9f68747d3ad836f4a6acb Mon Sep 17 00:00:00 2001 From: mpm11011 Date: Wed, 26 Aug 2020 23:07:59 -0400 Subject: [PATCH] Add search button to MoreController, stop infinite recursion. --- .../tachiyomi/ui/more/MoreController.kt | 38 +++++++++++++++++++ .../ui/setting/SettingsMainController.kt | 2 +- .../settingssearch/SettingsSearchHelper.kt | 4 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index 7f357e727f..55261c3afa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -2,6 +2,9 @@ package eu.kanade.tachiyomi.ui.more import android.content.Context import android.util.AttributeSet +import android.view.Menu +import android.view.MenuInflater +import androidx.appcompat.widget.SearchView import androidx.preference.Preference import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R @@ -15,6 +18,8 @@ import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.ui.download.DownloadController import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.SettingsMainController +import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchController +import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchHelper import eu.kanade.tachiyomi.util.preference.add import eu.kanade.tachiyomi.util.preference.iconRes import eu.kanade.tachiyomi.util.preference.iconTint @@ -26,6 +31,11 @@ import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.openInBrowser +import kotlinx.coroutines.flow.filterIsInstance +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import reactivecircus.flowbinding.appcompat.QueryTextEvent +import reactivecircus.flowbinding.appcompat.queryTextEvents import rx.android.schedulers.AndroidSchedulers import uy.kohesive.injekt.injectLazy @@ -39,6 +49,7 @@ class MoreController : private var downloadQueueSize: Int = 0 override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { + SettingsSearchHelper.initPreferenceSearchResultCollection(context, preferenceManager) titleRes = R.string.label_more val tintColor = context.getResourceColor(R.attr.colorAccent) @@ -140,6 +151,33 @@ class MoreController : } } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + // Inflate menu + inflater.inflate(R.menu.settings_main, menu) + + // Initialize search option. + val searchItem = menu.findItem(R.id.action_search) + val searchView = searchItem.actionView as SearchView + searchView.maxWidth = Int.MAX_VALUE + + // Change hint to show global search. + searchView.queryHint = applicationContext?.getString(R.string.action_search_settings) + + // Create query listener which opens the global search view. + searchView.queryTextEvents() + .filterIsInstance() + .onEach { + performSettingsSearch(it.queryText.toString()) + } + .launchIn(scope) + } + + private fun performSettingsSearch(query: String) { + router.pushController( + SettingsSearchController(query).withFadeTransaction() + ) + } + companion object { private const val URL_HELP = "https://tachiyomi.org/help/" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt index c3a4f0e9cb..8e85c618ca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt @@ -105,7 +105,7 @@ class SettingsMainController : SettingsController() { searchView.maxWidth = Int.MAX_VALUE // Change hint to show global search. - searchView.queryHint = applicationContext?.getString(R.string.action_global_search_hint) + searchView.queryHint = applicationContext?.getString(R.string.action_search_settings) // Create query listener which opens the global search view. searchView.queryTextEvents() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt index 1f8d6458c2..f57fc2ee69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt @@ -8,7 +8,6 @@ import androidx.preference.PreferenceManager import eu.kanade.tachiyomi.ui.browse.extension.ExtensionFilterController import eu.kanade.tachiyomi.ui.browse.source.SourceFilterController import eu.kanade.tachiyomi.ui.more.AboutController -import eu.kanade.tachiyomi.ui.more.MoreController import eu.kanade.tachiyomi.ui.setting.SettingsAdvancedController import eu.kanade.tachiyomi.ui.setting.SettingsBackupController import eu.kanade.tachiyomi.ui.setting.SettingsBrowseController @@ -43,8 +42,7 @@ object SettingsSearchHelper { SettingsTrackingController::class, ExtensionFilterController::class, SourceFilterController::class, - AboutController::class, - MoreController::class + AboutController::class ) /**