diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-30 05:28:51 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-30 05:29:54 +0200 |
commit | 596904977a62c080254f94e1941c376edcec268e (patch) | |
tree | 831ecce74f208a218f69762c1cfcfc03dc5c7aaa /app | |
parent | 73b0c4ea8116c4b1088dcd84cb2f4d7181baf7ab (diff) |
TunnelDetailFragment: rewrite and simplify
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java index 08f08298..8d0ae4cf 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java @@ -19,8 +19,6 @@ import com.wireguard.config.Config; public class TunnelDetailFragment extends BaseFragment { private TunnelDetailFragmentBinding binding; - private boolean isViewStateRestored; - private String originalName; @Override public void onCreate(final Bundle savedInstanceState) { @@ -48,34 +46,24 @@ public class TunnelDetailFragment extends BaseFragment { super.onDestroyView(); } - private void onConfigLoaded(Config config) { - binding.setConfig(new Config.Observable(config, originalName)); + private void onConfigLoaded(final String name, final Config config) { + binding.setConfig(new Config.Observable(config, name)); } @Override public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) { - if (binding != null && isViewStateRestored) { - binding.setTunnel(newTunnel); - if (newTunnel == null) - binding.setConfig(null); - else { - originalName = newTunnel.getName(); - newTunnel.getConfigAsync().thenAccept(this::onConfigLoaded); - } - } + if (binding == null) + return; + binding.setTunnel(newTunnel); + if (newTunnel == null) + binding.setConfig(null); + else + newTunnel.getConfigAsync().thenAccept(a -> onConfigLoaded(newTunnel.getName(), a)); } @Override public void onViewStateRestored(final Bundle savedInstanceState) { + onSelectedTunnelChanged(null, getSelectedTunnel()); super.onViewStateRestored(savedInstanceState); - Tunnel tunnel = getSelectedTunnel(); - binding.setTunnel(tunnel); - if (tunnel == null) - binding.setConfig(null); - else { - originalName = tunnel.getName(); - tunnel.getConfigAsync().thenAccept(this::onConfigLoaded); - } - isViewStateRestored = true; } } |