Minor settings search code cleanup

This commit is contained in:
arkon 2020-09-22 22:33:43 -04:00
parent 766f9e37b5
commit 3bce07e873
10 changed files with 68 additions and 62 deletions

View file

@ -253,9 +253,7 @@ class PreferencesHelper(val context: Context) {
fun enableDoh() = prefs.getBoolean(Keys.enableDoh, false) fun enableDoh() = prefs.getBoolean(Keys.enableDoh, false)
fun lastSearchQuerySearchSettings() = prefs.getString("last_search_query", "") fun lastSearchQuerySearchSettings() = flowPrefs.getString("last_search_query", "")
fun lastSearchQuerySearchSettings(query: String) = prefs.edit { putString("last_search_query", query) }
fun filterChapterByRead() = prefs.getInt(Keys.defaultChapterFilterByRead, Manga.SHOW_ALL) fun filterChapterByRead() = prefs.getInt(Keys.defaultChapterFilterByRead, Manga.SHOW_ALL)

View file

@ -100,9 +100,10 @@ class SettingsMainController : SettingsController() {
// Change hint to show global search. // Change hint to show global search.
searchView.queryHint = applicationContext?.getString(R.string.action_search_settings) searchView.queryHint = applicationContext?.getString(R.string.action_search_settings)
searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { searchItem.setOnActionExpandListener(
object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem?): Boolean { override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
preferences.lastSearchQuerySearchSettings("") // reset saved search query preferences.lastSearchQuerySearchSettings().set("") // reset saved search query
router.pushController(SettingsSearchController().withFadeTransaction()) router.pushController(SettingsSearchController().withFadeTransaction())
return true return true
} }
@ -110,6 +111,7 @@ class SettingsMainController : SettingsController() {
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
return true return true
} }
}) }
)
} }
} }

View file

@ -22,7 +22,11 @@ class SettingsSearchAdapter(val controller: SettingsSearchController) :
*/ */
private var bundle = Bundle() private var bundle = Bundle()
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: List<Any?>) { override fun onBindViewHolder(
holder: RecyclerView.ViewHolder,
position: Int,
payloads: List<Any?>
) {
super.onBindViewHolder(holder, position, payloads) super.onBindViewHolder(holder, position, payloads)
restoreHolderState(holder) restoreHolderState(holder)
} }

View file

@ -27,7 +27,7 @@ class SettingsSearchController :
* Adapter containing search results grouped by lang. * Adapter containing search results grouped by lang.
*/ */
protected var adapter: SettingsSearchAdapter? = null protected var adapter: SettingsSearchAdapter? = null
lateinit var searchView: SearchView private lateinit var searchView: SearchView
init { init {
setHasOptionsMenu(true) setHasOptionsMenu(true)
@ -79,7 +79,8 @@ class SettingsSearchController :
searchItem.expandActionView() searchItem.expandActionView()
setItems(getResultSet()) setItems(getResultSet())
searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { searchItem.setOnActionExpandListener(
object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem?): Boolean { override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
return true return true
} }
@ -88,9 +89,11 @@ class SettingsSearchController :
router.popCurrentController() router.popCurrentController()
return false return false
} }
}) }
)
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { searchView.setOnQueryTextListener(
object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean { override fun onQueryTextSubmit(query: String?): Boolean {
setItems(getResultSet(query)) setItems(getResultSet(query))
return false return false
@ -100,9 +103,10 @@ class SettingsSearchController :
setItems(getResultSet(newText)) setItems(getResultSet(newText))
return false return false
} }
}) }
)
searchView.setQuery(presenter.preferences.lastSearchQuerySearchSettings(), true) searchView.setQuery(presenter.preferences.lastSearchQuerySearchSettings().get(), true)
} }
override fun onViewCreated(view: View) { override fun onViewCreated(view: View) {
@ -160,7 +164,7 @@ class SettingsSearchController :
*/ */
override fun onTitleClick(ctrl: SettingsController) { override fun onTitleClick(ctrl: SettingsController) {
searchView.query.let { searchView.query.let {
presenter.preferences.lastSearchQuerySearchSettings(it.toString()) presenter.preferences.lastSearchQuerySearchSettings().set(it.toString())
} }
router.pushController(ctrl.withFadeTransaction()) router.pushController(ctrl.withFadeTransaction())

View file

@ -24,8 +24,7 @@ import kotlin.reflect.KClass
import kotlin.reflect.full.createInstance import kotlin.reflect.full.createInstance
object SettingsSearchHelper { object SettingsSearchHelper {
var prefSearchResultList: MutableList<SettingsSearchResult> = mutableListOf() private var prefSearchResultList: MutableList<SettingsSearchResult> = mutableListOf()
private set
/** /**
* All subclasses of `SettingsController` should be listed here, in order to have their preferences searchable. * 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` * 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. * 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) { when (pref) {
is PreferenceGroup -> { is PreferenceGroup -> {
val breadcrumbsStr = addLocalizedBreadcrumb(breadcrumbs, "${pref.title}") val breadcrumbsStr = addLocalizedBreadcrumb(breadcrumbs, "${pref.title}")

View file

@ -2,11 +2,11 @@ package eu.kanade.tachiyomi.ui.setting.settingssearch
import android.view.View import android.view.View
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder 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_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_summary
import kotlinx.android.synthetic.main.settings_search_controller_card.search_result_pref_title 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 kotlinx.android.synthetic.main.settings_search_controller_card.title_wrapper
import kotlin.reflect.full.createInstance
/** /**
* Holder that binds the [SettingsSearchItem] containing catalogue cards. * Holder that binds the [SettingsSearchItem] containing catalogue cards.

View file

@ -13,7 +13,10 @@ import eu.kanade.tachiyomi.R
* @param pref the source for the search results. * @param pref the source for the search results.
* @param results the search results. * @param results the search results.
*/ */
class SettingsSearchItem(val settingsSearchResult: SettingsSearchHelper.SettingsSearchResult, val results: List<SettingsSearchItem>?) : class SettingsSearchItem(
val settingsSearchResult: SettingsSearchHelper.SettingsSearchResult,
val results: List<SettingsSearchItem>?
) :
AbstractFlexibleItem<SettingsSearchHolder>() { AbstractFlexibleItem<SettingsSearchHolder>() {
override fun getLayoutRes(): Int { override fun getLayoutRes(): Int {
@ -25,7 +28,10 @@ class SettingsSearchItem(val settingsSearchResult: SettingsSearchHelper.Settings
* *
* @return holder of view. * @return holder of view.
*/ */
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): SettingsSearchHolder { override fun createViewHolder(
view: View,
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
): SettingsSearchHolder {
return SettingsSearchHolder(view, adapter as SettingsSearchAdapter) return SettingsSearchHolder(view, adapter as SettingsSearchAdapter)
} }

View file

@ -22,8 +22,8 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorSurface" android:alpha="0.75"
android:alpha="0.75" /> android:background="?attr/colorSurface" />
<ProgressBar <ProgressBar
style="?android:attr/progressBarStyleLarge" style="?android:attr/progressBarStyleLarge"

View file

@ -1,45 +1,35 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/title_wrapper" android:id="@+id/title_wrapper"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="48dp" android:background="?attr/selectableItemBackground"
android:layout_marginTop="16dp" android:orientation="vertical"
android:layout_marginBottom="16dp" android:padding="16dp">
android:background="?attr/selectableItemBackground">
<TextView <TextView
android:id="@+id/search_result_pref_title" android:id="@+id/search_result_pref_title"
style="@style/TextAppearance.Regular.SubHeading" style="@style/TextAppearance.Regular.SubHeading"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" /> tools:text="Title" />
<TextView <TextView
android:id="@+id/search_result_pref_summary" android:id="@+id/search_result_pref_summary"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_result_pref_title"
tools:text="Summary" /> tools:text="Summary" />
<TextView <TextView
android:id="@+id/search_result_pref_breadcrumb" android:id="@+id/search_result_pref_breadcrumb"
style="@style/TextAppearance.Regular.Caption" style="@style/TextAppearance.Regular.Caption"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_result_pref_summary"
tools:text="Location" /> tools:text="Location" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

View file

@ -412,7 +412,6 @@
<string name="licenses">Open source licenses</string> <string name="licenses">Open source licenses</string>
<string name="check_for_updates">Check for updates</string> <string name="check_for_updates">Check for updates</string>
<string name="updated_version">Updated to v%1$s</string> <string name="updated_version">Updated to v%1$s</string>
<string name="about_resources">Resources</string>
<!-- ACRA --> <!-- ACRA -->
<string name="pref_enable_acra">Send crash reports</string> <string name="pref_enable_acra">Send crash reports</string>