global: Automatic code formatting
Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
@@ -20,6 +20,10 @@ import com.wireguard.config.Config;
|
||||
public class TunnelDetailFragment extends BaseFragment {
|
||||
private TunnelDetailFragmentBinding binding;
|
||||
|
||||
private void onConfigLoaded(final String name, final Config config) {
|
||||
binding.setConfig(new Config.Observable(config, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -46,10 +50,6 @@ public class TunnelDetailFragment extends BaseFragment {
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.wireguard.android.fragment;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
@@ -41,46 +39,30 @@ public class TunnelEditorFragment extends BaseFragment {
|
||||
binding.setConfig(new Config.Observable(config, name));
|
||||
}
|
||||
|
||||
private void onConfigSaved(final Tunnel savedTunnel, final Config config,
|
||||
final Throwable throwable) {
|
||||
final String message;
|
||||
if (throwable == null) {
|
||||
message = getString(R.string.config_save_success, savedTunnel.getName());
|
||||
Log.d(TAG, message);
|
||||
onFinished();
|
||||
} else {
|
||||
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
|
||||
message = getString(R.string.config_save_error, savedTunnel.getName(), error);
|
||||
Log.e(TAG, message, throwable);
|
||||
if (binding != null) {
|
||||
final CoordinatorLayout container = binding.mainContainer;
|
||||
Snackbar.make(container, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
|
||||
tunnel = newTunnel;
|
||||
if (binding == null)
|
||||
return;
|
||||
binding.setConfig(new Config.Observable(null, null));
|
||||
if (tunnel != null)
|
||||
tunnel.getConfigAsync().thenAccept(a -> onConfigLoaded(tunnel.getName(), a));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull final Bundle outState) {
|
||||
outState.putParcelable(KEY_LOCAL_CONFIG, binding.getConfig());
|
||||
outState.putString(KEY_ORIGINAL_NAME, tunnel == null ? null : tunnel.getName());
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewStateRestored(final Bundle savedInstanceState) {
|
||||
if (savedInstanceState == null) {
|
||||
onSelectedTunnelChanged(null, getSelectedTunnel());
|
||||
} else {
|
||||
tunnel = getSelectedTunnel();
|
||||
Config.Observable config = savedInstanceState.getParcelable(KEY_LOCAL_CONFIG);
|
||||
String originalName = savedInstanceState.getString(KEY_ORIGINAL_NAME);
|
||||
if (tunnel != null && !tunnel.getName().equals(originalName))
|
||||
onSelectedTunnelChanged(null, tunnel);
|
||||
else
|
||||
binding.setConfig(config);
|
||||
}
|
||||
|
||||
super.onViewStateRestored(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.config_editor, menu);
|
||||
@@ -159,22 +141,21 @@ public class TunnelEditorFragment extends BaseFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void onConfigSaved(final Tunnel savedTunnel, final Config config,
|
||||
final Throwable throwable) {
|
||||
final String message;
|
||||
if (throwable == null) {
|
||||
message = getString(R.string.config_save_success, savedTunnel.getName());
|
||||
Log.d(TAG, message);
|
||||
onFinished();
|
||||
} else {
|
||||
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
|
||||
message = getString(R.string.config_save_error, savedTunnel.getName(), error);
|
||||
Log.e(TAG, message, throwable);
|
||||
if (binding != null) {
|
||||
final CoordinatorLayout container = binding.mainContainer;
|
||||
Snackbar.make(container, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull final Bundle outState) {
|
||||
outState.putParcelable(KEY_LOCAL_CONFIG, binding.getConfig());
|
||||
outState.putString(KEY_ORIGINAL_NAME, tunnel == null ? null : tunnel.getName());
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
|
||||
tunnel = newTunnel;
|
||||
if (binding == null)
|
||||
return;
|
||||
binding.setConfig(new Config.Observable(null, null));
|
||||
if (tunnel != null)
|
||||
tunnel.getConfigAsync().thenAccept(a -> onConfigLoaded(tunnel.getName(), a));
|
||||
}
|
||||
|
||||
private void onTunnelCreated(final Tunnel newTunnel, final Throwable throwable) {
|
||||
@@ -214,4 +195,21 @@ public class TunnelEditorFragment extends BaseFragment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewStateRestored(final Bundle savedInstanceState) {
|
||||
if (savedInstanceState == null) {
|
||||
onSelectedTunnelChanged(null, getSelectedTunnel());
|
||||
} else {
|
||||
tunnel = getSelectedTunnel();
|
||||
Config.Observable config = savedInstanceState.getParcelable(KEY_LOCAL_CONFIG);
|
||||
String originalName = savedInstanceState.getString(KEY_ORIGINAL_NAME);
|
||||
if (tunnel != null && !tunnel.getName().equals(originalName))
|
||||
onSelectedTunnelChanged(null, tunnel);
|
||||
else
|
||||
binding.setConfig(config);
|
||||
}
|
||||
|
||||
super.onViewStateRestored(savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import android.widget.AbsListView.MultiChoiceModeListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.Application.ApplicationComponent;
|
||||
@@ -44,7 +43,6 @@ import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -70,6 +68,14 @@ public class TunnelListFragment extends BaseFragment {
|
||||
private TunnelListFragmentBinding binding;
|
||||
private TunnelManager tunnelManager;
|
||||
|
||||
public boolean collapseActionMenu() {
|
||||
if (binding.createMenu.isExpanded()) {
|
||||
binding.createMenu.collapse();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void importTunnel(final Uri uri) {
|
||||
final Activity activity = getActivity();
|
||||
if (activity == null)
|
||||
@@ -199,14 +205,6 @@ public class TunnelListFragment extends BaseFragment {
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
public boolean collapseActionMenu() {
|
||||
if (binding.createMenu.isExpanded()) {
|
||||
binding.createMenu.collapse();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onRequestCreateConfig(@SuppressWarnings("unused") final View view) {
|
||||
startActivity(new Intent(getActivity(), TunnelCreatorActivity.class));
|
||||
if (binding != null)
|
||||
@@ -254,7 +252,7 @@ public class TunnelListFragment extends BaseFragment {
|
||||
if (tunnels.size() == 1 && throwables.isEmpty())
|
||||
message = getString(R.string.import_success, tunnels.get(0).getName());
|
||||
else if (tunnels.isEmpty() && throwables.size() == 1)
|
||||
/* Use the exception message from above. */;
|
||||
/* Use the exception message from above. */ ;
|
||||
else if (throwables.isEmpty())
|
||||
message = getString(R.string.import_total_success, tunnels.size());
|
||||
else if (!throwables.isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user