From abdee64724479253fad8da45882acb9cba6d8911 Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Sun, 30 Apr 2017 17:39:42 +0800 Subject: [PATCH] Added back-end support for Custom DNS server --- app/build.gradle | 1 + .../daedalus/fragment/SettingsFragment.java | 8 +-- .../itxtech/daedalus/util/Configurations.java | 9 +++- .../org/itxtech/daedalus/util/DnsServer.java | 28 ++++++++-- .../res/drawable/ic_note_add_black_24dp.xml | 9 ++++ .../main/res/layout/fragment_dns_servers.xml | 7 ++- app/src/main/res/layout/list_dns_servers.xml | 51 +++++++++++-------- 7 files changed, 80 insertions(+), 33 deletions(-) create mode 100644 app/src/main/res/drawable/ic_note_add_black_24dp.xml diff --git a/app/build.gradle b/app/build.gradle index 14c5504..0cdb6b5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -49,6 +49,7 @@ dependencies { compile 'com.android.support:design:25.3.1' compile 'com.android.support:support-v4:25.3.1' compile 'com.android.support:percent:25.3.1' + compile 'com.android.support:cardview-v7:25.3.1' compile 'org.pcap4j:pcap4j-core:1.7.0' compile 'org.pcap4j:pcap4j-packetfactory-propertiesbased:1.7.0' diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java index ad1caa3..9a5ecc0 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java @@ -33,11 +33,11 @@ public class SettingsFragment extends PreferenceFragment { ListPreference primaryServer = (ListPreference) findPreference("primary_server"); primaryServer.setEntries(DnsServer.getDnsServerNames(Daedalus.getInstance())); primaryServer.setEntryValues(DnsServer.getDnsServerIds()); - primaryServer.setSummary(DnsServer.getDnsServerById(primaryServer.getValue()).getStringDescription(Daedalus.getInstance())); + primaryServer.setSummary(DnsServer.getDnsServerDescription(primaryServer.getValue(), Daedalus.getInstance())); primaryServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - preference.setSummary(DnsServer.getDnsServerById((String) newValue).getStringDescription(Daedalus.getInstance())); + preference.setSummary(DnsServer.getDnsServerDescription((String) newValue, Daedalus.getInstance())); Snackbar.make(view, R.string.notice_need_restart, Snackbar.LENGTH_LONG) .setAction("Action", null).show(); return true; @@ -47,11 +47,11 @@ public class SettingsFragment extends PreferenceFragment { ListPreference secondaryServer = (ListPreference) findPreference("secondary_server"); secondaryServer.setEntries(DnsServer.getDnsServerNames(Daedalus.getInstance())); secondaryServer.setEntryValues(DnsServer.getDnsServerIds()); - secondaryServer.setSummary(DnsServer.getDnsServerById(secondaryServer.getValue()).getStringDescription(Daedalus.getInstance())); + secondaryServer.setSummary(DnsServer.getDnsServerDescription(secondaryServer.getValue(), Daedalus.getInstance())); secondaryServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - preference.setSummary(DnsServer.getDnsServerById((String) newValue).getStringDescription(Daedalus.getInstance())); + preference.setSummary(DnsServer.getDnsServerDescription((String) newValue, Daedalus.getInstance())); Snackbar.make(view, R.string.notice_need_restart, Snackbar.LENGTH_LONG) .setAction("Action", null).show(); return true; diff --git a/app/src/main/java/org/itxtech/daedalus/util/Configurations.java b/app/src/main/java/org/itxtech/daedalus/util/Configurations.java index f051ea7..1896294 100644 --- a/app/src/main/java/org/itxtech/daedalus/util/Configurations.java +++ b/app/src/main/java/org/itxtech/daedalus/util/Configurations.java @@ -11,7 +11,14 @@ import java.io.IOException; import java.util.ArrayList; /** - * @author PeratX + * Daedalus Project + * + * @author iTXTech + * @link https://itxtech.org + *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
*/
public class Configurations {
private static File file;
diff --git a/app/src/main/java/org/itxtech/daedalus/util/DnsServer.java b/app/src/main/java/org/itxtech/daedalus/util/DnsServer.java
index 0aa8942..329c949 100644
--- a/app/src/main/java/org/itxtech/daedalus/util/DnsServer.java
+++ b/app/src/main/java/org/itxtech/daedalus/util/DnsServer.java
@@ -50,6 +50,11 @@ public class DnsServer {
return server.getAddress();
}
}
+ for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
+ if (customDnsServer.getName().equals(id)) {
+ return customDnsServer.getAddress();
+ }
+ }
return Daedalus.DNS_SERVERS.get(0).getAddress();
}
@@ -59,6 +64,11 @@ public class DnsServer {
return server.getAddress();
}
}
+ for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
+ if (customDnsServer.getName().equals(description)) {
+ return customDnsServer.getAddress();
+ }
+ }
return Daedalus.DNS_SERVERS.get(0).getAddress();
}
@@ -67,6 +77,9 @@ public class DnsServer {
for (DnsServer server : Daedalus.DNS_SERVERS) {
servers.add(server.getId());
}
+ for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
+ servers.add(customDnsServer.getName());
+ }
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
return servers.toArray(stringServers);
}
@@ -76,17 +89,24 @@ public class DnsServer {
for (DnsServer server : Daedalus.DNS_SERVERS) {
servers.add(server.getStringDescription(context));
}
+ for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
+ servers.add(customDnsServer.getName());
+ }
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
return servers.toArray(stringServers);
}
- public static DnsServer getDnsServerById(String id) {
+ public static String getDnsServerDescription(String id, Context context) {
for (DnsServer server : Daedalus.DNS_SERVERS) {
if (server.getId().equals(id)) {
- return server;
+ return server.getStringDescription(context);
}
}
- return Daedalus.DNS_SERVERS.get(0);
-
+ for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
+ if (customDnsServer.getName().equals(id)) {
+ return customDnsServer.getName();
+ }
+ }
+ return Daedalus.DNS_SERVERS.get(0).getStringDescription(context);
}
}
diff --git a/app/src/main/res/drawable/ic_note_add_black_24dp.xml b/app/src/main/res/drawable/ic_note_add_black_24dp.xml
new file mode 100644
index 0000000..5bba8da
--- /dev/null
+++ b/app/src/main/res/drawable/ic_note_add_black_24dp.xml
@@ -0,0 +1,9 @@
+