From 596904977a62c080254f94e1941c376edcec268e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 30 Apr 2018 05:28:51 +0200 Subject: TunnelDetailFragment: rewrite and simplify Signed-off-by: Jason A. Donenfeld --- .../android/fragment/TunnelDetailFragment.java | 32 +++++++--------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'app/src/main/java/com/wireguard') 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; } } -- cgit v1.2.3