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,16 +100,18 @@ 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(
override fun onMenuItemActionExpand(item: MenuItem?): Boolean { object : MenuItem.OnActionExpandListener {
preferences.lastSearchQuerySearchSettings("") // reset saved search query override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
router.pushController(SettingsSearchController().withFadeTransaction()) preferences.lastSearchQuerySearchSettings().set("") // reset saved search query
return true router.pushController(SettingsSearchController().withFadeTransaction())
} return true
}
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,30 +79,34 @@ class SettingsSearchController :
searchItem.expandActionView() searchItem.expandActionView()
setItems(getResultSet()) setItems(getResultSet())
searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { searchItem.setOnActionExpandListener(
override fun onMenuItemActionExpand(item: MenuItem?): Boolean { object : MenuItem.OnActionExpandListener {
return true override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
} return true
}
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
router.popCurrentController() router.popCurrentController()
return false return false
}
} }
}) )
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { searchView.setOnQueryTextListener(
override fun onQueryTextSubmit(query: String?): Boolean { object : SearchView.OnQueryTextListener {
setItems(getResultSet(query)) override fun onQueryTextSubmit(query: String?): Boolean {
return false setItems(getResultSet(query))
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
setItems(getResultSet(newText))
return false
}
} }
)
override fun onQueryTextChange(newText: String?): Boolean { searchView.setQuery(presenter.preferences.lastSearchQuerySearchSettings().get(), true)
setItems(getResultSet(newText))
return false
}
})
searchView.setQuery(presenter.preferences.lastSearchQuerySearchSettings(), 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>