Move bundle keys where they are used
This both clarifies and simplifies the code. Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
parent
cef97b990e
commit
11f851abf8
@ -16,6 +16,8 @@ import java.util.Objects;
|
||||
*/
|
||||
|
||||
public abstract class BaseActivity extends Activity {
|
||||
private static final String KEY_SELECTED_TUNNEL = "selected_tunnel";
|
||||
|
||||
private final SelectionChangeRegistry selectionChangeRegistry = new SelectionChangeRegistry();
|
||||
private Tunnel selectedTunnel;
|
||||
|
||||
@ -33,9 +35,9 @@ public abstract class BaseActivity extends Activity {
|
||||
// Restore the saved tunnel if there is one; otherwise grab it from the arguments.
|
||||
String savedTunnelName = null;
|
||||
if (savedInstanceState != null)
|
||||
savedTunnelName = savedInstanceState.getString(TunnelManager.KEY_SELECTED_TUNNEL);
|
||||
savedTunnelName = savedInstanceState.getString(KEY_SELECTED_TUNNEL);
|
||||
else if (getIntent() != null)
|
||||
savedTunnelName = getIntent().getStringExtra(TunnelManager.KEY_SELECTED_TUNNEL);
|
||||
savedTunnelName = getIntent().getStringExtra(KEY_SELECTED_TUNNEL);
|
||||
if (savedTunnelName != null) {
|
||||
final TunnelManager manager = Application.getComponent().getTunnelManager();
|
||||
selectedTunnel = manager.getTunnels().get(savedTunnelName);
|
||||
@ -47,7 +49,7 @@ public abstract class BaseActivity extends Activity {
|
||||
@Override
|
||||
protected void onSaveInstanceState(final Bundle outState) {
|
||||
if (selectedTunnel != null)
|
||||
outState.putString(TunnelManager.KEY_SELECTED_TUNNEL, selectedTunnel.getName());
|
||||
outState.putString(KEY_SELECTED_TUNNEL, selectedTunnel.getName());
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import com.wireguard.config.Config;
|
||||
public class ConfigEditorFragment extends BaseFragment {
|
||||
private static final String KEY_LOCAL_CONFIG = "local_config";
|
||||
private static final String KEY_LOCAL_NAME = "local_name";
|
||||
private static final String KEY_ORIGINAL_NAME = "original_name";
|
||||
private static final String TAG = ConfigEditorFragment.class.getSimpleName();
|
||||
|
||||
private final ObservableField<String> localName = new ObservableField<>("");
|
||||
@ -79,7 +80,7 @@ public class ConfigEditorFragment extends BaseFragment {
|
||||
if (savedInstanceState != null) {
|
||||
localConfig = savedInstanceState.getParcelable(KEY_LOCAL_CONFIG);
|
||||
localName.set(savedInstanceState.getString(KEY_LOCAL_NAME));
|
||||
originalName = savedInstanceState.getString(TunnelManager.KEY_SELECTED_TUNNEL);
|
||||
originalName = savedInstanceState.getString(KEY_ORIGINAL_NAME);
|
||||
}
|
||||
// Erase the remains of creating or editing a different tunnel.
|
||||
if (getSelectedTunnel() != null && !getSelectedTunnel().getName().equals(originalName)) {
|
||||
@ -166,7 +167,7 @@ public class ConfigEditorFragment extends BaseFragment {
|
||||
public void onSaveInstanceState(final Bundle outState) {
|
||||
outState.putParcelable(KEY_LOCAL_CONFIG, localConfig);
|
||||
outState.putString(KEY_LOCAL_NAME, localName.get());
|
||||
outState.putString(TunnelManager.KEY_SELECTED_TUNNEL, originalName);
|
||||
outState.putString(KEY_ORIGINAL_NAME, originalName);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,6 @@ import java9.util.stream.StreamSupport;
|
||||
@ApplicationScope
|
||||
public final class TunnelManager {
|
||||
public static final String KEY_PRIMARY_TUNNEL = "primary_config";
|
||||
public static final String KEY_SELECTED_TUNNEL = "selected_tunnel";
|
||||
private static final Comparator<String> COMPARATOR = Comparators.<String>thenComparing(
|
||||
String.CASE_INSENSITIVE_ORDER, Comparators.naturalOrder());
|
||||
private static final String KEY_RESTORE_ON_BOOT = "restore_on_boot";
|
||||
|
Loading…
Reference in New Issue
Block a user