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?) { override fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, newTunnel: ObservableTunnel?) {
binding ?: return val binding = binding ?: return
binding!!.tunnel = newTunnel binding.tunnel = newTunnel
if (newTunnel == null) binding!!.config = null else lifecycleScope.launch { if (newTunnel == null) {
try { binding.config = null
binding!!.config = newTunnel.getConfigAsync() } else {
} catch (_: Throwable) { lifecycleScope.launch {
binding!!.config = null try {
binding.config = newTunnel.getConfigAsync()
} catch (_: Throwable) {
binding.config = null
}
} }
} }
lastState = Tunnel.State.TOGGLE lastState = Tunnel.State.TOGGLE