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