summaryrefslogtreecommitdiff
path: root/main/src/ui/java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui/java')
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.java150
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt106
2 files changed, 106 insertions, 150 deletions
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.java b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.java
deleted file mode 100644
index 843ff750..00000000
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 2012-2016 Arne Schwabe
- * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
- */
-
-package de.blinkt.openvpn.fragments;
-
-import android.os.Bundle;
-
-import androidx.preference.CheckBoxPreference;
-import androidx.preference.EditTextPreference;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceManager;
-import androidx.preference.SwitchPreference;
-
-import de.blinkt.openvpn.R;
-import de.blinkt.openvpn.VpnProfile;
-
-public class Settings_IP extends OpenVpnPreferencesFragment implements Preference.OnPreferenceChangeListener {
- private EditTextPreference mIPv4;
- private EditTextPreference mIPv6;
- private SwitchPreference mUsePull;
- private CheckBoxPreference mOverrideDNS;
- private EditTextPreference mSearchdomain;
- private EditTextPreference mDNS1;
- private EditTextPreference mDNS2;
- private CheckBoxPreference mNobind;
-
- @Override
- public void onResume()
- {
- super.onResume();
-
-
- // Make sure default values are applied. In a real app, you would
- // want this in a shared function that is used to retrieve the
- // SharedPreferences wherever they are needed.
- PreferenceManager.setDefaultValues(requireActivity(),
- R.xml.vpn_ipsettings, false);
-
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.vpn_ipsettings);
- mIPv4 = findPreference("ipv4_address");
- mIPv6 = findPreference("ipv6_address");
- mUsePull = findPreference("usePull");
- mOverrideDNS = findPreference("overrideDNS");
- mSearchdomain = findPreference("searchdomain");
- mDNS1 = findPreference("dns1");
- mDNS2 = findPreference("dns2");
- mNobind = findPreference("nobind");
-
- mIPv4.setOnPreferenceChangeListener(this);
- mIPv6.setOnPreferenceChangeListener(this);
- mDNS1.setOnPreferenceChangeListener(this);
- mDNS2.setOnPreferenceChangeListener(this);
- mUsePull.setOnPreferenceChangeListener(this);
- mOverrideDNS.setOnPreferenceChangeListener(this);
- mSearchdomain.setOnPreferenceChangeListener(this);
-
- loadSettings();
- }
-
- @Override
- protected void loadSettings() {
-
- if (mProfile.mAuthenticationType == VpnProfile.TYPE_STATICKEYS)
- mUsePull.setEnabled(false);
- else
- mUsePull.setChecked(mProfile.mUsePull);
- mIPv4.setText(mProfile.mIPv4Address);
- mIPv6.setText(mProfile.mIPv6Address);
- mDNS1.setText(mProfile.mDNS1);
- mDNS2.setText(mProfile.mDNS2);
- mOverrideDNS.setChecked(mProfile.mOverrideDNS);
- mSearchdomain.setText(mProfile.mSearchDomain);
- mNobind.setChecked(mProfile.mNobind);
-
-
- //mUsePull.setEnabled(mProfile.mAuthenticationType != VpnProfile.TYPE_STATICKEYS);
- mUsePull.setEnabled(true);
-
- if (mProfile.mAuthenticationType == VpnProfile.TYPE_STATICKEYS)
- mUsePull.setChecked(false);
-
- // Sets Summary
- onPreferenceChange(mIPv4, mIPv4.getText());
- onPreferenceChange(mIPv6, mIPv6.getText());
- onPreferenceChange(mDNS1, mDNS1.getText());
- onPreferenceChange(mDNS2, mDNS2.getText());
- onPreferenceChange(mSearchdomain, mSearchdomain.getText());
-
- setDNSState();
- }
-
-
- @Override
- protected void saveSettings() {
- mProfile.mUsePull = mUsePull.isChecked();
- mProfile.mIPv4Address = mIPv4.getText();
- mProfile.mIPv6Address = mIPv6.getText();
- mProfile.mDNS1 = mDNS1.getText();
- mProfile.mDNS2 = mDNS2.getText();
- mProfile.mOverrideDNS = mOverrideDNS.isChecked();
- mProfile.mSearchDomain = mSearchdomain.getText();
- mProfile.mNobind = mNobind.isChecked();
-
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference,
- Object newValue) {
- if(preference==mIPv4 || preference == mIPv6
- || preference==mDNS1 || preference == mDNS2
- || preference == mSearchdomain
- )
-
- preference.setSummary((String)newValue);
-
- if(preference== mUsePull || preference == mOverrideDNS)
- if(preference==mOverrideDNS) {
- // Set so the function gets the right value
- mOverrideDNS.setChecked((Boolean) newValue);
- }
- setDNSState();
-
- saveSettings();
- return true;
- }
-
- private void setDNSState() {
- boolean enabled;
- mOverrideDNS.setEnabled(mUsePull.isChecked());
- if(!mUsePull.isChecked())
- enabled =true;
- else
- enabled = mOverrideDNS.isChecked();
-
- mDNS1.setEnabled(enabled);
- mDNS2.setEnabled(enabled);
- mSearchdomain.setEnabled(enabled);
-
-
- }
-
-
- @Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
-
- }
-} \ No newline at end of file
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt
new file mode 100644
index 00000000..d2bf4b74
--- /dev/null
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2012-2016 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+package de.blinkt.openvpn.fragments
+
+import android.os.Bundle
+import androidx.preference.*
+import de.blinkt.openvpn.R
+import de.blinkt.openvpn.fragments.OpenVpnPreferencesFragment
+import de.blinkt.openvpn.VpnProfile
+
+class Settings_IP : OpenVpnPreferencesFragment(), Preference.OnPreferenceChangeListener {
+ private lateinit var mIPv4: EditTextPreference
+ private lateinit var mIPv6: EditTextPreference
+ private lateinit var mUsePull: SwitchPreference
+ private lateinit var mOverrideDNS: CheckBoxPreference
+ private lateinit var mSearchdomain: EditTextPreference
+ private lateinit var mDNS1: EditTextPreference
+ private lateinit var mDNS2: EditTextPreference
+ private lateinit var mNobind: CheckBoxPreference
+ override fun onResume() {
+ super.onResume()
+
+
+ // Make sure default values are applied. In a real app, you would
+ // want this in a shared function that is used to retrieve the
+ // SharedPreferences wherever they are needed.
+ PreferenceManager.setDefaultValues(
+ requireActivity(),
+ R.xml.vpn_ipsettings, false
+ )
+
+ // Load the preferences from an XML resource
+ addPreferencesFromResource(R.xml.vpn_ipsettings)
+ mIPv4 = findPreference("ipv4_address")!!
+ mIPv6 = findPreference("ipv6_address")!!
+ mUsePull = findPreference("usePull")!!
+ mOverrideDNS = findPreference("overrideDNS")!!
+ mSearchdomain = findPreference("searchdomain")!!
+ mDNS1 = findPreference("dns1")!!
+ mDNS2 = findPreference("dns2")!!
+ mNobind = findPreference("nobind")!!
+ mUsePull.onPreferenceChangeListener = this
+ mOverrideDNS.onPreferenceChangeListener = this
+ loadSettings()
+ }
+
+ override fun loadSettings() {
+ if (mProfile.mAuthenticationType == VpnProfile.TYPE_STATICKEYS) mUsePull.isEnabled =
+ false else mUsePull.isChecked = mProfile.mUsePull
+ mIPv4.text = mProfile.mIPv4Address
+ mIPv6.text = mProfile.mIPv6Address
+ mDNS1.text = mProfile.mDNS1
+ mDNS2.text = mProfile.mDNS2
+ mOverrideDNS.isChecked = mProfile.mOverrideDNS
+ mSearchdomain.text = mProfile.mSearchDomain
+ mNobind.isChecked = mProfile.mNobind
+
+
+ //mUsePull.setEnabled(mProfile.mAuthenticationType != VpnProfile.TYPE_STATICKEYS);
+ mUsePull.isEnabled = true
+ if (mProfile.mAuthenticationType == VpnProfile.TYPE_STATICKEYS) mUsePull.isChecked = false
+
+ // Sets Summary
+ setDNSState()
+ }
+
+ override fun saveSettings() {
+ mProfile.mUsePull = mUsePull.isChecked
+ mProfile.mIPv4Address = mIPv4.text
+ mProfile.mIPv6Address = mIPv6.text
+ mProfile.mDNS1 = mDNS1.text
+ mProfile.mDNS2 = mDNS2.text
+ mProfile.mOverrideDNS = mOverrideDNS.isChecked
+ mProfile.mSearchDomain = mSearchdomain.text
+ mProfile.mNobind = mNobind.isChecked
+ }
+
+ override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
+ if (preference === mUsePull || preference === mOverrideDNS)
+ if (preference === mOverrideDNS) {
+ // Set so the function gets the right value
+ mOverrideDNS.isChecked = (newValue as Boolean)
+ }
+ setDNSState()
+ saveSettings()
+ return true
+ }
+
+ override fun onPause() {
+ super.onPause()
+ saveSettings()
+ }
+
+ private fun setDNSState() {
+ val enabled: Boolean
+ mOverrideDNS.isEnabled = mUsePull.isChecked
+ enabled = if (!mUsePull.isChecked) true else mOverrideDNS.isChecked
+ mDNS1.isEnabled = enabled
+ mDNS2.isEnabled = enabled
+ mSearchdomain.isEnabled = enabled
+ }
+
+ override fun onCreatePreferences(savedInstanceState: Bundle, rootKey: String) {}
+} \ No newline at end of file