From 3bce07e8734b4104f70788232eade97986c11161 Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 22 Sep 2020 22:33:43 -0400 Subject: [PATCH] Minor settings search code cleanup --- .../data/preference/PreferencesHelper.kt | 4 +- .../ui/setting/SettingsMainController.kt | 20 ++++---- .../settingssearch/SettingsSearchAdapter.kt | 6 ++- .../SettingsSearchController.kt | 46 ++++++++++--------- .../settingssearch/SettingsSearchHelper.kt | 9 ++-- .../settingssearch/SettingsSearchHolder.kt | 2 +- .../settingssearch/SettingsSearchItem.kt | 10 +++- .../res/layout/settings_search_controller.xml | 4 +- .../settings_search_controller_card.xml | 28 ++++------- app/src/main/res/values/strings.xml | 1 - 10 files changed, 68 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 62a98904b..ddf513f45 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -253,9 +253,7 @@ class PreferencesHelper(val context: Context) { fun enableDoh() = prefs.getBoolean(Keys.enableDoh, false) - fun lastSearchQuerySearchSettings() = prefs.getString("last_search_query", "") - - fun lastSearchQuerySearchSettings(query: String) = prefs.edit { putString("last_search_query", query) } + fun lastSearchQuerySearchSettings() = flowPrefs.getString("last_search_query", "") fun filterChapterByRead() = prefs.getInt(Keys.defaultChapterFilterByRead, Manga.SHOW_ALL) 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 a7794073f..dc3616aa7 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 @@ -100,16 +100,18 @@ class SettingsMainController : SettingsController() { // Change hint to show global search. searchView.queryHint = applicationContext?.getString(R.string.action_search_settings) - searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { - override fun onMenuItemActionExpand(item: MenuItem?): Boolean { - preferences.lastSearchQuerySearchSettings("") // reset saved search query - router.pushController(SettingsSearchController().withFadeTransaction()) - return true - } + searchItem.setOnActionExpandListener( + object : MenuItem.OnActionExpandListener { + override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + preferences.lastSearchQuerySearchSettings().set("") // reset saved search query + router.pushController(SettingsSearchController().withFadeTransaction()) + return true + } - override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { - return true + override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + return true + } } - }) + ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchAdapter.kt index a0a58e620..d0e5d795b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchAdapter.kt @@ -22,7 +22,11 @@ class SettingsSearchAdapter(val controller: SettingsSearchController) : */ private var bundle = Bundle() - override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: List) { + override fun onBindViewHolder( + holder: RecyclerView.ViewHolder, + position: Int, + payloads: List + ) { super.onBindViewHolder(holder, position, payloads) restoreHolderState(holder) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchController.kt index 3c57e612c..4c975fbdb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchController.kt @@ -27,7 +27,7 @@ class SettingsSearchController : * Adapter containing search results grouped by lang. */ protected var adapter: SettingsSearchAdapter? = null - lateinit var searchView: SearchView + private lateinit var searchView: SearchView init { setHasOptionsMenu(true) @@ -79,30 +79,34 @@ class SettingsSearchController : searchItem.expandActionView() setItems(getResultSet()) - searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { - override fun onMenuItemActionExpand(item: MenuItem?): Boolean { - return true - } + searchItem.setOnActionExpandListener( + object : MenuItem.OnActionExpandListener { + override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + return true + } - override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { - router.popCurrentController() - return false + override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + router.popCurrentController() + return false + } } - }) + ) - searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { - override fun onQueryTextSubmit(query: String?): Boolean { - setItems(getResultSet(query)) - return false + searchView.setOnQueryTextListener( + object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String?): Boolean { + setItems(getResultSet(query)) + return false + } + + override fun onQueryTextChange(newText: String?): Boolean { + setItems(getResultSet(newText)) + return false + } } + ) - override fun onQueryTextChange(newText: String?): Boolean { - setItems(getResultSet(newText)) - return false - } - }) - - searchView.setQuery(presenter.preferences.lastSearchQuerySearchSettings(), true) + searchView.setQuery(presenter.preferences.lastSearchQuerySearchSettings().get(), true) } override fun onViewCreated(view: View) { @@ -160,7 +164,7 @@ class SettingsSearchController : */ override fun onTitleClick(ctrl: SettingsController) { searchView.query.let { - presenter.preferences.lastSearchQuerySearchSettings(it.toString()) + presenter.preferences.lastSearchQuerySearchSettings().set(it.toString()) } router.pushController(ctrl.withFadeTransaction()) 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 57fabdda6..94087415a 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 @@ -24,8 +24,7 @@ import kotlin.reflect.KClass import kotlin.reflect.full.createInstance object SettingsSearchHelper { - var prefSearchResultList: MutableList = mutableListOf() - private set + private var prefSearchResultList: MutableList = mutableListOf() /** * All subclasses of `SettingsController` should be listed here, in order to have their preferences searchable. @@ -79,7 +78,11 @@ object SettingsSearchHelper { * Extracts the data needed from a `Preference` to create a `SettingsSearchResult`, and then adds it to `prefSearchResultList` * Future enhancement: make bold the text matched by the search query. */ - private fun getSettingSearchResult(ctrl: SettingsController, pref: Preference, breadcrumbs: String = "") { + private fun getSettingSearchResult( + ctrl: SettingsController, + pref: Preference, + breadcrumbs: String = "" + ) { when (pref) { is PreferenceGroup -> { val breadcrumbsStr = addLocalizedBreadcrumb(breadcrumbs, "${pref.title}") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt index 469310eca..2781a1de6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt @@ -2,11 +2,11 @@ package eu.kanade.tachiyomi.ui.setting.settingssearch import android.view.View import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder -import kotlin.reflect.full.createInstance import kotlinx.android.synthetic.main.settings_search_controller_card.search_result_pref_breadcrumb import kotlinx.android.synthetic.main.settings_search_controller_card.search_result_pref_summary import kotlinx.android.synthetic.main.settings_search_controller_card.search_result_pref_title import kotlinx.android.synthetic.main.settings_search_controller_card.title_wrapper +import kotlin.reflect.full.createInstance /** * Holder that binds the [SettingsSearchItem] containing catalogue cards. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchItem.kt index cb6417472..212851d88 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchItem.kt @@ -13,7 +13,10 @@ import eu.kanade.tachiyomi.R * @param pref the source for the search results. * @param results the search results. */ -class SettingsSearchItem(val settingsSearchResult: SettingsSearchHelper.SettingsSearchResult, val results: List?) : +class SettingsSearchItem( + val settingsSearchResult: SettingsSearchHelper.SettingsSearchResult, + val results: List? +) : AbstractFlexibleItem() { override fun getLayoutRes(): Int { @@ -25,7 +28,10 @@ class SettingsSearchItem(val settingsSearchResult: SettingsSearchHelper.Settings * * @return holder of view. */ - override fun createViewHolder(view: View, adapter: FlexibleAdapter>): SettingsSearchHolder { + override fun createViewHolder( + view: View, + adapter: FlexibleAdapter> + ): SettingsSearchHolder { return SettingsSearchHolder(view, adapter as SettingsSearchAdapter) } diff --git a/app/src/main/res/layout/settings_search_controller.xml b/app/src/main/res/layout/settings_search_controller.xml index 807f904dd..d3a2df127 100644 --- a/app/src/main/res/layout/settings_search_controller.xml +++ b/app/src/main/res/layout/settings_search_controller.xml @@ -22,8 +22,8 @@ + android:alpha="0.75" + android:background="?attr/colorSurface" /> - + android:background="?attr/selectableItemBackground" + android:orientation="vertical" + android:padding="16dp"> - + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7c8a5a8bf..6231321e5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -412,7 +412,6 @@ Open source licenses Check for updates Updated to v%1$s - Resources Send crash reports