summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/BaseConfigFragment.java
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-13 07:24:03 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-13 07:24:03 -0500
commit5e55d196be092f4a4dcb212cf09d7a1bdab70e00 (patch)
treeeb765a1b961fefdaa7ddc3cfae9cb83a09e0c031 /app/src/main/java/com/wireguard/android/BaseConfigFragment.java
parentc72d30a1af8114ef506a137e3e7274ac33d82bd1 (diff)
Major renaming and refactoring in activity and service
Apparently "configuration" is the proper term, not "profile". Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/BaseConfigFragment.java')
-rw-r--r--app/src/main/java/com/wireguard/android/BaseConfigFragment.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/BaseConfigFragment.java b/app/src/main/java/com/wireguard/android/BaseConfigFragment.java
new file mode 100644
index 00000000..4a754b63
--- /dev/null
+++ b/app/src/main/java/com/wireguard/android/BaseConfigFragment.java
@@ -0,0 +1,47 @@
+package com.wireguard.android;
+
+import android.app.Fragment;
+import android.os.Bundle;
+
+import com.wireguard.config.Config;
+
+/**
+ * Base class for fragments that need to remember the current configuration.
+ */
+
+abstract class BaseConfigFragment extends Fragment {
+ private static final String KEY_CURRENT_CONFIG = "currentConfig";
+
+ private Config currentConfig;
+
+ protected Config getCurrentConfig() {
+ return currentConfig;
+ }
+
+ protected abstract void onCurrentConfigChanged(Config config);
+
+ @Override
+ public void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // Restore the saved configuration if there is one; otherwise grab it from the arguments.
+ String initialConfig = null;
+ if (savedInstanceState != null)
+ initialConfig = savedInstanceState.getString(KEY_CURRENT_CONFIG);
+ else if (getArguments() != null)
+ initialConfig = getArguments().getString(KEY_CURRENT_CONFIG);
+ if (initialConfig != null && currentConfig == null)
+ setCurrentConfig(VpnService.getInstance().get(initialConfig));
+ }
+
+ @Override
+ public void onSaveInstanceState(final Bundle outState) {
+ super.onSaveInstanceState(outState);
+ if (currentConfig != null)
+ outState.putString(KEY_CURRENT_CONFIG, currentConfig.getName());
+ }
+
+ public void setCurrentConfig(final Config config) {
+ currentConfig = config;
+ onCurrentConfigChanged(currentConfig);
+ }
+}