diff options
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" |