Fixed Search and Edit Server to hide the keyboard when navigating away
This commit is contained in:
parent
00dc87d5df
commit
8675f25668
|
@ -110,8 +110,8 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
|||
FragmentTitle.setTitle(this, R.string.server_editor_label)
|
||||
val serverSetting = serverSettingsModel.getServerSetting(index)
|
||||
serverSetting.observe(
|
||||
viewLifecycleOwner,
|
||||
{ t ->
|
||||
viewLifecycleOwner
|
||||
) { t ->
|
||||
if (t != null) {
|
||||
currentServerSetting = t
|
||||
if (!isInstanceStateSaved) setFields()
|
||||
|
@ -128,7 +128,6 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
saveButton!!.setOnClickListener {
|
||||
if (currentServerSetting != null) {
|
||||
if (getFields()) {
|
||||
|
@ -187,6 +186,11 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
Util.hideKeyboard(activity)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
private fun updateColor(color: Int?) {
|
||||
val image = ContextCompat.getDrawable(requireContext(), R.drawable.thumb_drawable)
|
||||
currentColor = ServerColor.getBackgroundColor(requireContext(), color)
|
||||
|
@ -511,7 +515,6 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
|||
.setMessage(R.string.server_editor_leave_confirmation)
|
||||
.setPositiveButton(R.string.common_ok) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
Util.hideKeyboard(activity)
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
.setNegativeButton(R.string.common_cancel) { dialog, _ ->
|
||||
|
@ -519,7 +522,6 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
|||
}
|
||||
.show()
|
||||
} else {
|
||||
Util.hideKeyboard(activity)
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.moire.ultrasonic.util.CancellationToken
|
|||
import org.moire.ultrasonic.util.CommunicationError
|
||||
import org.moire.ultrasonic.util.Constants
|
||||
import org.moire.ultrasonic.util.Settings
|
||||
import org.moire.ultrasonic.util.Util
|
||||
import org.moire.ultrasonic.util.Util.toast
|
||||
import timber.log.Timber
|
||||
|
||||
|
@ -50,6 +51,7 @@ import timber.log.Timber
|
|||
class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
|
||||
private var searchResult: SearchResult? = null
|
||||
private var searchRefresh: SwipeRefreshLayout? = null
|
||||
private var searchView: SearchView? = null
|
||||
|
||||
private val mediaPlayerController: MediaPlayerController by inject()
|
||||
|
||||
|
@ -69,15 +71,14 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
|
|||
setHasOptionsMenu(true)
|
||||
|
||||
listModel.searchResult.observe(
|
||||
viewLifecycleOwner,
|
||||
{
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
if (it != null) {
|
||||
// Shorten the display initially
|
||||
searchResult = it
|
||||
populateList(listModel.trimResultLength(it))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
searchRefresh = view.findViewById(R.id.swipe_refresh_view)
|
||||
searchRefresh!!.isEnabled = false
|
||||
|
@ -143,9 +144,9 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
|
|||
val searchManager = activity.getSystemService(Context.SEARCH_SERVICE) as SearchManager
|
||||
inflater.inflate(R.menu.search, menu)
|
||||
val searchItem = menu.findItem(R.id.search_item)
|
||||
val searchView = searchItem.actionView as SearchView
|
||||
searchView = searchItem.actionView as SearchView
|
||||
val searchableInfo = searchManager.getSearchableInfo(requireActivity().componentName)
|
||||
searchView.setSearchableInfo(searchableInfo)
|
||||
searchView!!.setSearchableInfo(searchableInfo)
|
||||
|
||||
val arguments = arguments
|
||||
val autoPlay = arguments != null &&
|
||||
|
@ -154,31 +155,31 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
|
|||
|
||||
// If started with a query, enter it to the searchView
|
||||
if (query != null) {
|
||||
searchView.setQuery(query, false)
|
||||
searchView.clearFocus()
|
||||
searchView!!.setQuery(query, false)
|
||||
searchView!!.clearFocus()
|
||||
}
|
||||
|
||||
searchView.setOnSuggestionListener(object : SearchView.OnSuggestionListener {
|
||||
searchView!!.setOnSuggestionListener(object : SearchView.OnSuggestionListener {
|
||||
override fun onSuggestionSelect(position: Int): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSuggestionClick(position: Int): Boolean {
|
||||
Timber.d("onSuggestionClick: %d", position)
|
||||
val cursor = searchView.suggestionsAdapter.cursor
|
||||
val cursor = searchView!!.suggestionsAdapter.cursor
|
||||
cursor.moveToPosition(position)
|
||||
|
||||
// 2 is the index of col containing suggestion name.
|
||||
val suggestion = cursor.getString(2)
|
||||
searchView.setQuery(suggestion, true)
|
||||
searchView!!.setQuery(suggestion, true)
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
searchView!!.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String): Boolean {
|
||||
Timber.d("onQueryTextSubmit: %s", query)
|
||||
searchView.clearFocus()
|
||||
searchView!!.clearFocus()
|
||||
search(query, autoPlay)
|
||||
return true
|
||||
}
|
||||
|
@ -188,11 +189,12 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
|
|||
}
|
||||
})
|
||||
|
||||
searchView.setIconifiedByDefault(false)
|
||||
searchView!!.setIconifiedByDefault(false)
|
||||
searchItem.expandActionView()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
Util.hideKeyboard(activity)
|
||||
cancellationToken?.cancel()
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue