mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 00:01:54 +01:00
- retain search query when navigating *away* from SettingsSearchController
- keep `searchItem` in `expandActionView` state until user goes back (fixes the empty view in `SettingsSearchSearchController` issue)
This commit is contained in:
parent
381c061ebc
commit
18061d1077
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.net.toUri
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.tfcporciuncula.flow.FlowSharedPreferences
|
||||
@ -249,4 +250,8 @@ class PreferencesHelper(val context: Context) {
|
||||
fun trustedSignatures() = flowPrefs.getStringSet("trusted_signatures", emptySet())
|
||||
|
||||
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) }
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.setting
|
||||
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -13,11 +14,6 @@ import eu.kanade.tachiyomi.util.preference.onClick
|
||||
import eu.kanade.tachiyomi.util.preference.preference
|
||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
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
|
||||
|
||||
class SettingsMainController : SettingsController() {
|
||||
|
||||
@ -104,14 +100,16 @@ class SettingsMainController : SettingsController() {
|
||||
// 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<QueryTextEvent.QueryChanged>()
|
||||
.onEach {
|
||||
router.pushController(
|
||||
SettingsSearchController().withFadeTransaction()
|
||||
)
|
||||
searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||
preferences.lastSearchQuerySearchSettings("") // reset saved search query
|
||||
router.pushController(SettingsSearchController().withFadeTransaction())
|
||||
return true
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ class SettingsSearchController :
|
||||
* Adapter containing search results grouped by lang.
|
||||
*/
|
||||
protected var adapter: SettingsSearchAdapter? = null
|
||||
lateinit var searchView: SearchView
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
@ -69,7 +70,7 @@ class SettingsSearchController :
|
||||
|
||||
// Initialize search menu
|
||||
val searchItem = menu.findItem(R.id.action_search)
|
||||
val searchView = searchItem.actionView as SearchView
|
||||
searchView = searchItem.actionView as SearchView
|
||||
searchView.maxWidth = Int.MAX_VALUE
|
||||
|
||||
// Change hint to show "search settings."
|
||||
@ -80,22 +81,17 @@ class SettingsSearchController :
|
||||
|
||||
searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||
searchView.onActionViewExpanded() // Required to show the query in the view
|
||||
setItems(getResultSet())
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||
searchView.onActionViewCollapsed() // Required to show the query in the view
|
||||
router.popCurrentController()
|
||||
return true
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
searchItem.collapseActionView()
|
||||
setTitle(query) // Update toolbar title
|
||||
setItems(getResultSet(query))
|
||||
return false
|
||||
}
|
||||
@ -105,6 +101,8 @@ class SettingsSearchController :
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
searchView.setQuery(presenter.preferences.lastSearchQuerySearchSettings(), true)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View) {
|
||||
@ -161,6 +159,10 @@ class SettingsSearchController :
|
||||
* Opens a catalogue with the given search.
|
||||
*/
|
||||
override fun onTitleClick(ctrl: SettingsController) {
|
||||
searchView.query.let {
|
||||
presenter.preferences.lastSearchQuerySearchSettings(it.toString())
|
||||
}
|
||||
|
||||
router.pushController(ctrl.withFadeTransaction())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user