ui: account for binding disappearing on detail fragment

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-09-30 12:47:29 +02:00
parent 8a6f8f73cd
commit ddb6c87ebf

View File

@ -63,13 +63,17 @@ class TunnelDetailFragment : BaseFragment() {
}
override fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, newTunnel: ObservableTunnel?) {
binding ?: return
binding!!.tunnel = newTunnel
if (newTunnel == null) binding!!.config = null else lifecycleScope.launch {
try {
binding!!.config = newTunnel.getConfigAsync()
} catch (_: Throwable) {
binding!!.config = null
val binding = binding ?: return
binding.tunnel = newTunnel
if (newTunnel == null) {
binding.config = null
} else {
lifecycleScope.launch {
try {
binding.config = newTunnel.getConfigAsync()
} catch (_: Throwable) {
binding.config = null
}
}
}
lastState = Tunnel.State.TOGGLE