summaryrefslogtreecommitdiff
path: root/main/src/ui
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2021-10-25 00:50:15 +0200
committerArne Schwabe <arne@rfc2549.org>2021-10-25 00:51:01 +0200
commit7fb58f6609802a03dc82169531badbad98d4c33d (patch)
treeb9a185ecd87613fbf0b311e610f52a9908833fe2 /main/src/ui
parentaf4a789df914732e65b05dae582ed21eed0d91b7 (diff)
Implement custom summary provider for DNS
Diffstat (limited to 'main/src/ui')
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt28
-rw-r--r--main/src/ui/res/xml/vpn_ipsettings.xml4
2 files changed, 28 insertions, 4 deletions
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
index d2bf4b74..ada77836 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt
@@ -40,12 +40,15 @@ class Settings_IP : OpenVpnPreferencesFragment(), Preference.OnPreferenceChangeL
mSearchdomain = findPreference("searchdomain")!!
mDNS1 = findPreference("dns1")!!
mDNS2 = findPreference("dns2")!!
+ mDNS1.summaryProvider = DNSSummaryProvider()
+ mDNS2.summaryProvider = DNSSummaryProvider()
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
@@ -102,5 +105,26 @@ class Settings_IP : OpenVpnPreferencesFragment(), Preference.OnPreferenceChangeL
mSearchdomain.isEnabled = enabled
}
- override fun onCreatePreferences(savedInstanceState: Bundle, rootKey: String) {}
-} \ No newline at end of file
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+
+ }
+}
+
+class DNSSummaryProvider : Preference.SummaryProvider<Preference> {
+ override fun provideSummary(preference: Preference?): CharSequence {
+ val ep = preference as EditTextPreference
+ var summary = ep.text ?: ""
+ if (summary == "8.8.4.4" || summary == "8.8.8.8" || summary == "2001:4860:4860::8888" || summary == "2001:4860:4860::8844" )
+ summary += " (dns.google.com)"
+ else if (summary.startsWith("2606:4700:4700::") || summary.startsWith("1.1.1.") || summary.startsWith("1.0.0."))
+ summary += " (Cloudflare)"
+
+ else if (summary.startsWith("9.9.9.") || summary.startsWith("2620:fe::"))
+ summary += " (Quad9)"
+ else if (summary.isEmpty())
+ summary = "(not set)"
+
+ return summary
+ }
+
+}
diff --git a/main/src/ui/res/xml/vpn_ipsettings.xml b/main/src/ui/res/xml/vpn_ipsettings.xml
index 2b03c694..66d7d114 100644
--- a/main/src/ui/res/xml/vpn_ipsettings.xml
+++ b/main/src/ui/res/xml/vpn_ipsettings.xml
@@ -47,12 +47,12 @@
android:dialogMessage="@string/dns1_summary"
android:key="dns1"
android:title="@string/dns_server"
- app:useSimpleSummaryProvider="true" />
+ />
<EditTextPreference
android:dialogMessage="@string/secondary_dns_message"
android:key="dns2"
android:title="@string/backup_dns"
- app:useSimpleSummaryProvider="true" />
+ />
</PreferenceCategory>
</PreferenceScreen> \ No newline at end of file