mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
fix: search query stays the old one during back presses
This commit is contained in:
parent
ac5bf43846
commit
acc43b815f
@ -58,6 +58,7 @@ class MainActivity : BaseActivity() {
|
|||||||
private val subscriptionsViewModel: SubscriptionsViewModel by viewModels()
|
private val subscriptionsViewModel: SubscriptionsViewModel by viewModels()
|
||||||
|
|
||||||
private var savedSearchQuery: String? = null
|
private var savedSearchQuery: String? = null
|
||||||
|
private var shouldOpenSuggestions = true
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -283,6 +284,8 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String?): Boolean {
|
override fun onQueryTextChange(newText: String?): Boolean {
|
||||||
|
if (!shouldOpenSuggestions) return true
|
||||||
|
|
||||||
// Prevent navigation when search view is collapsed
|
// Prevent navigation when search view is collapsed
|
||||||
if (searchView.isIconified ||
|
if (searchView.isIconified ||
|
||||||
binding.bottomNav.menu.children.any {
|
binding.bottomNav.menu.children.any {
|
||||||
@ -356,6 +359,15 @@ class MainActivity : BaseActivity() {
|
|||||||
return super.onCreateOptionsMenu(menu)
|
return super.onCreateOptionsMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the query text in the search bar without opening the search suggestions
|
||||||
|
*/
|
||||||
|
fun setQuerySilent(query: String) {
|
||||||
|
shouldOpenSuggestions = false
|
||||||
|
searchView.setQuery(query, false)
|
||||||
|
shouldOpenSuggestions = true
|
||||||
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
// Handle action bar item clicks here. The action bar will
|
// Handle action bar item clicks here. The action bar will
|
||||||
// automatically handle clicks on the Home/Up button, so long
|
// automatically handle clicks on the Home/Up button, so long
|
||||||
|
@ -23,6 +23,7 @@ import com.github.libretube.extensions.TAG
|
|||||||
import com.github.libretube.extensions.hideKeyboard
|
import com.github.libretube.extensions.hideKeyboard
|
||||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||||
import com.github.libretube.helpers.PreferenceHelper
|
import com.github.libretube.helpers.PreferenceHelper
|
||||||
|
import com.github.libretube.ui.activities.MainActivity
|
||||||
import com.github.libretube.ui.adapters.SearchAdapter
|
import com.github.libretube.ui.adapters.SearchAdapter
|
||||||
import com.github.libretube.ui.dialogs.ShareDialog
|
import com.github.libretube.ui.dialogs.ShareDialog
|
||||||
import com.github.libretube.util.TextUtils
|
import com.github.libretube.util.TextUtils
|
||||||
@ -60,6 +61,10 @@ class SearchResultFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
// fixes a bug that the search query will stay the old one when searching for multiple
|
||||||
|
// different queries in a row and navigating to the previous ones through back presses
|
||||||
|
(context as MainActivity).setQuerySilent(query)
|
||||||
|
|
||||||
binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext())
|
binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext())
|
||||||
|
|
||||||
// add the query to the history
|
// add the query to the history
|
||||||
|
Loading…
x
Reference in New Issue
Block a user