diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-28 04:45:17 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-28 04:51:43 +0200 |
commit | 63071f57b7b501c23843f502a5d2a1ac83338bc7 (patch) | |
tree | 21a9a0f4de77b67669949534c27e033d1ee896c3 /app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java | |
parent | 693228985df3aab03a53d9ae68aed7d309c4f6bd (diff) |
Use validation instead of two-way binding
This is insane, but it appears to be working. We essentially store
things in a separate class for editing, and then commit it back at a
given time.
This business with onViewStateRestored in both TunnelEditorFragment and
in TunnelDetailFragment is buggy and likely wrong.
In general TunnelEditorFragment should probably be rewritten. The
relationship with the changed name is not clear.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java | 24 |
1 files changed, 22 insertions, 2 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 e236da71..5592c28a 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java @@ -10,6 +10,7 @@ import android.view.ViewGroup; import com.wireguard.android.R; import com.wireguard.android.databinding.TunnelDetailFragmentBinding; import com.wireguard.android.model.Tunnel; +import com.wireguard.config.Config; /** * Fragment that shows details about a specific tunnel. @@ -18,6 +19,7 @@ import com.wireguard.android.model.Tunnel; public class TunnelDetailFragment extends BaseFragment { private TunnelDetailFragmentBinding binding; private boolean isViewStateRestored; + private String originalName; @Override public void onCreate(final Bundle savedInstanceState) { @@ -45,16 +47,34 @@ public class TunnelDetailFragment extends BaseFragment { super.onDestroyView(); } + private void onConfigLoaded(Config config) { + binding.setConfig(new Config.Observable(config, originalName)); + } + @Override public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) { - if (binding != null && isViewStateRestored) + if (binding != null && isViewStateRestored) { binding.setTunnel(newTunnel); + if (newTunnel == null) + binding.setConfig(null); + else { + originalName = newTunnel.getName(); + newTunnel.getConfigAsync().thenAccept(this::onConfigLoaded); + } + } } @Override public void onViewStateRestored(final Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); - binding.setTunnel(getSelectedTunnel()); + Tunnel tunnel = getSelectedTunnel(); + binding.setTunnel(tunnel); + if (tunnel == null) + binding.setConfig(null); + else { + originalName = tunnel.getName(); + tunnel.getConfigAsync().thenAccept(this::onConfigLoaded); + } isViewStateRestored = true; } } |