TunnelDetailFragment: rewrite and simplify
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
73b0c4ea81
commit
596904977a
@ -19,8 +19,6 @@ import com.wireguard.config.Config;
|
|||||||
|
|
||||||
public class TunnelDetailFragment extends BaseFragment {
|
public class TunnelDetailFragment extends BaseFragment {
|
||||||
private TunnelDetailFragmentBinding binding;
|
private TunnelDetailFragmentBinding binding;
|
||||||
private boolean isViewStateRestored;
|
|
||||||
private String originalName;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
@ -48,34 +46,24 @@ public class TunnelDetailFragment extends BaseFragment {
|
|||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onConfigLoaded(Config config) {
|
private void onConfigLoaded(final String name, final Config config) {
|
||||||
binding.setConfig(new Config.Observable(config, originalName));
|
binding.setConfig(new Config.Observable(config, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
|
public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
|
||||||
if (binding != null && isViewStateRestored) {
|
if (binding == null)
|
||||||
|
return;
|
||||||
binding.setTunnel(newTunnel);
|
binding.setTunnel(newTunnel);
|
||||||
if (newTunnel == null)
|
if (newTunnel == null)
|
||||||
binding.setConfig(null);
|
binding.setConfig(null);
|
||||||
else {
|
else
|
||||||
originalName = newTunnel.getName();
|
newTunnel.getConfigAsync().thenAccept(a -> onConfigLoaded(newTunnel.getName(), a));
|
||||||
newTunnel.getConfigAsync().thenAccept(this::onConfigLoaded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewStateRestored(final Bundle savedInstanceState) {
|
public void onViewStateRestored(final Bundle savedInstanceState) {
|
||||||
|
onSelectedTunnelChanged(null, getSelectedTunnel());
|
||||||
super.onViewStateRestored(savedInstanceState);
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user