summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2018-07-23 13:10:18 +0200
committerArne Schwabe <arne@rfc2549.org>2018-07-23 13:23:40 +0200
commit367e7e4fd1246f8e15fd5e036e49ef971f44a8de (patch)
treea2e3cd87aa0a29da17683c450d745e83f524b084 /main
parentf65b8f232c84fb15767c14018d942666bc4e1b71 (diff)
Move loading of default VPN entries to custom class (closes #879)
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java14
-rw-r--r--main/src/main/java/de/blinkt/openvpn/views/DefaultVPNListPreference.java39
-rw-r--r--main/src/main/res/xml/general_settings.xml2
3 files changed, 40 insertions, 15 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java b/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java
index 2d544ee5..1c20e167 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/GeneralSettings.java
@@ -94,21 +94,7 @@ public class GeneralSettings extends PreferenceFragment implements OnPreferenceC
public void onResume() {
super.onResume();
- ProfileManager pm = ProfileManager.getInstance(getActivity());
- Collection<VpnProfile> profiles = pm.getProfiles();
- CharSequence[] entries = new CharSequence[profiles.size()];
- CharSequence[] entryValues = new CharSequence[profiles.size()];;
-
- int i=0;
- for (VpnProfile p: profiles)
- {
- entries[i]=p.getName();
- entryValues[i]=p.getUUIDString();
- i++;
- }
- mAlwaysOnVPN.setEntries(entries);
- mAlwaysOnVPN.setEntryValues(entryValues);
VpnProfile vpn = ProfileManager.getAlwaysOnVPN(getActivity());
diff --git a/main/src/main/java/de/blinkt/openvpn/views/DefaultVPNListPreference.java b/main/src/main/java/de/blinkt/openvpn/views/DefaultVPNListPreference.java
new file mode 100644
index 00000000..e8328f5c
--- /dev/null
+++ b/main/src/main/java/de/blinkt/openvpn/views/DefaultVPNListPreference.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012-2018 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+
+package de.blinkt.openvpn.views;
+
+import android.content.Context;
+import android.preference.ListPreference;
+import android.util.AttributeSet;
+import de.blinkt.openvpn.VpnProfile;
+import de.blinkt.openvpn.core.ProfileManager;
+
+import java.util.Collection;
+
+public class DefaultVPNListPreference extends ListPreference {
+ public DefaultVPNListPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setVPNs(context);
+ }
+
+ private void setVPNs(Context c) {
+ ProfileManager pm = ProfileManager.getInstance(c);
+ Collection<VpnProfile> profiles = pm.getProfiles();
+ CharSequence[] entries = new CharSequence[profiles.size()];
+ CharSequence[] entryValues = new CharSequence[profiles.size()];;
+
+ int i=0;
+ for (VpnProfile p: profiles)
+ {
+ entries[i]=p.getName();
+ entryValues[i]=p.getUUIDString();
+ i++;
+ }
+
+ setEntries(entries);
+ setEntryValues(entryValues);
+ }
+}
diff --git a/main/src/main/res/xml/general_settings.xml b/main/src/main/res/xml/general_settings.xml
index f0b9e9d9..5c2ff8aa 100644
--- a/main/src/main/res/xml/general_settings.xml
+++ b/main/src/main/res/xml/general_settings.xml
@@ -23,7 +23,7 @@
android:title="OpenVPN 3 Core"/>
- <ListPreference
+ <de.blinkt.openvpn.views.DefaultVPNListPreference
android:key="alwaysOnVpn"
android:title="@string/defaultvpn"
tools:summary="@string/defaultvpnsummary"