Merge pull request #1172 from Bnyro/master

fix search focus
This commit is contained in:
Bnyro 2022-08-26 15:04:07 +02:00 committed by GitHub
commit fbfd74f269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View File

@ -202,7 +202,10 @@ class MainActivity : BaseActivity() {
)
}
private fun removeSearchFocus() {
/**
* Remove the focus of the search view in the toolbar
*/
fun removeSearchFocus() {
searchView.setQuery("", false)
searchView.clearFocus()
searchView.onActionViewCollapsed()

View File

@ -7,7 +7,9 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R
import com.github.libretube.activities.MainActivity
import com.github.libretube.adapters.SearchHistoryAdapter
import com.github.libretube.adapters.SearchSuggestionsAdapter
@ -18,6 +20,7 @@ import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.await
import com.github.libretube.models.SearchViewModel
import kotlinx.android.synthetic.main.activity_main.toolbar
import retrofit2.HttpException
import java.io.IOException
@ -109,4 +112,14 @@ class SearchFragment() : BaseFragment() {
binding.historyEmpty.visibility = View.VISIBLE
}
}
override fun onStop() {
if (findNavController().currentDestination?.id != R.id.searchResultFragment) {
// remove the search focus
(activity as MainActivity)
.toolbar.menu
.findItem(R.id.action_search).collapseActionView()
}
super.onStop()
}
}

View File

@ -6,8 +6,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R
import com.github.libretube.activities.MainActivity
import com.github.libretube.adapters.SearchAdapter
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.databinding.FragmentSearchResultBinding
@ -18,6 +20,7 @@ import com.github.libretube.extensions.TAG
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.hideKeyboard
import kotlinx.android.synthetic.main.activity_main.toolbar
import retrofit2.HttpException
import java.io.IOException
@ -141,4 +144,14 @@ class SearchResultFragment : BaseFragment() {
)
}
}
override fun onStop() {
if (findNavController().currentDestination?.id != R.id.searchFragment) {
// remove the search focus
(activity as MainActivity)
.toolbar.menu
.findItem(R.id.action_search).collapseActionView()
}
super.onStop()
}
}