TunnelEditorFragment: avoid extra trip through event loop

onSelectedTunnelChanged is already queueing us to Dispatchers.Main
(rather than Dispatchers.Main.immediate, which would crash, but why?),
so avoid the extra trip through the event loop by toggling the selected
tunnel right away.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-09-16 10:51:56 +02:00
parent abcb51d2a6
commit 52a2ae36f6

View File

@ -117,14 +117,13 @@ class TunnelEditorFragment : BaseFragment(), AppSelectionListener {
inputManager?.hideSoftInputFromWindow(focusedView.windowToken, inputManager?.hideSoftInputFromWindow(focusedView.windowToken,
InputMethodManager.HIDE_NOT_ALWAYS) InputMethodManager.HIDE_NOT_ALWAYS)
} }
// Tell the activity to finish itself or go back to the detail view. // Tell the activity to finish itself or go back to the detail view.
activity.runOnUiThread { // TODO(smaeul): Remove this hack when fixing the Config ViewModel
// TODO(smaeul): Remove this hack when fixing the Config ViewModel // The selected tunnel has to actually change, but we have to remember this one.
// The selected tunnel has to actually change, but we have to remember this one. val savedTunnel = tunnel
val savedTunnel = tunnel if (savedTunnel === selectedTunnel) selectedTunnel = null
if (savedTunnel === selectedTunnel) selectedTunnel = null selectedTunnel = savedTunnel
selectedTunnel = savedTunnel
}
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {