2018-01-01 09:06:37 +01:00
|
|
|
package com.wireguard.android.fragment;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
2018-04-27 19:29:24 +02:00
|
|
|
import android.support.annotation.NonNull;
|
2018-01-01 09:06:37 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import com.wireguard.android.R;
|
|
|
|
import com.wireguard.android.databinding.TunnelDetailFragmentBinding;
|
|
|
|
import com.wireguard.android.model.Tunnel;
|
2018-04-28 04:45:17 +02:00
|
|
|
import com.wireguard.config.Config;
|
2018-01-01 09:06:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fragment that shows details about a specific tunnel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class TunnelDetailFragment extends BaseFragment {
|
|
|
|
private TunnelDetailFragmentBinding binding;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.tunnel_detail, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-04-27 19:29:24 +02:00
|
|
|
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
|
2018-01-01 09:06:37 +01:00
|
|
|
final Bundle savedInstanceState) {
|
|
|
|
super.onCreateView(inflater, container, savedInstanceState);
|
|
|
|
binding = TunnelDetailFragmentBinding.inflate(inflater, container, false);
|
|
|
|
binding.executePendingBindings();
|
|
|
|
return binding.getRoot();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
binding = null;
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
2018-04-30 05:28:51 +02:00
|
|
|
private void onConfigLoaded(final String name, final Config config) {
|
|
|
|
binding.setConfig(new Config.Observable(config, name));
|
2018-04-28 04:45:17 +02:00
|
|
|
}
|
|
|
|
|
2018-01-01 09:06:37 +01:00
|
|
|
@Override
|
|
|
|
public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
|
2018-04-30 05:28:51 +02:00
|
|
|
if (binding == null)
|
|
|
|
return;
|
|
|
|
binding.setTunnel(newTunnel);
|
|
|
|
if (newTunnel == null)
|
|
|
|
binding.setConfig(null);
|
|
|
|
else
|
|
|
|
newTunnel.getConfigAsync().thenAccept(a -> onConfigLoaded(newTunnel.getName(), a));
|
2018-01-01 09:06:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewStateRestored(final Bundle savedInstanceState) {
|
2018-04-30 05:28:51 +02:00
|
|
|
onSelectedTunnelChanged(null, getSelectedTunnel());
|
2018-01-01 09:06:37 +01:00
|
|
|
super.onViewStateRestored(savedInstanceState);
|
|
|
|
}
|
|
|
|
}
|